// is it Internet Explorer
var IE = document.all?true:false
// how long was the user scroll
var scroll = 0;
// Timer beforeclosing the iframe
var timerMotor;
var timerBeforeShowingIframe;
var timerBeforeOver;

// Find the position of an object on the page
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
    {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
        {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function afterOver(id, product, supplier, emplacement, variable)
{
    // If we are over something we don't want to hide the iframe
    stoptimer();

    // Get the widht and the height of the screen
    if (IE)
        // marche sur IE
        height = document.documentElement.clientHeight-40;
    else
        height = window.innerHeight;


    // The widow height - iframe height - icone height
    windowsSize= height - 245 -90;

    if(getElem('id', "popupfull",null))
    {
        iframe = getElem('id', "popupfull",null);
        // x positon of the iframe from the right (broder + 5*icone width + 4*space between icone - widht of the iframe)
        positionX = 14 + 5*90 + 4*5 - 327-2;

        // Display the iframe
        iframe.style.display ='';
        // Position the iframe
        iframe.style.right = positionX + "px";
        // Is it IE
        if(IE)
        {
            // Find the position of the icone the user was on
            imagePosition = parseInt(findPos(id));
             // Check where to place the iframe (above or under the icone)
            if(imagePosition - parseInt(document.documentElement.scrollTop) > windowsSize)
            {
                // Above icone
                iframePosition = imagePosition - 280;
                iframe.style.top = iframePosition + "px";
            }
            else
            {
                // Under icone
                iframePosition = imagePosition + 75;
                iframe.style.top = iframePosition + "px";
            }
        }
        else
        {
            // Get the value of the scroll
            scroll = document.documentElement.scrollTop;
            // Find the position of the icone the user was on
            imagePosition = parseInt(findPos(id));
             // Check where to place the iframe (above or under the icone)
            if(imagePosition - scroll> windowsSize)
            {
                // Above icone
                iframePosition = imagePosition - 300;
                iframe.style.top = iframePosition + "px";
            }
            else
            {
                // Under icone
                iframePosition = imagePosition + 20;
                iframe.style.top = iframePosition + "px";
            }
        }
        if(product == 10002)
            iframe.src = "../products/products.prod2.preview.iframecontent.php?supplier="+supplier+"&product="+product;		
        else{
		 // Change the source of the iframe
            iframe.src = "../motor/motor.product.php?supplier="+supplier+"&product="+product+"&variable="+variable;
		}
    }
	if (emplacement=='home'){
		divSquare = getElem('id', "pubSquare",null);
		document.getElementById("pubSquare").style.visibility="hidden";
		iframe.style.right = "30px";
		iframe.style.top="250px";		
		if (variable == 'exemple1'){
			iframe.src = "../motor/motor.exemple1.htm";
		}
		if (variable == 'exemple2'){
			iframe.src = "../motor/motor.exemple2.htm";
		}
		if (variable == 'exemple3'){
			iframe.src = "../motor/motor.exemple3.htm";
		}
		if (variable == 'exemple4'){
			iframe.src = "../motor/motor.exemple4.htm";
		}
		if (variable == 'exemple5'){
			iframe.src = "../motor/motor.exemple5.htm";
		}
		if (variable == 'exemple6'){
			iframe.src = "../motor/motor.exemple6.htm";
		}
	}
	if (emplacement=='eshop'){

		iframe.style.right = "200px";
		iframe.style.top="270px";		
	}
	if (emplacement=='presentation'){
		divSquare = getElem('id', "pubSquare",null);
		iframe.style.right = "250px";
		iframe.style.top="500px";		
		if (variable == 'exemple1'){
			iframe.src = "../motor/motor.exemple1.htm";
		}
		if (variable == 'exemple4'){
			iframe.src = "../motor/motor.exemple4.htm";
		}
	}
	if (emplacement=='exemple1'){
		iframe.src = "../motor/motor.exemple1.htm";
		iframe.style.right = "280px";
		iframe.style.top="420px";
	}
	if (emplacement=='exempleVideoPreview'){
		iframe.src = "../motor/motor.exemple1.htm";
		iframe.style.right = "400px";
		iframe.style.top="850px";
	}
	
	
}

var idOver;
var productOver;
var supplierOver;
function over(id, product, supplier, waitingTime, emplacement,variable)
{
   window.clearTimeout(timerMotor);
   idOver = id;
   productOver = product;
   supplierOver = supplier;
   // Time to wait until showing the iframe
    timeBeforeOver = waitingTime;
	emplacementOver = emplacement;
	variableOver = variable;
    // Start the timer	
    timerBeforeOver = window.setTimeout("afterOver(idOver,productOver,supplierOver,emplacementOver,variableOver);",timeBeforeOver);

}

function stoptimer()
{
    window.clearTimeout(timerMotor);
}

function hideiframe(name)
{
    if(getElem('id', name, null))
    {
        // Get the iframe
        iframe = getElem('id', name, null);
        // Hide the iframe
        iframe.style.display ='none';
        iframe.src="";
    }
}

function out(waitingTime)
{
    window.clearTimeout(timerBeforeShowingIframe);
    window.clearTimeout(timerBeforeOver);
    // Name of the iframe to hide
    name="popupfull";
    // Time to wait until hiding the iframe
    time = waitingTime;
    // Start the timer
    timerMotor = window.setTimeout("hideiframe(name);",time)
}
