$(document).ready(function() {

	var currentSection = 0;
	var allSections = 0;


	//init site
	initArray();
	toggleVideo(currentSection);

	//button handlers
	$("#infobutton").click(function() {btnInfo("#infobutton")});
	$("#nextbutton").click(function() {btnNav("#nextbutton")});
	$("#previousbutton").click(function() {btnNav("#previousbutton")});

	//handle next and previous buttons
	function btnNav(myBtn) {
		
		if (myBtn == "#nextbutton") {
			if (currentSection < allSections) {
				currentSection++;
			} else {
				currentSection = allSections;	
			}
		} else if (myBtn == "#previousbutton") {
			if (currentSection > 0) {
				currentSection--;
			} else {
				currentSection = 0;	
			}
		} 
	
		toggleVideo(currentSection);		
		toggleContent(currentSection);
	}
	
	
	//show content section
	function toggleContent (myId) {
		
		//hide all sections
		$("#sections > #main").removeClass("mainVisible");
		$("#sections > #main").addClass("mainHidden");
		
		//toggle current section
		$("#sections > div:eq("+ myId +")").addClass("mainVisible");
		
		//toggle bg video
		$("#MyPlayer").attr("href", myVid);
		initVideo();
	}


	//display info overlay
	function btnInfo(myBtn) {
		//toggle info ui	
		$('#content').toggle('drop', {direction: 'up'}, 1000);
		$(myBtn).toggleClass("infobuttonSelected");
		toggleContent(currentSection);
	}


	function toggleVideo(myId) {
	
		if (myId == 0) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/andrea.f4v");}
		if (myId == 1) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/aboutus.flv");}		
		if (myId == 2) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/findolena.f4v");}
		if (myId == 3) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/killmenow.f4v");}
		if (myId == 4) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/mastercard.f4v");}		
		if (myId == 5) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/plastic.f4v");}
		if (myId == 6) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/princess.f4v");}
		if (myId == 7) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/justnotlikethem.f4v");}
		if (myId == 8) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/gamegirl.f4v");}		
		if (myId == 9) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/120.f4v");}
		if (myId == 10) {$("#MyPlayer").attr("href", "http://www.playandgrow.dk/video/andrussiandoll.f4v");}
		initVideo();
	}
	
	
	//init background video
	function initVideo() {
		$f("MyPlayer", {src: 'flowplayer/flowplayer-3.2.7.swf', wmode: 'opaque'}, {
			onBeforeFinish: function() {return false;},	
			plugins: {
				
				clip:{ 
					autoPlay: true,
					autoBuffering: true,
					accelerated: true, 
					fadeInSpeed: 1000,
				}, 
	
				canvas: {
					 backgroundColor: '#FFFFFF',
					 backgroundGradient: 'none'
				},
	
				controls: null
				} 
				
		 });                                 
	}


	//iterate content divs
	function initArray () {
		// Loop over each hottie.
		$("#sections > div").each(
			function(intIndex){
				allSections++;	
			}
		);		
		
		allSections--;
	}

});





