ie=false;
$.each($.browser, function(i, val) {
if (i=='msie' && val==true){ie=true;}
});

z=0;
f=0;
activeframe=0;

$(document).ready(function(){

activatedclass=$("body").attr("class");

/********************** NAV **/
	$(".nav li a").each(function(){ //for Javascript enabled, replace all nav links with #anchors
		thehref=$(this).attr("href");
		if(thehref=="/default.asp"){newhref="#home";}
		else{newhref=thehref.replace('/','#');}
		$(this).attr("href",newhref);
	});
	
	$("ul.nav li a").click(function(){	activate($(this).parent().attr("class"));	});						//All nav links
	$(".nav a").mouseover(function(){	rollover($(this).parent().attr("class"));	});
	$(".nav a").mouseout(function(){	activating=false;	rollout($(this).parent().attr("class"));});
	
	$("#logo a").mouseover(function(){	rollover("home");	}); 											//Logo	
	$("#logo a").mouseout(function(){	rollout("home");	});
	$("#logo a").click(function(){	activate("home");	return false;});
	
	$("a#backtocontact").live("click",function(event){	activate("contact");return false;}); 				//After e-mailing, link back to Contact
	
/********************** WORK **/
	
	$("ul#projects li a").live("click", function(event) {   												//clicking a project tile
			$("#hitarea").css("display","block");
			var theclass=$(this).attr("class");
			var thediv=$("div.project."+theclass);
			thediv.slideDown(500); 								//show project contents
			thediv.append("<div class=\"overlay\"></div>"); 	//add overlay
			$("div.overlay").slideDown(300,function(){ 			//show overlay
				$("#controls").show();	//show controls
				});
			$("div.overlay").css("z-index","120");				//bring overlay to top
			thediv.find("div.info").css("z-index","130");		//bring info to top
			activeproject=theclass;								
			return false;
	});
	
	$("div#controls a").live("click",function(event){       											//clicking a controls button
		if($(this).hasClass("previous")){																	//previous 
			if(activeframe>0){
			$("div."+activeproject+" li").eq(activeframe-1).show(500);
			activeframe--;
			}}
		else if($(this).hasClass("next")){																	//next 
			if(activeframe<$("div."+activeproject+" li").length-1){
			$("div."+activeproject+" li").eq(activeframe).hide(500);
			activeframe++;
			}}
		else if($(this).hasClass("close")){  																//close
			$("#hitarea").css("display","none");
			$("div.project").slideUp(300,function(){$("#controls").hide();});
			$("div.project").css("z-index","0");
			$("div.overlay").slideUp(500);
			$("div.images ul li").show();
			activeframe=0;
		}
		return false;
	});
	
	$("div#controls a").live("mousedown",function(event){ $(this).addClass("active"); })
						.live("mouseout",function(event){ $(this).removeClass("active");})
						.live("mouseup",function(event){ $(this).removeClass("active");});
						
	$("a.info").live("mouseover",function(event){$("div."+activeproject+" .info").show(); })
				.live("mouseout",function(event){$("div."+activeproject+" .info").fadeOut(300);});
	
	$("a#hitarea").live("mouseover",function(event){ $("div."+activeproject+" .info").hide(); })
	.live("mouseout",function(event){ $("div."+activeproject+" .info").show(); });


/********************** CONTACT **/	
	$("input#sendmessage").live("mousedown",function(event){ $(this).addClass("mousedown");	})
						  .live("mouseout",function(event){ $(this).removeClass("mousedown"); });
	$("form#contactform").live("submit",function(event){
			var dataString=$(this).serialize();
			$.ajax({type: "POST",url: "/thankyou.asp",data: dataString,success: function() {
						$("form#contactform").fadeOut(500, function(){$("#content").load("/thankyou.asp");});
						}
			});return false;
	});
	
	
	$("#takeapeek a").live("click",function(event){	activate("work"); return false;})
	.live("mouseover",function(event){	rollover("work");})
	.live("mouseup",function(event){	rollout("work");});
	
	
/********************** UNIVERSAL **/	
$("a#readytoboost").click(function(){	activate("contact"); return false; })
					.mouseover(function(){ rollover("contact");})
					.mouseout(function(){ rollout("contact");});

moo=document.location.hash.substring(1);
if(moo=="work" || moo=="clients" || moo=="contact" || moo=="home"){
activate(moo);
}


});

function rollover(theclass){
if(theclass!=activatedclass){
	var thediv=$("div#fields div.field_"+theclass);
	if(theclass=="home"){
			thediv.animate({marginTop:"-20px"},200);
	}
	if(theclass=="clients"){
			thediv.animate({marginTop:"20px"},200);
	}
	if(theclass=="contact"){
			thediv.animate({marginLeft:"20px"},200);
	}
	if(theclass=="work"){
			thediv.animate({marginLeft:"-20px"},200);
	}
}
}

function rollout(theclass){
	var thediv=$("div#fields div.field_"+theclass);
	if(theclass=="home"){
			thediv.animate({marginTop:"0px"},180);
	}
	if(theclass=="clients"){
			thediv.animate({marginTop:"0px"},180);
	}
	if(theclass=="contact"){
			thediv.animate({marginLeft:"0px"},180);
	}
	if(theclass=="work"){
			thediv.animate({marginLeft:"0px"},180);
	}
}

function activate(theclass){
				thefield=$("div#fields div.field_"+theclass);
				thecontent=$("div#content");
				z++;	
				$("#hitarea").css("display","none");
				$("#controls").hide(); 				   //hide work controls if showing
				$("ul.nav li."+theclass+" a").css("margin-top","-800px");
				
				thecontent.html(""); 									  //erase contents
				thefield.hide().css("z-index", 120+z); 					  //hide, then bring color to front
				
				if(ie==true){
					thefield.show();
					thecontent.hide().show(); 
					thecontent.load("../"+theclass+".asp",function(){
										$("ul.nav li."+theclass+" a").css("margin-top","0px");
					});//load the content
					$("div#splash").fadeIn(200);
					//$("#holder ul.nav").css("z-index","200");
					$("div#container").css("background-image","url(/images/patterns/"+theclass+".gif)");						
					activatedclass=theclass;						
				}else{
				
					thefield.fadeIn(800, function(){
						thecontent.hide(); //hide content box				
						thecontent.fadeIn(800,function(){ //fade in content box
						thecontent.load("../"+theclass+".asp");//load the content
						$("div#splash").fadeIn(200);
						//$("#holder ul.nav").css("z-index","200");
						$("ul.nav li."+theclass+" a").css("margin-top","0px");
						$("div#container").css("background-image","url(/images/patterns/"+theclass+".gif)");						
						activatedclass=theclass;						
						});
					});
				}
			currclass=$("body").attr("class");
			$("body").removeClass(currclass);
			$("body").addClass(theclass);
			
}


function rotateupdates(){
	$("li").hide();
	$("li").eq(activeframe).show();
	if(activeframe<$("#updates li").size()-1){activeframe++;}
	else{activeframe=0;}
	var t = setTimeout("rotateupdates();", 3500);
}