var api;

function init() {
i=0;
tab = new Array();
$(".items img").each(function () {
tab[i] = $(this).attr("id");
i++;
});

$(".scrollable").scrollable({ 
vertical: true, 
mousewheel: true,
onSeek:function () {
oil = this.getIndex();
//alert(oil);
$("body").css('background-image', 'url(../img_dyna/'+tab[oil]+'.jpg)');
},
circular: true}).autoscroll({ interval: 6000 });	


$(".avec_tooltip[title]").tooltip({			
	offset: [150, 2],
	position: "top center",
   // use the "slide" effect
   	effect: 'slide'
	});
	
	
	$("a.prev").fadeTo("fast", 0.2);
	$("a.next").fadeTo("fast", 0.2);
	$("a.prev").hover(function () {
			$(this).fadeTo("fast", 1);
		},function () {
			$(this).fadeTo("fast", 0.2);
		});
	$("a.next").hover(function () {
		$(this).fadeTo("fast", 1);
	},function () {
		$(this).fadeTo("fast", 0.2);
	});

}

function init_ref () {

if(document.getElementById("menu_gauche")) {
// SCROLL BAR POUR MENU GAUCHE LISTE REFERENCES

active_deplace_menu();
active_taille_menu ();
api = $('.scroll-pane').jScrollPane(
		{
			showArrows:true,
			maintainPosition: true
		}
	).data('jsp');	
// CALCULE DE LA HAUTEUR //
api.reinitialise({
     showArrows: true
 }); 

	// ONRESIZE //	 
	window.onresize = function (){
	hauteur_scroll ();
	api.reinitialise({
	        showArrows: true
	    }); 
	} // FIN ONRESIZE //	 
	
	// ONSCROLL //	 
	window.onscroll = function (){
	hauteur_scroll ();
	api.reinitialise({
	        showArrows: true
	    }); 
	}	// FIN ONSCROLL //	
} // FIN SI MENU GAUCHE //


	
	
// AFFICHE VIGNETTE MENU GAUCHE REFERENCES
if(document.getElementById("small_image")){
$(".scroll-pane li:not(.active)").hover(function(){		

	if($(this).hasClass("active")==false){
	
	document.getElementById("small_image").innerHTML = '<div style="text-align:center;width:200px;"><img src="/img_com/loading.gif" alt="" style="margin-top:0px;" width="20" height="20" /></div>';
	ln = '<div class="small_image_haut"></div><div class="small_image_centre"><img src="/img_dyna/prod-'+$(this).attr("id")+'.jpg" width="200" alt=""></div><div class="small_image_bas"></div>';
	position = $(this).position();	
	moin = $(".jspPane").css('top');	
	posi_v = (position.top);
	//alert(parseInt(moin));
	posi_total = (parseInt(position.top)+ parseInt(moin))+30;
	//alert(posi_total+"="+moin);
	//
	//alert(posi_v+" - "+moin+" = "+posi_total);
	
	//alert(parseInt(posi_v) + " ->"+moin+"="+posi_total);
	
	if(getCookie("menu_gauche")=="menu_coller_droite" && $("#block_central").hasClass("grand")) {
	$("#small_image").css('left', (position.left)-220);
	}else {
	$("#small_image").css('left', (position.left)+280);
	}
	$("#small_image").css('top', posi_total);
	$("#small_image").show();
	
	im = new Image();
	im.src = "/img_dyna/prod-"+$(this).attr("id")+".jpg";
	if (im.complete){
	show_html (ln) ;
	
	
	
	} else {
		im.onload = function () {		
		show_html (ln) ;
		}
	}
	//$("#visu_photo").text(ln);
	
	//$(this).find("ul.bouton_roll").not(':animated').slideDown("normal");
	} // FIn si pas de class Active
	
	}
	,function(){
	$("#small_image").hide();
	}
	);	
}
	
	
$(".scroll-pane li").click(function () {
	if($(this).attr("ref")!='' && $(this).attr("ref")!=undefined) {
	show_ref(this);
	}
});
} // ***************** FIN INIT () ********************* //


function active_deplace_menu() {
var draggable = document.getElementById('menu_gauche');
var options =  {
	handle : document.getElementById('picto_deplace'),
	movingClass : 'bouge',
	cssPosition : 'fixed',
	moveArea : document.getElementById('block_central')
};
dragOn.apply( draggable, options );
}



// Active overlay //
function active_overlay () {
$("#moyen_image img[rel]").overlay({
		closeOnClick: true,
		expose: '#3c3951',
		top: 10,
		opacity:1,
		fixed: false
		
	});
$("#fleche_precedente").css('opacity', 0.5);
$("#fleche_suivante").css('opacity', 0.5);
// rollover sur les fleche precedente //
$("#fleche_precedente").mouseover(function(){$(this).fadeTo('slow',1);});
$("#fleche_precedente").mouseout(function(){$(this).fadeTo('slow',0.5);});	

// rollover sur les fleche Suivante //
$("#fleche_suivante").mouseover(function(){$(this).fadeTo('slow',1);});
$("#fleche_suivante").mouseout(function(){$(this).fadeTo('slow',0.5);});	
}



function show_html (ln) {
document.getElementById("small_image").innerHTML = ln;
}


// DONNE LA TAILLE DU SCROLL DE LA FENTRE //
function donne_valeur_scroll () {
taille_scroll = 0;
if(document.documentElement.scrollTop){
taille_scroll = document.documentElement.scrollTop;
}else if(window.pageYOffset) {
taille_scroll = window.pageYOffset;
}else if (document.body.scrollTop) {
taille_scroll = document.body.scrollTop;
}
return taille_scroll;
}


