// JavaScript Document

//functions .....



function slideLinks(mylink, url) {  
   							
			mylink = mylink || ".caseStudy";
			url = url || "index.php";
               
			// add click events for main nav
			$(mylink).click(function() {
			$("#mainCaseHolder").animate({"height" : "80px"},1000,function(){$("#mainCaseHolder ul").remove();});
			$("#cornerBG").animate({"height" : "80px"},1000);
			$("body").animate({"opacity" : 0 }, 1500, function(){window.location = url;});
			return false;
             
});
			
};

// suckerfish jquery
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};


$(document).ready(function(){
						   
$("#nav-one li").hover(
		function(){ $("ul", this).fadeIn("fast"); }, 
		function() { } 
	);
	if (document.all) {
		$("#nav-one li").hoverClass ("sfHover");
	}						   

// remove height between sub nav squares when no thumbHead there
$(".thumbHead").each(function(){
getthumbHead = $(this).text();
if(getthumbHead == "") {
$(this).css({"height" :0});
};
});
						   
						   
// fade in body slide down

$("body").css({"display" : "block" });
$("body").css({"opacity" : 0 });
$("body").animate({"opacity" : 1},2000); 
//add back visibility from jumping issue
$("body").css({"visibility" : "visible"});
// end body fade



// add switch to set each page init state

	// get location
	var myLocation = window.location.href.slice(window.location.href.indexOf('?') + 1).split('/');
	
	
	switch(myLocation[3])
{		
		 case "index.php":
				$("#displayLogo").css({"opacity" : 0});
				$("#nav-one li a:eq(0)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "341px"},2000);
				$("#mainCaseHolder").css({"height" : "0px" });
				$("#mainCaseHolder").animate({"height" : "344px"},2000, function() {
																				 $("#displayLogo").animate({"opacity" : 1},3000); 
																				 $("#hotLinkCase a").slideDown(2000); 
																				 });
		  break;

		case "caseStudies.php":
				$("#nav-one li a:eq(1)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "348px"},2000);
				$("#mainCaseHolder").css({"height" : "0px" });
				$("#mainCaseHolder").animate({"height" : "330px"},2000);
		  break;
		  
		case "":
				$("#displayLogo").css({"opacity" : 0});
				$("#nav-one li a:eq(0)").addClass("activeClass"); 
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "341px"},2000);
				$("#mainCaseHolder").css({"height" : "0px" });
				$("#mainCaseHolder").animate({"height" : "344px"},2000, function() {
																				 $("#displayLogo").animate({"opacity" : 1},3000);
																				 $("#hotLinkCase a").slideDown(2000); 
																				 });
		  break;
		case "people.php":
				$("#nav-one li a:eq(10)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);
		  break;
		  
		case "contactusWEB.php": 
				$("#nav-one li a:eq(26)").addClass("activeClass");
				$("#divDirections").css({"opacity" : 0 });
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000, function() {$("#divDirections").animate({"opacity" : 1},2000);});
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);
		  break;
		  
		case "loginftp.php":
				$("#nav-one li a:eq(27)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);
		  break;
		  
		  case "caseOne":
		  		$("#nav-one li a:eq(1)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);	
		break;
		  case "caseTwo":
		  		$("#nav-one li a:eq(1)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);	
		break;
		
		  case "caseThree":
		  		$("#nav-one li a:eq(1)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);	
		break;
  case "legal":
		  		$("#nav-one li a:eq(1)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);	
		break;		
		default:
				$("#nav-one li a:eq(11)").addClass("activeClass");
				$("#cornerBG").css({"height" : "0px" });
				$("#cornerBG").animate({"height" : "75px"},2000);
				$("#headerFiller").css({"height" : "0px" });
				$("#headerFiller").animate({"height" : "75px"},2000);				

}
// end switch


// Center the wrapper for main page
winWidth = $(window).width();
marWidth = (winWidth-826)/2;
if (winWidth<826){
$("#wrapper").css({'margin-left': '0px'});
}else {
$("#wrapper").css({'margin-left': marWidth});
        }
$(window).resize(function(){
winWidth = $(window).width();
marWidth = (winWidth-826)/2;
if (winWidth<826){
$("#wrapper").css({'margin-left': '0px'});
}else {
$("#wrapper").css({'margin-left': marWidth});
        }
});
// end center

// Coastline Case Study Slider

var items = [];
$("#mainCaseHolder li").each(function () {
    items.push('<li>' + $(this).html() + '</li>');
$(this).remove();
});
       currentItem = 0;               
       function coastSlide() {

$('#mainCaseHolder li').filter(':gt(1)').remove();
 
var $insert = $(items[currentItem]).css({
               width: 0,
               opacity : 0,
               display : 'none'
           }).prependTo("#mainCaseHolder ul");
$insert.animate({ "width" : "1000px"}, 3000).animate({ "opacity" : 1 }, 2000);
$('#mainCaseHolder li').filter(':gt(0)').animate({"opacity" : 0}, 3000);
$('#mainCaseHolder li').filter(':gt(1)').remove(); 
           currentItem++;
           if (currentItem >= 3) {
      currentItem = 0;               
                  }
           
           setTimeout(coastSlide, 7000);
		   
		          }
      
       coastSlide();
   

		    
/*
// ............................  Main Nav 

 Close case studio


       slideLinks(".caseStudy","http://coastlinestudios.com/index.php");
       slideLinks(".people","http://coastlinestudios.com/people.php");
       slideLinks(".contacts","http://coastlinestudios.com/contactus.php");
       slideLinks(".login","http://coastlinestudios.com/loginftp.php");

*/




// people page 

// sub nav people 
		$("#left li a").hover(
		function(){
		$(this).addClass('mySlide');
		},
		function(){
		$(this).removeClass('mySlide');
		});
		
// detect FF 3.0 down and move hot button

var ua = $.browser;
  if ( ua.mozilla && ua.version.slice(0,3) == "1.9" ) {
$("#hotLinkCase a").css({"" : ""});
}
		
		
});  // end ready
