// IMPORTANT: 
// Questo Script ha preso ispirazione dalla libreria di Urs Dudli and Peter Gehrig (info@24fun.com): http://www.24fun.com/fast/index.html on the webpage 
// E' stato riadattato per www.AdvertPower.com da Tommaso Trani


var popwindow
var tisurl
var tiswidth
var tisheight
var thismargin=10
var tistopposition=thismargin
var tisleftposition=thismargin
var pause=20
var step=20
var attesaCorner=500
var screenwidth
var screenheight
var endposition_x
var endposition_y
var timer
var memberCode

function openAdvertPowerPopup(memb,thiswidth,thisheight) {
	
	memberCode=memb
	tiswidth=thiswidth
	tisheight=thisheight

	var rand=new String(Math.random());

	popwindow=window.open('', 'AdvertPower'+rand.substring(7,13),"scrollbars=yes,resizable=yes, width="+tiswidth+",height="+tisheight+",top="+tistopposition+",left="+(tisleftposition)+"");

	popwindow.document.write('<html><script>var newcolor=new Array("FF0000","EE0011","DD0022","CC0033","BB0044","AA0055","990066","880077","770088","660099","5500AA","4400BB","3300CC","2200DD","1100EE","0000FF","0000FF","0000FF","0011EE","0022DD","0033CC","0044BB","0055AA","006699","007788","008877","009966","00AA55","00BB44","00CC33","00DD22","00EE11","00FF00","00FF00","00FF00","00FF00","11EE00","22DD00","33CC00","44BB00","55AA00","669900","778800","887700","996600","AA5500","BB4400","CC3300","DD2200","EE1100","FF0000","FF0000","FF0000");');
	popwindow.document.write('var pause2=30;var timer2;var animation_on=true;var thislink;var i_color=0;');
	popwindow.document.write('function startanimation(newlink) { if (document.all) { animation_on=true; thislink=eval("document.all."+newlink+".style");changecolors();}}');
	popwindow.document.write('function changecolors() { if (animation_on) { if (i_color>=newcolor.length-1) {i_color=0} thislink.color=newcolor[i_color];i_color++;timer2=setTimeout("changecolors()",pause2);}else {clearTimeout(timer2);}} </script>  ');
	popwindow.document.write('<body bgcolor="#0000FF" text="#FFFFFF" link="#FFFFFF" alink="#FFFFFF" vlink="#FFFFFF" leftmargin=0 topmargin=0><table width=180 height=180 border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=middle height=170><h3><a name="AdvertPowerLink" href="http://www.advertpower.com" target="_blank" title="Clicca per scoprire i metodi di promozione pił innovativi!">Advert Power</a></h3>The real power of Advertising<br><br><br><font size=-1>Loading...</font></td></tr></table><SCRIPT>startanimation("AdvertPowerLink");</SCRIPT></body></html>');
	
	
	popwindow.focus()			

	screenwidth=window.screen.width
	screenheight=window.screen.height
	endposition_x=screenwidth-thiswidth-thismargin
	endposition_y=screenheight-thisheight-thismargin
	moveright()
}

function moveright() {
	if (tisleftposition<=endposition_x) {
		popwindow.moveTo(tisleftposition,tistopposition)
		tisleftposition+=step
		timer= setTimeout("moveright()",pause)
	}
	else {
		clearTimeout(timer)
		tisleftposition=endposition_x
		popwindow.moveTo(tisleftposition,tistopposition)
		timer= setTimeout("movecenter()",attesaCorner)		
	}
}


function movecenter() {
	if (tisleftposition>=endposition_x/2) {
		popwindow.moveTo(tisleftposition,tistopposition)
		tisleftposition-=step
		tistopposition+=step*(screenheight/screenwidth)
		timer= setTimeout("movecenter()",pause)
	}
	else {
		clearTimeout(timer)
		tisleftposition=thismargin
		//popwindow.moveTo(tisleftposition,tistopposition)
		popwindow.focus()			
		
		//setTimeout("loadMemberMPage()",attesaCorner)
		loadMemberPage();

	}
}

function loadMemberPage()
{
		clearTimeout(timer)
		numPage = parseInt(Math.random()*1000)

		popwindow.document.location='http://www.softwareplanet.net:6379/?exchangeCode=ScambioPopupDinamica&numeroPagina='+numPage+'&ID='+memberCode;
}
/////////////////////////////////////////////////////////////

var newcolor=new Array("FF0000","EE0011","DD0022","CC0033","BB0044","AA0055","990066","880077","770088","660099","5500AA","4400BB","3300CC","2200DD","1100EE","0000FF","0000FF","0000FF","0011EE","0022DD","0033CC","0044BB","0055AA","006699","007788","008877","009966","00AA55","00BB44","00CC33","00DD22","00EE11","00FF00","00FF00","00FF00","00FF00","11EE00","22DD00","33CC00","44BB00","55AA00","669900","778800","887700","996600","AA5500","BB4400","CC3300","DD2200","EE1100","FF0000","FF0000","FF0000")

// speed of animation. Smaller means faster
var pause2=30

// Do not edit the values below
var timer2
var animation_on=true
var thislink
var i_color=0

function startanimation(newlink) {
    if (document.all) {
        animation_on=true
        thislink=eval("document.all."+newlink+".style")
        changecolors()
    }
}

function changecolors() {
    if (animation_on) { 
        if (i_color>=newcolor.length-1) {i_color=0}
        thislink.color=newcolor[i_color]
        i_color++
        timer2=setTimeout("changecolors()",pause2)
    }
    else {
        clearTimeout(timer2)
    }
} 

/////////////////////////////////////////////////////////////
