/* $Id: nx_bubble.js,v 1.8 2009/06/03 07:06:32 neeta Exp $ */

/* Detect if the browser is IE or not. If it is not IE, we assume that the browser is NS. */
var IEbbl = document.all?true:false;

var IEbblBody = ietruebody();

function displayBubble(bblId,e,contEmail)
{
	var musX = getMouseX(e);
	var musY = getMouseY(e);
    var contEmail;

	/* Absolute bottom position (including scroll value) of browser-window (viewport) */
	var wndwHeight = getWinHeight();

	document.getElementById(bblId).style.display = 'inline';

	var bblWidth = document.getElementById(bblId).offsetWidth;
	var bblHeight = document.getElementById(bblId).offsetHeight + 30;

	/* vertical distance between musY and bottom edge of browser-window (viewport) */
	var bottomDist = wndwHeight - musY;

	if(bottomDist < bblHeight)
	{
		var bblY = musY - bblHeight;
	}
	else
	{
		var bblY = musY + 30;
	}

    if(contEmail == 1 && location.hash != '#DealerInfo')
    {
        document.getElementById(bblId).style.top = (musY - bblHeight) + "px";
        document.getElementById(bblId).style.left = (musX - 390) + "px";
    }
    else if(location.hash == '#DealerInfo')
    {
        document.getElementById(bblId).style.top = (bblY + 275) + "px";
        //document.getElementById(bblId).style.left = (bblX - 425) + "px";
    }
    else if(contEmail == 3 )
    {
        document.getElementById(bblId).style.top = (musY - bblHeight + 300 ) + "px";
        document.getElementById(bblId).style.left = (musX - 390) + "px";
    }
    //Contact request bubble positioning in purchase ads in NETTIVERAROSA
    else if(contEmail == 2 )
    {
        document.getElementById(bblId).style.top = (musY - bblHeight + 100 ) + "px";
        document.getElementById(bblId).style.left = (musX - 390) + "px";
    }
    else if(contEmail == 4)
	{
		document.getElementById("lm").checked = true;
		document.getElementById(bblId).style.top = (musY + 5) + "px";
		document.getElementById(bblId).style.left = (musX - 724) + "px";

		if(bblId == 'bubble_map_search' && document.getElementById("body_banner"))
			document.getElementById("body_banner").style.visibility = "hidden";

		if(bblId == 'bubble_map_search' && document.getElementById("videocontainer"))
			document.getElementById("videocontainer").style.visibility = "hidden";
	}
    else if(contEmail == 5 ) // iFrame for venelehti , bubble position adjustment
        document.getElementById(bblId).style.top = (musY - bblHeight + 100 ) + "px";
	else
	{
		document.getElementById(bblId).style.top = bblY + "px";
		document.getElementById(bblId).style.left = (musX - 100) + "px";
	}
}

function hideBubble(bblId)
{
	document.getElementById(bblId).style.display = 'none';

	if(bblId == 'bubble_map_search' && document.getElementById("body_banner"))
		document.getElementById("body_banner").style.visibility = "visible";

	if(bblId == 'bubble_map_search' && document.getElementById("videocontainer"))
		document.getElementById("videocontainer").style.visibility = "visible";
}

function getMouseX(e)
{
	var tempX = 0;

	if (IEbbl)
	{
		/* Get the x pos.s if browser is IE */
		tempX = event.clientX + IEbblBody.scrollLeft;
	}
	else
	{
		/* Get the x pos.s if browser is NS */
		tempX = e.pageX;
	}

	/* catch possible negative values in NS4 */
	if (tempX < 0)
	{
		tempX = 0;
	}

	return tempX;
}

function getMouseY(e)
{
	var tempY = 0;

	if (IEbbl)
	{
		/* Get the y pos.s if browser is IE */
		tempY = event.clientY + IEbblBody.scrollTop;
	}
	else
	{
		/* Get the y pos.s if browser is NS */
		tempY = e.pageY;
	}

	/* catch possible negative values in NS4 */
	if (tempY < 0)
	{
		tempY = 0;
	}

	return tempY;
}

/* Gives absolute bottom position (Including scroll value) of bottom edge of browser visible window (viewport) */
function getWinHeight()
{
	/* Default value for old browser if(parseInt(navigator.appVersion)<3) */
	/*	var winW = 630, winH = 460;	*/

	/* We can also use if(navigator.appName.indexOf("Microsoft")!=-1) for the following */
	if(IEbbl && !window.opera)	/* For IE */
	{
// 		var winW = IEbblBody.offsetWidth + IEbblBody.scrollLeft;
// 		var winH = (IEbblBody.offsetHeight - 1222) + IEbblBody.scrollTop;
// 		var winW = IEbblBody.clientWidth + IEbblBody.scrollLeft;
		var winH = IEbblBody.clientHeight + IEbblBody.scrollTop;
	}
	else	/* For Netscape if(navigator.appName=="Netscape") */
	{
// 		var winW = window.innerWidth + window.pageXOffset;
		var winH = window.innerHeight + window.pageYOffset;
	}

	return winH;
}

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}