/* Init caption legend */
var lng = "";
var item = "";
var pathname = "";
var packHeigth = 0;
var packWidth = 0;
var isOn = true;

	// set ViewFullscreen	
	var wSize = $(window).width();
	var hSize = $(window).height();
	$("#view1").css('width', wSize);
	$("#view1").css('height', hSize);
	$("#view2").css('width', wSize);
	$("#view2").css('height', hSize);
	$("#main").css('height', hSize);
	initPositionPackshot(wSize, hSize);
	
	var ua = navigator.userAgent;
	var isIE6 = /MSIE 6.0/.test(ua);
	isIE6 == true ? messageBox() : console.log(isIE6);

$(document).ready(function() {
	/********************************** HEADER **************************************/
	$("#main").fadeIn(800, function (){
		/*menu Header*/
		$("#menuPrincipal").addClass("active");
	});
	
	
	var isColorIn = false;	
	$('#pushIndex').hover(function(){
		switch (isColorIn){
			case (false):
				$(this).css(
					'background-color', 'rgba(25, 25, 25, .2)'
				);
				isColorIn = true;
			break;
			case (true):
			$(this).css('background-color', 'rgba(25, 25, 25, 0)');
				isColorIn = false;
			break;
			default:;
		};
	});
	/********************************** FOOTER / NAV **************************************/
	
	/*menu language*/
	var isOpenSwitch = false;
	$("#switchLanguage").click(function(e) {
		switch (isOpenSwitch){
			case (false):
				$("#footerBox").slideDown("fast").addClass("active");
				isOpenSwitch = true;
			break;
			case (true):
				$("#footerBox").slideUp("fast").removeClass("active");
				isOpenSwitch = false;
			break;
			default:;
		};
		e.preventDefault();
	});
	
	$(".menu_select_language li a").click(function(e) {
			lng = $(this).attr('class');
		$("#footerBox").slideUp('fast', function() {
			redirectUrl(lng);
		}).removeClass("active");
	});
	
	
	/************************************** CONTENT ***********************************************/
	//menu Principal
	$("#darthVador li a").click(function (e) {
		//console.log("e :: " + e.target);
		e.stopPropagation();
		item = $(this).attr('class');
				manageMenu(item);
	});
	
	/************************************** resize Stage ***********************************************/
	$(window).resize(function() {
  		stageResize();
	});
	
	//retirer les événements clavier
	//window.addEventListener('keydown',function(e){if(e.keyCode==32){e.preventDefault();}},true); 
	
	/************************************** Content BOX ***********************************************/
	$('#innerText').animate( {opacity:1}, 500 );
	$('#contentBox').animate( {height:390} );
	$("#innerMiniBox h4").css('padding-top', '19px');
	
	$('#arrow #down a').animate( {opacity:0}, 500 ).css('display','none');
	$('#arrow #up a').animate( {opacity:1}, 500 ).css('display','block');
	
	$('#arrow #down a').live("click", function(){
		console.log('DOWN');
		$('#contentBox').animate( {height:390} );
		$('#innerText').slideDown( 200 ).animate( {opacity:1}, 500 );
		$("#innerMiniBox h4").css('padding-top', '19px');
		
		$('#arrow #down a').animate( {opacity:0}, 500 ).css('display','none');
		$('#arrow #up a').animate( {opacity:1}, 500 ).css('display','block');
	});
	
	$('#arrow #up a').live("click", function(){
		console.log('UP');
		$('#contentBox').animate( {height:22} );
		$('#innerText').slideUp( 200 ).animate( {opacity:0}, 500 );
		$("#innerMiniBox h4").css('padding-top', '3px');
		
		$('#arrow #down a').animate( {opacity:1}, 500 ).css('display','block');
		$('#arrow #up a').animate( {opacity:0}, 500 ).css('display','none');
	});
	/************************************** Bath Page ***********************************************/
	$("#bath li").live({
	  mouseover: function(e) {
	   	$(this).addClass("over");
	   	el = $(this).attr('id');
		loadingBoxBath(el);
	  },
	  mouseout: function(e) {
	  		backBoxHome();
	    $(this).removeClass("over");
	  }
	});
	window.onorientationchange = updateOrientation;
	
	$('#menu2').css('left', ($(window).width()-$('#menu2').width())/2);	
	$('#menu2').css('display', 'block');
});

