// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

function isInt(numIn)
{
	var checknum = parseInt(numIn);
	return !isNaN(checknum);
}

// Make an object visible
function showObject(obj) 
{
        if (NS4) obj.visibility = "show";
        else if (IE4plus||NS6) obj.visibility = "visible";
}

// Hides an object
function hideObject(obj) 
{
        if (NS4) obj.visibility = "hide";
        else if (IE4plus||NS6) obj.visibility = "hidden";
}

// Move a layer
function moveTo(obj,xL,yL) 
{
        obj.left = xL;
        obj.top = yL;
}

// Browser window width
function getWindowWidth()
{
	if (NS4 || NS6)
		return window.innerWidth;
	else if (IE4plus)
		return document.body.clientWidth;
}

function getObjLoc(oIn)
{
	var oOut = new Object();
	oOut.top = 0;
	oOut.left = 0;

	if ((IE4plus && !isMac) || (IEmac && IE5) )
	{
		oOut.left = oIn.offsetLeft;
		oOut.top = oIn.offsetTop;
		var newp = oIn.offsetParent;
		while(newp != null)
		{
			oOut.left += newp.offsetLeft;
			oOut.top += newp.offsetTop;
			newp = newp.offsetParent;
		}
		if (IEmac)
		{	
			oOut.left += parseInt(document.body.leftMargin);
			oOut.top +=  parseInt(document.body.topMargin);
		}
	}
	else if (NS4)
	{
		oOut.left = oIn.x;
		oOut.top = oIn.y;
	}
	else if (isMac && IE4)
	{
		var el = oIn;
		do
		{	
			if (isInt(el.offsetTop))
				oOut.top += el.offsetTop;
			if (isInt(el.offsetLeft))
				oOut.left += el.offsetLeft;
			el = el.parentElement;
		} while (el.tagName != "BODY");
		if (navigator.appVersion.indexOf("4.5")>=0)
			oOut.top = oOut.top - 15;
	}
	else if (NS6)
	{
		var b=document.getElementsByTagName('body')[0];
		oOut.left = oIn.offsetLeft+b.offsetLeft;
		oOut.top = oIn.offsetTop+b.offsetTop;
	}
	return oOut;
} 


function createLayer(name,left,top,width,height,html)
{
	var nL;
	
	if (IE4plus)
	{
		var divhtml = '<div id=' + name + ' style="visibility:hidden;left:' + left + 
			'px;top:' + top + 'px;width:' + width + 
			'px;height:' + height + 'px;position:absolute">' + 
			html + '</div>';
		document.body.insertAdjacentHTML('beforeEnd', divhtml);
		nL = document.all[name].style
	}
	else if (NS4)
	{
		nL=new Layer(width);
		nL.name = name;
		nL.left=left;
		nL.top=top;
		nL.clip.width=width;
		nL.clip.height=height;
		nL.document.open();
		nL.document.write(html);
		nL.document.close();
	}
	else if (NS6)
	{
		var nL = document.createElement("DIV");
		nL.innerHTML = html;
		var mybody=document.body;
		mybody.appendChild(nL);
		nL.style.position = "absolute";
		nL.style.visibility = "hidden";
		nL.style.left = left;
		nL.style.top = top;
		nL.style.width = width;
		nL.style.height = height;
		nL.id = name;
		nL = nL.style;
	}
	return nL;
}

function PI_Reveal()
{
	this.index++;
	
	if (this.index <= this.steps)
	{
		var w = (parseInt(this.width)*this.index)/this.steps;
		var h = (parseInt(this.height)*this.index)/this.steps;
		this.SetClip(w,h);
		setTimeout("gPopInside.Reveal()",50);
	}
	else
	{
		this.dvc.visibility = "visible";
		if (this.autoClose > 0)
			setTimeout("gPopInside.Show(false)",this.autoClose);
	}
}