// DEBUT APPLIQUE LE MENU DE GAUCHE //
function hauteur_scroll () {
taille_scroll = 0;	
taille_total_largeur = $(window).width();
if(((taille_total_largeur-1000)/2) < 180) {	
	$("#block_central").removeClass("grand");			
	$("#menu_gauche").css("left","auto");
	fixe_menu_interne();	
} else {
	if (getCookie("menu_gauche")=="menu_libre") {	
		dragOn.place(document.getElementById('menu_gauche'));
	}  else if (getCookie("menu_gauche")=="menu_coller_gauche") {
		fixe_menu_gauche();
	}  else if (getCookie("menu_gauche")=="menu_coller_droite") {
		fixe_menu_droite();
	} else if(getCookie("menu_gauche")=="" || getCookie("menu_gauche")=="menu_interne") {
		fixe_menu_interne();		
	}
}


}
// FIN hauteur_scroll //

function modif_menu_gauche (taille) {
$(".scroll-pane").css('height',taille);
$(".jspScrollable").css('height',taille);
$(".jspContainer").css('height',taille);
$(".jspTrack").css('height',taille-32);
api = $('.scroll-pane').jScrollPane(
		{
			showArrows:true,
			maintainPosition: true
		}
	).data('jsp');	
api.reinitialise({
        showArrows: true
    }); 
}

function fixe_menu_gauche () {
$("#block_central").addClass("grand");	
taille = parseInt($("#global").height())-50;
hauteur_window = parseInt($(window).height());
taille = hauteur_window -80;
position = $("#pos_cont").position();
$("#menu_gauche").css('left',parseInt(position.left)-300);
$("#menu_gauche").css('top',10);
setCookie("menu_top",10,365);
setCookie("menu_left",parseInt(position.left)-300,365);	
setCookie("menu_gauche","menu_coller_gauche",365);
modif_menu_gauche (taille);
}

function fixe_menu_droite () {
$("#block_central").addClass("grand");	
taille = parseInt($("#global").height())-50;
hauteur_window = parseInt($(window).height());
taille = hauteur_window -80;
position = $("#pos_cont").position();
$("#menu_gauche").css('left',parseInt(position.left)+994);
$("#menu_gauche").css('top',10);
setCookie("menu_top",10,365);
setCookie("menu_left",parseInt(position.left)+994,365);	
setCookie("menu_gauche","menu_coller_droite",365);
modif_menu_gauche (taille);
}

function fixe_menu_interne () {
taille_scroll = donne_valeur_scroll ();
top_menu_gauche = parseInt(250-parseInt(taille_scroll));
	if(taille_scroll>250) {
	$("#menu_gauche").css('top',0);
	taille_scroll= 250;
	}else {
	$("#menu_gauche").css('top',top_menu_gauche);
	}
lat_scrollpane = parseInt(($(window).height())-320)+taille_scroll;
lat_menu_gauche = parseInt(($(window).height())-180)+taille_scroll;	
	if(lat_menu_gauche>300) {
	modif_menu_gauche (lat_scrollpane);
	}
}
// FIN AFFICHE VIGNETTE MENU GAUCHE REFERENCES //


function GetXmlHttpObject(handler){ 
var objXMLHttp=null;
	if (window.XMLHttpRequest){
	objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
return objXMLHttp;
}

// AFFICHE DETAIL REFERENCES //
function lance_ref(id_prod) {
show_ref(document.getElementById(id_prod));
}



// DEBUT AFFICHE LES FICHES PRODUITS //
function show_ref(prod) {
$(".chargement").fadeIn();
var id_prod= $(prod).attr("id");
if(window.history.pushState) {
window.history.pushState(document.title,document.title,$(prod).attr("ref"));
}
//alert($(prod).find("strong").html());
$("ul.ariane a:last").html($(prod).find("strong").html());
$("ul.ariane a:last").attr("href",$(prod).attr("ref"));
$(".scroll-pane li").removeClass("active");
$(prod).addClass("active");
document.title = $(prod).find("strong").html()+" - Nos Références de création de site Internet -  DYNA CREATION - Conception, réalisation, hébergement et référencement de site internet";

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;
} 
var url="/_inc/detail_prod.php"
url=url+"?id_prod="+id_prod
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=function() { 
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200) {
               Changed(xmlHttp, id_prod);
			}
    }
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
// FIN AFFICHE LES FICHES PRODUITS //

// CHANGE LE CONTENU D'UNE REFERENCE //
function Changed(dett, id_prod){
//document.getElementById("texte_contenu").innerHTML = '<div style="text-align:center;padding-top:180px;padding-bottom:180px;"><img src="/img_com/loading.gif" alt="" style="margin-top:0px;" width="20" height="20" /></div>';
document.getElementById("small_image").style.display='none';
theimage = new Image;
theimage.src = "/img_dyna/gr-prod-"+id_prod+".jpg";
cont = dett.responseText;
	if (theimage.complete){
	chargeImage(cont);
	} else {
		theimage.onload = function () {
		chargeImage(cont);
		}
	}
}
// FIN CHANGE LE CONTENU D'UNE REFERENCE //

function chargeImage(cont) {
$(".chargement").fadeOut(10);
$('#texte_contenu').fadeOut(400, function() {
        // Animation complete
		document.getElementById("texte_contenu").innerHTML = cont;
		liens  = $("#moyen_image img").attr("src");
		document.getElementById("gr_zoom").src = liens.replace("/med","/gr");
		active_overlay ();		
      });
 $('#texte_contenu').fadeIn(800);
}








