// JavaScript Document

//run the currently selected effect
	function runEffectDock(distance){
		// Animation

		var animation = {};
		
		window.document.getElementById("scrollRight").src = "images/scroll_right.png"
		window.document.getElementById("scrollLeft").src = "images/scroll_left.png"		
	
		var str_pos = document.getElementById("product_lst").style.left;
		var int_pos = parseFloat(str_pos.substr(0,str_pos.length-2)) 
		if (isNaN(int_pos)) int_pos=0;
		
		int_pos += distance;
		
		if (distance>=0 && int_pos >= 0){
			int_pos = 0;
			window.document.getElementById("scrollLeft").src = "images/scroll_left_nobutton.png";

		}else if (distance<0 && Math.abs(int_pos) >= (document.getElementById("product_lst").offsetWidth - document.getElementById("product_menu_lst").offsetWidth)){
			int_pos = -1*(document.getElementById("product_lst").offsetWidth - document.getElementById("product_menu_lst").offsetWidth);				
			window.document.getElementById("scrollRight").src = "images/scroll_right_nobutton.png";
		}

		animation['left'] = int_pos;
		
		//run the effect
		$("#product_lst").animate(animation, { queue: false, duration: 1000, easing: 'easeOutQuad'});

	};

$(function() {
	
	//set effect from select menu value
	$("#lst_left_arrow").click(function() {
		runEffectDock(232);
		DisplaySousCategorie(0);
		return false;
	});
	
	//set effect from select menu value
	$("#lst_right_arrow").click(function() {
		runEffectDock(-232);
		DisplaySousCategorie(0);
		return false;
	});

	
});

var lastTimer;

function DisplaySousCategorie(NoCategorie){
	
	var AllDiv = window.document.getElementsByTagName("div");
	
	clearTimeout(lastTimer);
	
	for (i = 0; i < AllDiv.length-1; i++) {
		if (Left(AllDiv[i].id, 10) == 'categorie_'){
			AllDiv[i].style.display='none';
		}
	}
	if(trim(document.getElementById('categorie_'+NoCategorie).innerHTML) == ""){
		SubmitString = "noCategorie=" + NoCategorie;	
		var tmp_contenu = getRequest('gestion/get_souscategories_menu.asp', SubmitString);	
		document.getElementById('categorie_'+NoCategorie).innerHTML = tmp_contenu;
	}
	if (NoCategorie != 0){
		var myPhotoObj = window.document.getElementById('photo_cat_'+NoCategorie);
		var myDivObj = window.document.getElementById('categorie_'+NoCategorie);
		
		var OffsetLeft = getposOffset(myPhotoObj, 'left');
		var OffseTop = getposOffset(myPhotoObj, 'top');
		
		//alert(OffseTop);
		
		
		
		myDivObj.style.display='block';
		
		myDivObj.style.left = OffsetLeft + "px";
		myDivObj.style.top = (OffseTop - myDivObj.offsetHeight) + "px";	
		
		/*
		myDivObj.style.posLeft = OffsetLeft;
		myDivObj.style.posTop = (OffseTop - myDivObj.offsetHeight);			
		*/
	}
}


var lastTimer;
function HideSousCategorie(NoCategorie){
	//var myDivObj = window.document.getElementById('categorie_'+NoCategorie);
	clearTimeout(lastTimer);
	lastTimer = setTimeout("HideSousCategorieReal("+NoCategorie+");", 500);
}

function HideSousCategorieReal(NoCategorie){
	window.document.getElementById('categorie_'+NoCategorie).style.display='none';
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}



