/******************************************************************************
* gershFrontShowroom.js
*******************************************************************************

*******************************************************************************
*                                                                             *
* Copyright 2010									                          *
*                                                                             *
******************************************************************************/

var posPosters = new Array();
var absTop;
var	startPos;
function heliosInit() {
	var Dom = YAHOO.util.Dom;
	var Event= YAHOO.util.Event;
	eteindToutesInfos = function (ev) {
		for (oZoom in aListeZoom){
			eteind('infos'+aListeZoom[oZoom]);
		}
	}

	afficheInfo = function (ev, eltInfos) {
		//alert(eltInfos.id);
		eteindToutesInfos();
		allume(eltInfos.id);
	}

	allume = function (eltInfos) {
		var imgInfos = Dom.getRegion("imgPoster");
		var idBg = "bgGrey" + eltInfos.substring(5, eltInfos.length);
		//alert(imgInfos);
		Dom.get(idBg).style.height = imgInfos.height + "px";
		var idDescr = "infos" + eltInfos.substring(5, eltInfos.length);
		//alert("allume " + idElt);
		//Dom.replaceClass(eltInfos, "infosOff", "infosOn");
		//Dom.get("descrZooms").style.zIndex = 4;
		Dom.replaceClass(idDescr, "infosOff", "infosOn");
	}

	eteind = function (eltInfos) {
		var idBg = "bgGrey" + eltInfos.substring(5, eltInfos.length);
		var idDescr = "infos" + eltInfos.substring(5, eltInfos.length);
		//alert("eteind " + idElt);
		//Dom.replaceClass(eltInfos, "infosOn", "infosOff");
		//Dom.get("descrZooms").style.zIndex = 1;
		Dom.replaceClass(idDescr, "infosOn", "infosOff");
	}
	if(typeof(aListeZoom) != "undefined") {
		for (oZoom in aListeZoom) {
			var elt = Dom.get(oZoom);
			/*
			Event.addListener(elt, "mouseover", afficheInfo, 'infos'+aListeZoom[oZoom]);
			Event.addListener(elt, "mouseout", eteindToutesInfos);
			*/
			Event.addListener(elt, "mouseenter", afficheInfo, 'infos'+aListeZoom[oZoom]);
			Event.addListener(elt, "mouseleave", eteindToutesInfos);
		}	
	}
	
	absTop = Dom.getY("posterList");
	
	for (var iPoster=1; iPoster<=20; iPoster++) {
		/*var eltVignette = Dom.get("ancre"+iPoster);
		if (eltVignette) {*/
			var oRegionY = Dom.getY("ancre"+iPoster)
			if (oRegionY) {
				posPosters[iPoster]=oRegionY-absTop;
			}else {
				posPosters[iPoster]=false;
			}
		//}
		
	}
	
	startPos = Dom.getXY("scrollList");
	
	donnePosterPosition = function (iPosition) {
		iTop=0;
		//iViewerHeight = YAHOO.util.Dom.getRegion("posterList").height - 30;
		//iListHeight = YAHOO.util.Dom.getRegion("scrollList").height;
		
		if (iPosition>1) {
			iTop=-posPosters[iPosition-1];
		}
		/*
		iBottom = iTop+iListHeight;
		if (iBottom < iViewerHeight) {
			iTop = iViewerHeight - iListHeight;
		}*/
		return iTop;
	}
	
	
	changePositionPoster= function (iPosition) {
		var posX = Dom.getXY("scrollList")[0];
	
		new YAHOO.util.Motion( 
			"scrollList", { 
				points: { 
					to: [posX,startPos[1]+donnePosterPosition(iPosition)]
				}
			}, 
			0.3, 
			YAHOO.util.Easing.easeOut 
		).animate();
		
		//Dom.setStyle("scrollList","top",""+donnePosterPosition(iPosition)+"px");
	}
	
	posterPrecedent = function () {
		if (iPosterCourant>1) {
			iPosterCourant--;
		}
		
		changePositionPoster(iPosterCourant);
	}
	
	posterSuivant = function () {
		if (iPosterCourant<20 && posPosters[iPosterCourant+1]) {
			iPosterCourant++;
		}
		
		changePositionPoster(iPosterCourant);
	}
	
	// re-positionnement initial
	changePositionPoster(iPosterCourant);
	
	Event.addListener("upBtn", "click", posterPrecedent);
	Event.addListener("downBtn", "click", posterSuivant);
}
