// JavaScript Document
// alert('ok!');

$(document).ready(function(){
	var msc_nOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
	var msc_nIe = (document.all && !msc_nOpera && navigator.platform == "Win32")? true : false;
	var msc_nIe7 = (navigator.userAgent.indexOf('MSIE 7') != -1)? true : false ;
	var msc_chrome = (navigator.userAgent.indexOf('Chrome') != -1)? true : false ;
	
	$('.nav .itemOver').each(function(){
		this.check = true;
		this.check2 = true;
	});
	
	$('.nav .itemOver').mouseenter(function(){
		if (this.check) {
			this.check = false;
			myItems = 0;
			$('.navCont li', this).each(function(){
				myItems = myItems +1;
			});
			myHeight = (myItems*30)-1;
		
			$('.navCont', this).animate({ height:myHeight+'px' }, 200);
		}
	});
	
	$('.nav .itemOver').mouseleave(function(){
		if (this.check2) {
			this.check2 = false;
			var myItem = this;
			$('.navCont', this).animate({ height:0 }, 200, function(){
				myItem.check = true;
				myItem.check2 = true;
			});
		}
	});
	
	$('.media .mediaBox a').click(function(){
		var imgTemp = '<a href="'+$(this).get(0).rel+'" rel="myZoom"><img src="'+$(this).get(0).rev+'" alt="" title="" /></a>';
		$('.descLeft .visu').html(imgTemp);
		initZoom();
	});
	
	initZoom();
});
	
function initZoom() {	
	$("a[rel='myZoom']").colorbox({transition:"fade"});
}

function goLayer () {
	$.ajax({ url: "cgu.html", success: function(data){
		$('#myLayerCont').html(data);
		$('.layer').css({ display:'block' });
		$('.myLayer').css({ display:'block' });
		jQuery('.layer').animate({ opacity:'0.7' }, 1000, function(){ });
		jQuery('.myLayer').animate({ opacity:'1' }, 1000, function(){ });
    }});
}

function closeLayer (o) {
	jQuery('.layer').animate({ opacity:'0' }, 1000, function(){
		$(this).css({ display:'none' });
	});
	jQuery('.myLayer').animate({ opacity:'0' }, 1000, function(){
		$(this).css({ display:'none' });
		if (o) { $('#myLayerCont').html(''); }
	});
}

function ajoutPanier(code_prd) {
    $.post("/rpc/ajoute-panier.php",
      {carte: code_prd},
      function(data) {
        $('#panier').html(data);
	goLayerPanier();
      }
    );
}

function plusPanier(code_prd) {
    $.post("/rpc/ajoute-panier.php",
      {carte: code_prd},
      function(data) {
        $('#panier').html(data);
      }
    );
}

function moinsPanier(code_prd) {
    $.post("/rpc/retire-panier.php",
      {carte: code_prd},
      function(data) {
        $('#panier').html(data);
      }
    );
}

function videPanier() {
  $.post("/rpc/annule-panier.php", {},
      function(data) {
        $('#panier').html(data);
      }
  );
}

function goLayerPanier() {
    $.post("/rpc/get-panier.php",
      {},
      function(data) {
        $('#panier-layer').html(data);
        updateLayerPanier();
      }
    );

        $('.layer').css({ display:'block' });
        $('.myLayerPanier').css({ display:'block' });
        jQuery('.layer').animate({ opacity:'0.7' }, 1000, function(){ });
        jQuery('.myLayerPanier').animate({ opacity:'1' }, 1000, function(){ });
}

function updateLayerPanier() {
        var lpHeight = $('.myLayerPanier .panier').height();
        $('.myLayerPanier').css({ height:lpHeight, marginTop:-(lpHeight/2) });
}

