// FONCTIONS DE POSITIONNEMENT
function getScrollY()
{
	pos = false;

	if (window.pageYOffset)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	return pos;
}

function getScrollX()
{
	pos = false;

	if (window.pageXOffset)
	{
		  pos = window.pageXOffset
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
	{
		pos = document.documentElement.scrollLeft
	}
	else if (document.body)
	{
		  pos = document.body.scrollLeft
	}
	return pos;
}

function getScreenInnerHeight()
{
	h = false;
	if (window.innerHeight)
	{
		h = window.innerHeight
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		h = document.documentElement.clientHeight
	}
	else if (document.body)
	{
		h = document.body.clientHeight
	}
	return h;
}

function getScreenInnerWidth()
{
	w = false;
	if (window.innerWidth)
	{
		w = window.innerWidth
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		w = document.documentElement.clientWidth
	}
	else if (document.body)
	{
		w = document.body.clientWidth
	}
	return w;
}

function visualiserAgrandissement(imgId)
{
	var popup = window.open('agrandissment.php?imgId='+imgId,'agrandissement','resizable=yes,scrollbars=yes,top=0,left=0,width=500,height=400,status=no');
	popup.focus();
}


function openBrowserWindow(noProduit, idMediaAssocie)
{
	largeur = Math.round(getScreenInnerWidth()*0.8);
	hauteur = Math.round(screen.height*0.6);

	window.fenPop = window.open('browser.php?iEmePage=0&noProduit='+ noProduit+ '&idMediaAssocie='+idMediaAssocie,'browserImages','resizable=yes,scrollbars=yes,top=0,left=0,width='+largeur+',height='+hauteur);
	window.fenPop.focus();
}

/**
 * Attache les action aux menu de pages (produits.php et browser.php
 */
function evtMenuPage()
{
	// Menu de pages
	$$('.menuPage').each(function(ul) {
		ul.select('li a').invoke('observe', 'click', function(evt) {
			evt.stop();
			var a = evt.element();
			var iPage = a.id.substring(a.id.lastIndexOf('_')+1)
			var rgx1 = /iEmePage=\d{1,3}&/;
			var rgx2 = /iEmePage=\d{1,3}/;
			var url = window.location.href;
			var ancre = '';
			if(url.indexOf('#') != -1)
			{
				ancre = url.substring(url.indexOf('#'));
				url = url.substring(0, url.indexOf('#'));
			}
			if(rgx1.test(url))
				url = url.replace(rgx1, 'iEmePage='+iPage+'&');
			else if(rgx2.test(url))
				url = url.replace(rgx2, 'iEmePage='+iPage);
			else if(url.indexOf('?') != -1)
				url = url + '&iEmePage='+iPage;
			else
				url = url + '?iEmePage='+iPage;

			if(ancre != undefined)
				url += ancre;

			window.location.href = url;
		});
	});
}
