
/*
  Vide les champs lorsqu'ils sont sélectionné
*/
$(function(){
    
    $(".autoEmpty").each(function(){
        var defaultText = $(this).val();
        $(this).focus(function(){
            if($(this).val()==defaultText){
                $(this).val("");
            }
        });
        $(this).blur(function(){
            if($(this).val()==""){
                $(this).val(defaultText);
            }
        });
    });
    
});


/*
    CARROUSEL JS
*/


var carrousel = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slide").length;
        
       
        
        // Initialisation du carrousel
        this.elem=elem;
        elem.find(".slide").hide();
        elem.find(".slide:first").show();
        this.elemCurrent = elem.find(".slide:first");
        this.elem.find(".navigation").css("opacity",0.6);   // On rend la navigation opaque
        this.elem.find(".navigation span:first").addClass("active");
        
        // On cré le timer
        carrousel.play();
        // Stop quand on passe dessus
        elem.mouseover(carrousel.stop);
        elem.mouseout(carrousel.play);
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
           
        this.elemCurrent.find(".visu").fadeOut();
        this.elem.find("#slide"+num).show();
        this.elem.find("#slide"+num+" .visu").hide().fadeIn();
        var titleHeight = this.elemCurrent.find(".title").height();
        this.elemCurrent.find(".title").animate({"bottom": -titleHeight},500);
        this.elem.find("#slide"+num+" .title").css("bottom",-titleHeight).animate({"bottom": 0},500);    
        
        this.elem.find(".navigation span").removeClass("active");
        this.elem.find(".navigation span:eq("+(num-1)+")").addClass("active");
        this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#slide"+num);
    },
    
    next : function(){
        var num  = this.nbCurrent+1;
        if(num  >this.nbSlide){
            num  = 1;
        }
        this.gotoSlide(num);
    },
    prev : function(){
        var num  = this.nbCurrent-1;
        if(num< 1){
            num= this.nbSlide;
        }
        this.gotoSlide(num);
    },
    stop : function(){
        window.clearInterval(carrousel.timer);
    },
    play : function(){
        window.clearInterval(carrousel.timer);
        carrousel.timer = window.setInterval("carrousel.next()",5000);
    }

}
/*initialisation du caroussel*/
$(function(){
    carrousel.init($("#carrousel"));
});

/*	Scrolling sur les ancres */
$(document).ready(function(){
	$('a[href^=#]').click(function() {
		cible=$(this).attr('href');
		scrollTo(cible);
		return false;
	});
});

function scrollTo(cible){
	if($(cible).length>=1){
		hauteur=$(cible).offset().top;
	}
	else{
		hauteur=$("a[name="+cible.substr(1,cible.length-1)+"]").offset().top;
	}
	hauteur -= (windowH()-$(cible).height())/2;
	$('html,body').animate({scrollTop: hauteur}, 1000);
	return false;
}

function  windowH(){
	if (window.innerHeight) return window.innerHeight  ;
	else{return $(window).height();}
}

/*menu deroullant*/
$(document).ready(function(){

	//$j("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	$("ul.menu li a").addClass("deroul");
	$(".sub-menu li a").removeClass("deroul");
	
	$("li .deroul").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).addClass("menuhov");
		$(this).parent().find("ul.sub-menu").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.sub-menu").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			$(this).parent().find(".menuhov").removeClass("menuhov");
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});