function PI_GetContentHTML()
	{
	var html = '<center><A HREF="newsusa.htm" target="rbottom" onClick="window.close()"><IMG SRC="prodotti/bpc230/new.jpg" BORDER=0 ALT="New BPC 230 Evolution"></A>';
	html += '<A HREF="newsusa.htm" target="rbottom" onClick="window.close()"><IMG src="img/shim.gif" width=2 height=2 border=0></a></center>';
	return html;
	}

function PI_GetWindowHTML()
{
	var html = '<map name="PIMap">';
	html += '<area href="javascript:gPopInside.Show(false)" alt="Close" shape="rect" coords="' + (this.width - 24) + ', 0, ' + this.width + ', 18"></map>';
	html += '<img src="' + this.imgURL + '" width="' + this.width + '" height="' + this.height + '" border="0" usemap="#PIMap" >';

	return html;
}

function PI_Init()
{
	if (IE4plus || NS4 || NS6)
	{
		this.dv = createLayer("popinside",0,0,this.width,this.height,this.GetWindowHTML());
		this.SetClip(0,0);

		this.dvc = createLayer("popinsidecontent",0,0,this.width-4,this.height-18,this.GetContentHTML());

		var loc = getObjLoc(document.images["popinsideloc"]);
		this.dv.left = loc.left + 310 ;
		this.dv.top = loc.top + 30;

		this.dvc.left = loc.left + 314;
		this.dvc.top = loc.top + 48;
		if (this.CheckFrequency())
		{
			setTimeout("gPopInside.StartReveal()",this.showDelay);
		}
	}
}

function PI_StartReveal()
{
	showObject(this.dv);
	this.Reveal();
}

function PI_SetClip(width,height)
{
	if ((IE4plus || NS6) && !(IEmac && IE4))
		this.dv.clip = "rect(" + 0 + "px " + width + "px " + height + "px 0px)";
	else if (NS4)
	{
		this.dv.clip.left = 0;
    	this.dv.clip.right = width;
    	this.dv.clip.top = 0;
    	this.dv.clip.bottom = height;
	}
}

function PI_Show(show)
{
	if (show)
	{
		showObject(this.dv);
		showObject(this.dvc);
	}
	else
	{
		hideObject(this.dv);
		hideObject(this.dvc);	
	}
}

function PI_CheckFrequency()
{
	var shouldShow = this.frequency != 0;
	if (this.frequency > 0)
	{
		var allCookies = document.cookie;
		var start = allCookies.indexOf("PICount=");
		if (start >= 0)
		{
			var end = allCookies.indexOf(";",start);
			if (end < 0)
				end = allCookies.length;
			var freqStr = allCookies.substring(start+8,end);
			if (isInt(freqStr))
				this.frequency = parseInt(freqStr);
		}

		if (this.frequency>0)
			this.frequency--;
		else
			shouldShow = false;
			
		var exp = new Date();
		exp.setTime(exp.getTime()+this.renew*60*60000);
		document.cookie = "PICount="+this.frequency+ "; expires=" + exp.toGMTString();
	}
	
	return shouldShow;
}


function PopInside(imageURL,width,height)
{
	this.steps = 20;
	this.index = 0;
	this.width = width;
	this.height = height;
	this.imgURL = imageURL;
	this.showDelay = 1000;
	this.autoClose = -1;
	this.frequency = 200; 
	this.renew = 1; 
	
	this.dv = null;
	this.dvc = null;
	
	this.SetClip = PI_SetClip;
	this.Init = PI_Init;
	this.Reveal = PI_Reveal;
	this.StartReveal = PI_StartReveal;
	this.GetWindowHTML = PI_GetWindowHTML;
	this.GetContentHTML = PI_GetContentHTML;
	this.Show = PI_Show;
	this.CheckFrequency = PI_CheckFrequency;
}

function PIStart()
{
	gPopInside.Init();
}

SafeAddOnload(PIStart);

var gPopInside = new PopInside("img/1.gif",225,265);