/***************************** Functions ***************************************************/
	function redirectUrl(lng) {
		document.location.href = "setlanguage.php?lng=" + lng;
	}

	function pathName(path) {
		 pathname = path;
	}

	function backBoxHome() {
		$("#boxBath").load('productsDesc/descHome.php').stop();
	}

	function loadingBoxBath(el) {
		switch(true){
			case (el == 1):
				$("#boxBath").load('productsDesc/desc.php').stop();
			break;
			case (el == 2):
				$("#boxBath").load('productsDesc/desc1.php').stop();
			break;
			case (el == 3):
				$("#boxBath").load('productsDesc/desc2.php').stop();
			break;
			case (el == 4):
				$("#boxBath").load('productsDesc/desc3.php').stop();
			break;
		}
	}

	function manageMenu(item) {
		switch (true){
			case (item == "muse"):
				document.location.href = "muse.php";
			break;
			case (item == "film"): 
				document.location.href = "film.php";
			break;
			case (item == "fragance"):
				document.location.href = "fragance.php";
			break;
			case (item == "bottle"):
				document.location.href = "bottle.php";
			break;
			case (item == "bath"):
				document.location.href = "bath.php";
			break;
			case (item == "behind"):
				document.location.href = "behind.php";
			break;
		}
	}

	function updateOrientation(){
		 var orientation = window.orientation;
		 orientation = (window.orientation) == 0 || (window.orientation) == 180 ? "portrait" : "landscape";
		 
		 switch(orientation)
		 {
		 	case "portrait" 	:
		 	 	document.body.setAttribute("class", "portrait");
		 	 	$('#container').removeClass('landscape').addClass('portrait');
		 	 	$('#container').css('opacity', '.2');
		 	 	alert('This site is not optimized to be watching in this position : Turn your IPAD');
		 	break;
		 	
		 	case "landscape" :
		 		document.location.href = "index.php";
		 	 	document.body.setAttribute("class","landscapeLeft");
		 	 	$('#container').removeClass('portrait').addClass('landscape');
		 	 	//alert(orientation);
		 	 	$('footer').addClass('landscapeFooter');
		 	break;
		 }
	}
	
	function displayImgIpad() {
		var iSize = $(window).width();
			if(iSize == 768){
				$('#container').css('opacity', '.2');
				alert('This site is not optimized to be watching in this position : Turn your IPAD');
			}else if (iSize == 1024){
				$('#bgimg').css('width', '1024');
				$('#bgimg').css('height', '100%');
			}
	}

	function messageBox() {
		$('header').prepend("<div id='message'><p>la navigation sur ce navigateur n'est optimisé. Veillez à upgrader celui-ci</p></div>");
	}

	function displayVideoIpad(){
		document.location.href = "ipadPlayer.php";
	}
	
	function displayBottleIpad(){
		document.location.href = "ipadPlayerbottle.php";
	}
	
	function displayBehindIpad(locate){
		document.location.href = locate;
	}
	
	function stageResize() {
			wSize = $(window).width();
			hSize = $(window).height();
			initPositionPackshot(wSize, hSize);
			$("#view1").css('width', wSize);
			$("#view1").css('height', hSize);
			$("#view2").css('width', wSize);
			$("#view2").css('height', hSize);
			$("#main").css('height', hSize);
	}
		
	function initPositionPackshot(w , h) {
		packWidth = $('#packshot').width();
		packHeight = $('#packshot').height();
		menuWidth = $('#menu2').width();
		var posX = ( w - packWidth ) / 2; 
		var posY = ( h - packHeight );
		
		//position packshot
		$('#packshot').css({
			position: 'fixed',
			top: posY,
			right: 0
		});
	
		//position packshot
		$('#menu2').css({
			left: (w - menuWidth) / 2
		});
		
	}


