// JavaScript Document
$(window).load(function(){
	
	
	//var $windowHeight = $(window).height(); - MIGHT  NEED THIS IN FUTURE
	//var $windoWidth = $(window).width(); - MIGHT NEED THIS IN FUTURE
	 
	 var $bodyHeight = $(document).height();
	 var $bodyWidth = $("body").width();
	 
	 //console.log($bodyHeight);
	 
	 
	 $("#bgContainer").height($bodyHeight);
	 $("#bgContainer").width($bodyWidth);

	//IF RESIDE
	$(window).resize(function() {
							  
		 var $bodyHeight = $(document).height();
		 var $bodyWidth = $("body").width();
		 
		 $("#bgContainer").height($bodyHeight);
		 $("#bgContainer").width($bodyWidth);
			
	});
	

	/*GET FIRST BACK GROUND*/
	var fristclass = $(".items img:first").attr("rel");
	fristclassImg = new Image();
	fristclassImg.src = "images/backgrounds/" + fristclass + ".png";
	$('#bgContainer').addClass(fristclass);
	
	/*********HOME scrollable*/
	
	 var arrayOfBG = [];
	 var imgs =[];
	 var titleForHeaders =[];
	
	$(".items img").each(function(){ 

					var name0fclass	= $(this).attr("rel");
					arrayOfBG.push(name0fclass);
					
					/* GRAB HEADERS FORM scrollable*/
					titleForHeaders.push( $(this).attr("alt"));
	
	})
	
	
	 jQuery.each(arrayOfBG, function(index, value) {
   		//console.log("index", index, "value", value);
					imgs[index] = new Image();
					imgs[index].src = "images/backgrounds/" + arrayOfBG[index] + ".png";
					//console.log(titleForHeaders[index]);
 	});
	 
	 
	 
	//int headers 							
	$("h1").html(titleForHeaders[0]);
	Cufon.replace('h1',{fontFamily:'helvecltbold',textShadow: '1px 1px 2px #ccc', letterSpacing:"-1px"});
	
	$(".scrollable").scrollable({ circular: true, speed:600,
						onBeforeSeek:function(event, i) { 
							$("#homeslideshownav ul li span").each(function(){
									$(this).removeClass("masking");
							});
							
							
							$('#bgContainer').fadeOut(300,function(){ $(this).attr("class",""); });
							
						},
						
						onSeek:function(event, i) {
							
							$('#homeslideshownav ul li:eq('+ i +') span').addClass("masking");

							$('#bgContainer').addClass(arrayOfBG[i]).fadeIn(400);
							
							/* GRAB HEADERS FORM scrollable*/
							$("h1").html(titleForHeaders[i]);
							Cufon.replace('h1',{fontFamily:'helvecltbold',textShadow: '1px 1px 2px #ccc', letterSpacing:"-1px"});

							//console.log(i);
							
						}
						
					
					})
	.autoscroll({interval:5000,autoplay: false})
	.navigator("#homeslideshownav ul");
	
	var api = $(".scrollable").data("scrollable");
	
	api.play();
	
	$("#homeslideshownav a").click(function(){ api.stop() });
	
	
	/*************/
	
	//////////////////// FEATURE BOX FIX
	var hightest = 0;
	$("#homefeaterboxcontainer  h2").each(function(){
		var thisheight = $(this).height();
	
		if(thisheight > hightest){
			hightest  = thisheight  ;
		}
	});

 	$("#homefeaterboxcontainer h2").each(function(){
		var thisheight = $(this).height();
		if(thisheight < hightest){
			var thediffrance = (hightest - thisheight) +"px";
			//$(this).css("margin-bottom",thediffrance);
		}
	});

	



	
}); // end of ready() function



