// JavaScript Document
var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
if (isOpera) isIE = false;


// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){
	var yScroll;
	var xScroll;
	if (self.pageYOffset)
	{
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}
	// Explorer 6 Strict
	else if (document.documentElement && document.documentElement.scrollTop)
	{	
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}
	// all other Explorers
	else if (document.body)
	{
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	var arrayPageScroll = new Array(xScroll,yScroll); 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;

	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}
	var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function mouseposition(e)
{
	var x, y;
	if (e.pageX || e.pageY) { //ff et opera
		x = e.pageX;
		y = (e.pageY);
	}else if (e.clientX || e.clientY) { //ie 6 et 7
		x = e.clientX;
		y = (e.clientY);
		if (isIE)
		{
			//on ajoute ici pour IE la valeur du Scroll en plus a x et y , car
			// e.clientX et e.clientY nous donne les valeurs relatives, mais pas sur tout le document
			//à l'inverse de FF ou Opera, donc on les rajoutes pour savoir où on est dans le document
			//et non dans l'écran
			ScrollVals = getPageScroll();
			x += ScrollVals[0] ; //scrollLeft
			y += ScrollVals[1]; //scrollTop
		}
	}
	return Array(x,y);
}

var ie=document.all;
var ns6=document.getElementById&&!document.all;

function ietruebody()
{
	return (document.compatMode!="BackCompat") ? document.documentElement : document.body;
}

var posMouseX = 0
var posMouseY = 0
function position(e) {
	posMouseX = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
	posMouseY = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
	//window.status = "Souris x:"+x+" | y:"+y;
}

if (navigator.appName.substring(0,3) == "Net")
	document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = position;
function zoom2(which, e, position, imgwidth, imgheight)
{

	var maxSize = 220;
	if(typeof(imgwidth) == "undefined")
		imgwidth = maxSize;
	if(typeof(imgheight) == "undefined")
		imgheight = maxSize;
	// on redimensionne l'image
	var newWidth = (imgwidth > imgheight) ? maxSize : parseInt(imgwidth * maxSize / imgheight);
	var newHeight = (imgwidth > imgheight) ? parseInt(imgheight * maxSize / imgwidth) : maxSize;
	var crossobj = document.getElementById("showimage");
	var arrayPageScroll = getPageScroll();
	var arrayMousePos = mouseposition(e);
	crossobj.style.top =arrayMousePos[1]-maxSize+"px";
	/*arrayPageScroll[1]+ +arrayPageScroll[0]*/
	crossobj.style.left = arrayMousePos[0]+"px";
	//crossobj.innerHTML='<img src="'+which+'" style="height:'+maxSize+'px;" title="zoom"/>';
	style = '"'+((imgwidth<imgheight)?'height:':'width:')+maxSize+'px"';
	crossobj.innerHTML='<img src="'+which+'" style='+style+' alt="zoom" title="zoom"/>';
	/*crossobj.style.width = maxSize+"px";
	crossobj.style.height = maxSize+"px";*/
	crossobj.style.border="none";		
	crossobj.style.display = 'block';
	return false;
}

function module_zoom(which, e, position, imgwidth, imgheight)
{
	var crossobj = document.getElementById("showimage");
	crossobj.style.top="100px";
	crossobj.style.left="50%";
	crossobj.style.marginLeft="-250px";
	crossobj.style.width="583px";
	crossobj.style.border="1px solid #000";		
	crossobj.innerHTML='<div align="right" id="dragbar" class="txt-bold" style"background:red;"><span id="closetext" onclick="closepreview()">&raquo; Fermer&nbsp;</span>&nbsp;&nbsp;</div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="583" height="583" title="module zoom"><param name="movie" value="swf/zoom.swf?lampe='+which+'" /><param name="quality" value="high" /><embed src="swf/zoom.swf?lampe='+which+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="583" height="583"></embed></object>';
	crossobj.style.display="block";
	crossobj.style.visibility="visible";
	return false;
}

function vision_360(file, e)
{
	var x, y;
	if (ie||ns6)
	{
		var crossobj = document.getElementById ? document.getElementById("showimage") : document.all.showimage;
		// ICI POUR REGLER LA POSITION DE LA LOUPE PAR RAPPORT A LA PAGE
		x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
		y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
		if (navigator.appName.substring(0,3) == "Net")
		{
			monX = (x+10);
			monY = (y+10);
		}
		else
		{
			monX = (x-60);
			monY = (y+90);
		}
		crossobj.style.left="50%";
		crossobj.style.marginLeft="-120px";
		crossobj.style.top="240px";
		crossobj.innerHTML='<div align="right" id="dragbar" class="txt-bold"><span id="closetext" onclick="closepreview()">&raquo; Fermer&nbsp;</span>&nbsp;&nbsp;</div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="336" height="280" title="vision 360"><param name="movie" value="components/com_virtuemart/shop_image/product/'+file+'" /><param name="quality" value="high" /><embed src="components/com_virtuemart/shop_image/product/'+file+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="336" height="280"></embed></object>';
		crossobj.style.display="block";
		crossobj.style.visibility="visible";
		crossobj.style.border="1px solid #000";		
	
		return false;
	}
	else //if NOT IE 4+ or NS 6+, affiche image ds le navigateur en pleine page
		return true;
}

function closepreview()
{
	var crossobj = document.getElementById("showimage");
	crossobj.style.display = 'none';
}
function preload(){
	imgload=new Array();
	for(var j=0; j<preload.arguments.length; j++)
	{
		/*alert(preload.arguments[j]);*/
		imgload[j]=new Image();
		imgload[j].src=preload.arguments[j];
	}
}