timer = 0;
$(document).ready(function() {
	$("#content").cycle({speed:5000});
	$(".home").css("display","none");
	w = $("#buttons div.button a.main").parent().width()
	$("#buttons div.button a.main").mouseover(
		function(){expand(this,w);}
		)
	.mouseout(
		function(){colapse(this,w);}
		)
	.click(
		function(event){
			if ($(this).siblings("span.a").is("span.a"))
			{
				if (!$(this).hasClass("active"))
				{
					event.preventDefault();
				}
				toggle_span(this); 
				$("div#content").css("visibility","hidden");
			}
		});
	gs = Math.random();
	
	if (!$.cookie("survey"))
	{
		if(Math.floor(gs*100) <= 100)
			{
				setTimeout('survey("/_survey/prompt.php");',1000);
				$.cookie("survey",1,{expires: 60})		
			}
	}
	else
	{
		if ($.cookie("survey") != 1)
		{
			if(Math.floor(gs*100) <= 100)
			{
				setTimeout('survey("/_survey/prompt.php");',1000);
				$.cookie("survey",1,{expires: 60});		
			}
		}
	}
		
});	

function expand(x,w)
{
	l = $(x).parent().width();
	date = new Date()
	start = date.getTime();
	end = 0;
	if (timer < 1000)
	{
		if ($(x).hasClass("bio"))
		{
			$(x).css({'backgroundImage':"url(/_img/transparent/006600-80.png)",color:"white"}).parent().stop().animate({width:w+w/16},"slow",function(){
				edate = new Date()
				end = edate.getTime();
				timer = end - start;
			});
		}
		else
		{
			$(x).css({'backgroundImage':"url(/_img/transparent/000066-80.png)",color:"white"}).parent().stop().animate({width:w+w/16},"slow",function(){
				edate = new Date()
				end = edate.getTime();
				timer = end - start;
			});		
		}		
	}
	else
	{
		if ($(x).hasClass("bio"))
			$(x).css({backgroundColor:"#006600",color:"white",width:w+w/4});
		else
			$(x).css({backgroundColor:"#000066",color:"white",width:w+w/4});
	}

	
}

function colapse(c,w)
{
	l = $(c).parent().width();
	if (timer < 1000 || l > w)
	{	
		if ($(c).hasClass("active") == false)
		{
			if ($(c).hasClass("bio"))
			{
				$(c).parent().stop().animate({width:w},"slow", function(){
					$(c).css({backgroundImage:"url(/_img/transparent/ffffff-90.png)",color:"#006600"});
				});
			}
			else
			{
				$(c).parent().stop().animate({width:w},"slow", function(){
					$(c).css({backgroundImage:"url(/_img/transparent/ffffff-90.png)",color:"#000066"});
				});
			}
		}
	}
	else
	{	
		if ($(c).hasClass("active") == false)
		{
			if ($(c).hasClass("bio"))
			{		
				$(c).css({backgroundImage:"url(/_img/transparent/ffffff-80.png)",color:"#006600",width:w});		
			}
			else
			{	
				$(c).css({backgroundImage:"url(/_img/transparent/ffffff-80.png)",color:"#000066",width:w});		
			}
		}				
	}
}
function toggle_span(c)
{
	if (!$(c).hasClass("active"))
	{
		active = $(".active");
		active.removeClass("active");
		colapse(active,w);
	}
		
		
	$("#buttons span.a").animate({height:0,width:0},0,function(){ 
		$(this).css({"visibility":"hidden"}); 
		$(c).siblings("span.a").css({"visibility":"visible",height:"26em",width:"37em"});
	});
	$("#buttons a.main").removeClass("active").css({overflow:"hidden"});
	$(c).css({overflow:"visible"}).addClass("active");
}

