// JavaScript Document

/*
  VIDEO ET PHOTO PAGE ACCEUIL
  ALTI-COM - 2011
*/

var photovideo={
        nbSlide:0,
		nbCurrent:1,
        elemCurrent:null,
        elem:null,
        timer:null,

        init:function(elem,autostart){
                this.nbSlide=elem.find(".slide").length;
				this.nbCurrent=1;
				this.elem = elem;
				
				this.show(elem);

				this.elem.find(".slide").hide();
                this.elem.find(".slide:first").show();
				
                this.elemCurrent=elem.find(".slide:first");
				
                this.elem.find(".navigation .nav:first").addClass("active");
				
				photovideo.stop();
                if(autostart==true)
				{
					photovideo.play();
				  	this.elem.mouseover(photovideo.stop);
                	this.elem.mouseout(photovideo.play);
				}
				
				this.elem.find(".navigation .nav").click(function(){
					photovideo.gotoSlide(parseInt($(this).attr("name")));
				})
				
				this.elem.find(".navigation .prec").click(function(){
					photovideo.prev();
				})
				this.elem.find(".navigation .suiv").click(function(){
					photovideo.next();
				})
				
              
        },
		
		hide:function(elem){
			elem.hide();
		},
		
		show:function(elem){
			elem.show();
		},

        gotoSlide:function(num){
			if(num==this.nbCurrent){return false;}

			this.elemCurrent.fadeOut();
			this.elem.find("#slide"+num).fadeIn('slow');
			this.elem.find(".navigation .nav").removeClass("active");
			this.elem.find(".navigation .nav[name="+num+"]").addClass("active");
			this.nbCurrent=num;
			this.elemCurrent=this.elem.find("#slide"+num);
        },

        next:function(){
             if (window.focus)
			 {
			    var num=parseInt(this.nbCurrent)+1;
                if(num>this.nbSlide){num=1;}
                this.gotoSlide(num);
			 }
        },

        prev:function(){
                var num=parseInt(this.nbCurrent)-1;
                if(num<1){num=this.nbSlide;}
                this.gotoSlide(num);
        },

        stop:function(){
			window.clearInterval(photovideo.timer);
		},
		
        play:function(){
                window.clearInterval(photovideo.timer);
                photovideo.timer=window.setInterval("photovideo.next()",4000);
        }
}

$(document).ready(function() {
		   $('#photovideo').show();
		   photovideo.init($("#photo"),true);
		   $('#affichephoto').addClass("active");
		   photovideo.hide($("#video"));
		   
		   $('#affichephoto').click( function() {
				$('#reservation').show();
				$('#affichephoto').addClass("active");
				$('#affichevideo').removeClass("active");
				photovideo.init($("#photo"),true);
		   		photovideo.hide($("#video"));			  			  
			});
		   
		    $('#affichevideo').click( function() {
				$('#reservation').hide();
				$('#affichevideo').addClass("active");
				$('#affichephoto').removeClass("active");
				photovideo.init($("#video"),false);
		   		photovideo.hide($("#photo"));			  			  
			});	   
});