//Positionnement du conteneur par rapport à l'écran
positionwrap = {	

		init : function() {	
		$("body.home").append("<div id='lightbox'><div id='lightbox_wrapper' class='lightbox_close'></div><div id='lightbox_contener'><div id='lightbox_content'></div><div class='lightbox_close' id='closezone'></div></div>");
		$('#lightbox_wrapper').css({'opacity': 0.7});	
		/*$("#lightbox_contener").append("<span style=\"width:480px;height:384px;\" class=\"vvqbox vvqflv\"><object width=\"480\" height=\"384\" type=\"application/x-shockwave-flash\" data=\"http://www.pencaksilat.fr/wp-content/plugins/vipers-video-quicktags/resources/jw-flv-player/player.swf\" id=\"vvq-308-flv-1\" style=\"visibility: visible;\"><param name=\"wmode\" value=\"opaque\"><param name=\"allowfullscreen\" value=\"true\"><param name=\"allowscriptaccess\" value=\"always\"><param name=\"flashvars\" value=\"wmode=transparent&amp;allowfullscreen=true&amp;allowscriptaccess=always&amp;file=http://www.pencaksilat.fr/video/panglipurstbsa.flv&amp;volume=100&amp;bufferlength=15&amp;image=http://www.pencaksilat.fr/video/panglipurstbsa.jpg\"></object></span><a href='#' id=\"wrapclose\">Fermer la fenêtre et accèder au site</a>");*/
			$("#lightbox_content").append("<div class='shootbox' id='exterieur'><div id='interieur'><a href='http://www.blini.fr/categorie/nos-produits/tartineretcuisiner/' class='go_tartiner'></a><a href='http://www.blini.fr/categorie/recettes/' class='go_recettes'></a><div class='acces_site lightbox_close'></div></div></div>");
		/*$("#wrapbox").append("<embed src=\"http://www.pencaksilat.fr/wp-content/themes/pencak/js/zoombox/FLVplayer.swf\" width=\"460\" height=\"384\" allowscriptaccess=\"always\" allowfullscreen=\"true\" flashvars=\"file=http://www.pencaksilat.fr/video/panglipurstbsa.flv&width=460&height=384&autostart=true\" wmode=\"transparent\" /><a href='#' id=\"wrapclose\">Fermer la fenêtre et accèder au site</a>");*/
		$("#wrapclose").click(function(){
			$("#wrapbox").empty().hide();	
			return false;	
				});	
				
		$(".lightbox_close").click(positionwrap.close);	
		
	
		//$("#lightbox_wrapper").css({"height":positionwrap.windowH(),"width":positionwrap.windowW()});		
		//on indique les tailles du conteneur qui sera placé
		positionwrap.largeur = 579;
		positionwrap.hauteur = 440;
		//on lance la fonction
		positionwrap.resize();	
		//si la fenetre bouge, on relance la fonction
		$(window).resize(positionwrap.resize);
		
		},
		close : function(){$("#lightbox_contener").empty(); $("#lightbox_contener").remove(); $("#lightbox_wrapper").animate({"opacity":0},500,positionwrap.remove);},		
		remove : function(){$("#lightbox").remove(); $("#lightbox_loader").remove(); $("embed").css("visibility","visible"); $("object").css("visibility","visible");},
		resize : function(){
		$("#lightbox_contener").css("left", "100px");
		positionwrap.varposi = positionwrap.windowW;
		//alert(positionwrap.varposi);
		positionwrap.positionh =(positionwrap.windowH()-positionwrap.hauteur)/2;
		positionwrap.positionl =(positionwrap.windowW()-positionwrap.largeur)/2;
		
		//alert (positionwrap.positionh);
		//alert (positionwrap.positionl);
		//si la position top est négative, on oblige a placer en absolu à 0 sinon on centre
		if(positionwrap.positionh < 1){$("#lightbox_contener").css("top", "0px");}
		else {$("#lightbox_contener").css("top", positionwrap.positionh+"px");}
		//si la position left est négative, on oblige a placer en absolu à 0 sinon on centre
		if(positionwrap.positionl < 1){$("#lightbox_contener").css("left","0px");}
		else {$("#lightbox_contener").css("left", positionwrap.positionl +"px");}
		},
	
		//on détermine et on retourne la hauteur de la fenêtre
			windowH : function(){
				if (window.innerHeight) {return window.innerHeight;}
				else{return $(window).height();}

			},
		//on détermine et on retourne la largeur de la fenetre
			windowW : function(){
				if (window.innerWidth) return window.innerWidth  ;
				else{return $(window).width();}
			},
		//on détermine et on retourne la position du top avec scrOfy
			scrollY : function() {
				scrOfY = 0;
				if( typeof( window.pageYOffset ) == 'number' ) {
					//Netscape compliant
					scrOfY = window.pageYOffset;
				} else if( document.body && ( document.body.scrollTop ) ) {
					//DOM compliant
					scrOfY = document.body.scrollTop;
				} else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
					//IE6 standards compliant mode
					scrOfY = document.documentElement.scrollTop;
				}
				return scrOfY;
			},
		//on détermine et on retourne la position du scroll left
			scrollX : function() {
				scrOfX = 0;
				if( typeof( window.pageXOffset ) == 'number' ) {
					//Netscape compliant
					scrOfX = window.pageXOffset;
				} else if( document.body && ( document.body.scrollLeft ) ) {
					//DOM compliant
					scrOfX = document.body.scrollLeft;
				} else if( document.documentElement && ( document.documentElement.scrollLeft ) ) {
					//IE6 standards compliant mode
					scrOfX = document.documentElement.scrollLeft;
				}
				 return scrOfX;
			}
			

};	


