//****************************************************************//
//Written by Colin Eyo for Lloydlakelodge.com. 2011. 6992569
//****************************************************************//
$(document).ready(function(){
	// Variables to change.
	// Slide show variables.
	var firstSlide 							= 1;
	var autoRotation 						= true;
	var rotationSpeed 						= 6000;
	var sliderAnimationSpeed				= 500;	
	var stopAnimationOnAction 				= false;

	var slideTitle 							= new Array();
	slideTitle[1]							= "Why Choose Us?";
	slideTitle[2]							= "Why Choose Us?";
	slideTitle[3]							= "Why Choose Us?";
	slideTitle[4]							= "Why Choose Us?";
	slideTitle[5]							= "Why Choose Us?";
	
	var slideText  							= new Array();
	slideText[1]							= "Look at that smile. The biggest walleye he’s ever seen.";
	slideText[2]							= "We’re 2 brothers living the dream and we’d like to share.";
	slideText[3]							= "Sit back, relax, and enjoy a piece of peace.";
	slideText[4]							= "Last year, our hunters harvested 2 Boone & Crockett and 2 Pope & Young bears. You won’t be disappointed.";
	slideText[5]							= "Because you dream about casting a fly and hooking into this beauty.";
	
	var slideTextColor						= new Array();
	slideTextColor[1]						= "#FFF";
	slideTextColor[2]						= "#FFF";
	slideTextColor[3]						= "#FFF";
	slideTextColor[4]						= "#FFF";
	slideTextColor[5]						= "#FFF";
	
	//Home page copy blocks variables.
	var padding 							= 20;
	var contentContainerInnerBlocksHeight	= 200;
	
	//Contact area auto open variables.
	var contactAreaMaxHeight				= 150;
	var contactAreaMinHeight				= 3;
	var mainContainerHeight					= 760;
	var contactAreaAnimationSpeed			= 500;
	var contactButtonOpenText				= "Contact Us"
	var contactButtonCloseText				= "Close"
	
	//Various Container sizes and positions
	var contactButtonWidth					= 80;
	var slideshowNavigationElementSize		= 12;
	
	//Inner content images
	var innerContentImageArray 				= new Array();
	innerContentImageArray[0]				= 'innerContentImage0.jpg';
	innerContentImageArray[1]				= 'innerContentImage1.jpg';
	innerContentImageArray[2]				= 'innerContentImage2.jpg';
	
	
	//****************************************************************//
	//Place inner content images
	//****************************************************************//
	/*
	$.each(innerContentImageArray,function(index,value){
			$("#innerContentImage"+index).css('background-image',"url(assets/images/"+value);
			$("#innerContentImage"+index).css('background-position',"center");
		});
	*/
	
	//****************************************************************//
	//Contact area auto open function
	//****************************************************************//
	var contactAreaHeightDifference			= (contactAreaMaxHeight - contactAreaMinHeight);
	var contactButtonState 					= "closed";
	var mainContainerNewHeight				= (mainContainerHeight + contactAreaHeightDifference);
	
	$("#contactContainer").height(contactAreaMinHeight);
	$("#mainContainer").height(mainContainerHeight);
	$("#contactButton p").text(contactButtonOpenText);
	
	$("#contactButton").hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);	
	$("#contactButton").click(
		function(){
			if (contactButtonState == "closed") {
				$("#contactContainer").animate({
					height: contactAreaMaxHeight
				}, contactAreaAnimationSpeed);
				$("#mainContainer").animate({
					height: mainContainerNewHeight
				}, contactAreaAnimationSpeed);
				
				contactButtonState = "open";
				$("#contactButton p").text(contactButtonCloseText);
				
			}else{
				$("#contactContainer").animate({
					height: contactAreaMinHeight
				}, contactAreaAnimationSpeed);
				$("#mainContainer").animate({
					height: mainContainerHeight
				}, contactAreaAnimationSpeed);
				contactButtonState = "closed";
				$("#contactButton p").text(contactButtonOpenText);
			}
		}
	);		


	//****************************************************************//
	//Homepage image slideshow
	//****************************************************************//		
	var timer;
	var currentImageID = firstSlide;
	var numberOfSlides = $(".slides").children().length;
	
	//Draw the proper number of navigation elements.
	$('#slideContainer').children().each( 
		function(index){
			var navigationNumber = index+1;
				$("#slideshowNavigation").append("<div id='nav"+navigationNumber+"' class='slideshowNavigationElement'></div>");
		}
	);
	
	//Make all the slides invisible.
	$(".slide").css("visibility","hidden");
	
	//Fade in the default Image
	$("#image" + currentImageID ).css("visibility","visible");
	
	//Make the default text visible for the current slide
	updateSlideText( currentImageID );
		
	//Make sure the default navigation item is selected.
	$("#nav"+firstSlide).addClass("selected");
	
	//Image switch function
	function switchImages( currentID, newID ){

		//Fade out the current active image
		$("#image" + currentID).animate({
		"opacity": 0
		}, sliderAnimationSpeed, "swing");
		//Remove all the active classes in the li
		$(".slide").removeClass("active");
		//Remove all the selected classes from the navigation
		$(".slideshowNavigationElement").removeClass("selected");
			
		//Prepare the new image to be faded in
		$("#image" + newID).css("visibility","visible");
		$("#image" + newID).css("opacity",0.01);
		//Fade in the new image
		$("#image" + newID).animate({"opacity":1},sliderAnimationSpeed, "swing", null);
		//Add active class to li
		$("#image" + newID).addClass("active");
		//Add selected class to proper slide navigation element
		$("#nav"+newID).addClass("selected");		
		
		timer.reset();
		currentImageID = newID;
		
		$("#currentID").text(currentImageID);
		
		updateSlideText( newID );			
	};
	
	function updateSlideText( slideNumber ) {
		$("#slideTitle").text(slideTitle[slideNumber]).css("color",slideTextColor[slideNumber]);
		$("#slideText").text(slideText[slideNumber]).css("color",slideTextColor[slideNumber]);		
	};
	
	function showNextImage( direction ){
		var nextSlide;
				
		//Calculate the next slide
		if(direction == "higher"){
			
			//Check to see what the next slide should be
			if( numberOfSlides == currentImageID ){
			 	nextSlide = 1;
			}else{
				nextSlide = parseFloat(currentImageID) + 1;
				
			}
				 
		}else{	
			
			if( currentImageID == 1 ){
			 	nextSlide = numberOfSlides;
			}else{
				nextSlide = parseFloat(currentImageID) - 1;	
			}			
		}
		switchImages( currentImageID, nextSlide);			
	};
		
	function rotate(){
		showNextImage("higher");
	};
		
	timer = $.timer(
		function(){
			rotate();
		}
	);
	timer.set({time : rotationSpeed, autostart : true});
	
	function toggleTime(){
		if (stopAnimationOnAction) {
			timer.stop();
		};
	};
	
	//Action Elements
	$(".slideshowNavigationElement").click(
		function(){		
			var switchTo = this.id.split("nav")[1];			
			if ( currentImageID != switchTo ){
				switchImages( currentImageID, switchTo );
				toggleTime();
			};			
		}
	);
		
	$("#testHigher").click(
		function(){		
			showNextImage("higher");
			toggleTime();
		}
	);
	
	$("#testLower").click(
		function(){
			showNextImage("lower");
			toggleTime();
		}
	);
	
	//****************************************************************//	
	//Auto sizing home page copy blocks.
	//****************************************************************//
	var numberOfColumns 					= 3;
	var numberOfContactColumns 				= 4;
	var innerContentWidth 					= 840;
	var pixlesToSubtract 					= (padding*2)+((numberOfColumns-1)*padding);
	var widthOfEachElement 					=  Math.floor((innerContentWidth - pixlesToSubtract)/numberOfColumns);
	var widthOfEachContactElement			=  Math.floor((innerContentWidth - pixlesToSubtract)/numberOfContactColumns);
	
	$(".innerContentModule").css("padding-right", padding );
	$(".innerContentModule.first").css("padding-left", padding );
	$(".imageContainer").width(widthOfEachElement);
	$(".innerContentModule").width(widthOfEachElement);
	$("#contentContainerInnerBlocks").height(contentContainerInnerBlocksHeight);
	$("#contactButton").width(contactButtonWidth);
	$("#slideshowNavigation").css("margin-left", padding );
	$(".slideTitle").css("margin-left", padding );
	$(".slideText").css("margin-left", padding );
	$(".slideshowNavigationElement").height(slideshowNavigationElementSize).width(slideshowNavigationElementSize);
	$(".bottomLinkContainer").width(Math.floor(widthOfEachElement/2)).css("margin-left", padding);	
	$(".topLinkContainer").width(Math.floor(widthOfEachContactElement)-5).css("margin-right", padding);
	/*
$(".topLinkContainer first").css("margin-right", "0");
*/

	$("#mainInfoBox0").click(
		function(){ window.location = "index.cfm/your-experience/why-lloyd-lake-lodge/";}
	);
	$("#mainInfoBox0").hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);
	
	$("#mainInfoBox1").click(
			function(){ window.location = "index.cfm/your-experience/your-fishing-experience/";}
	);
	$("#mainInfoBox1").hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);
	
	$("#mainInfoBox2").click(
			function(){ window.location = "index.cfm/your-experience/your-hunting-experience/";}
	);
	$("#mainInfoBox2").hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);
	
	$("#facebookLink").click(
			function(){ window.open('http://www.facebook.com/LloydLakeLodge','_blank') }
	);
	$("#facebookLink").hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);
	
	$("#twitterLink")
	.click(
		function(){ window.open('http://twitter.com/lloydlakelodge','_blank') })
	.hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);
	
	$("#blogspotLink")
	.click(
		function(){ window.open('http://www.lloydlakelodge.blogspot.com/','_blank') })
	.hover(
		function(){document.body.style.cursor = "pointer"},
		function(){document.body.style.cursor = "default"}
	);
	
	

});	

