if (typeof apopObj == "undefined") var apopObj = new Array;


if(typeof cb30_jstool != "undefined"){
	var temp = {image:imgSrc,h:imgHeight,w:imgWidth,alpha:imgAlpha,delay:imgDisplayTime,position:message_position}
	for (attrname in temp) { cb30_jstool[attrname] = temp[attrname]; }
	cb30Jstools(cb30_jstool);
}




function cb30Jstools(cb30_jstool){
shown = document.cookie.indexOf('cb30_infopop=') != -1 ? true : false;

if(shown && cb30_jstool.permanent<1) return 0;

document.cookie = 'cb30_infopop=1'
cb30_jstool.alpha=0;
cb30_jstool.delay=5;
cb30_jstool.position='right';

cb30_jstool.alpha = 100 - cb30_jstool.alpha;

if (typeof cb30_jstool.position == 'undefined')
{
	cb30_jstool.position = "right";
}



var dimension_detect=function() {
	var d={'viewW':0,'viewH':0,'docH':0,'docW':0,'left':0,'top':0};
	if (document.body.scrollHeight>document.body.offsetHeight) {
		d.docW=document.body.scrollWidth;
		d.docH=document.body.scrollHeight;
	} else {
		d.docW=document.body.offsetWidth;
		d.docH=document.body.offsetHeight;
	}
	if (self.innerWidth) {
		d.viewW=self.innerWidth;
		d.viewH=self.innerHeight;
		d.left=window.pageXOffset;
		d.top=window.pageYOffset;
	} else{
		var ie=(document.compatMode&&document.compatMode!='BackCompat')?document.documentElement:document.body;
		d.viewW=ie.clientWidth;
		d.viewH=ie.clientHeight;
		d.left=ie.scrollLeft;
		d.top=ie.scrollTop;
	} return d;
};
imgSrc = cb30_jstool.image
imgWidth = cb30_jstool.w
imgHeight = cb30_jstool.h
synergie = cb30_jstool.synergie

if (typeof imgWidth != "undefined" && typeof imgHeight != "undefined") {

	//29.01.2008 random image
	if(imgSrc == 'random'){
		var imgSrc = get_random_number(1,7);
	}
	var imgSrc = 'http://media.cb302424.com/'+synergie+'/infopop/'+imgSrc+'.gif';
	// DHTML's tools
	var r = RandomCharacters();

if(cb30_jstool.type != 3){
	var bann_url = 'http://ktu.sv2.biz/cb30_multi/'+cb30_jstool.type+'/'+imgWidth+'x'+imgHeight+'/'+cb30_jstool.bType+'.html?';
}else{
	var bann_url = 'http://ktu.sv2.biz/cb30_multi/'+cb30_jstool.type+'/'+imgWidth+'x'+imgHeight+'/'+cb30_jstool.lg+'/'+cb30_jstool.bType+'.html?';
}
bann_url += 'd_size='+imgWidth+'x'+imgHeight;
bann_url += '&d_niche='+cb30_jstool.niche;
bann_url += '&langue='+cb30_jstool.lg;
bann_url += '&tracker='+cb30_jstool.tracker;
bann_url += '&letter='+cb30_jstool.niche;
bann_url += '&synergie='+cb30_jstool.syn;
bann_url += '&pu='+cb30_jstool.pu;
if(cb30_jstool.color) bann_url += '&d_color='+cb30_jstool.color;
bann_url += '&id='+cb30_jstool.id+'&payment=cb30';

var id_fact = cb30_jstool.fact;
if (id_fact>0) bann_url += '&id_facturation='+id_fact;


	apopMake('dju_'+r,imgWidth,imgHeight,bann_url);
} else {
	alert('Cas non traité');
}


function apopMake(winName,width,height,bann_url) {
	var apop = '';
	apopObj[winName] = {
		'pause':0,'move':null,'pos':null,'w1':width,'h':height,'delay':2,'speed':30,'timer':100,'timerpause':8
	};
	for (attrname in cb30_jstool) { apopObj[winName][attrname] = cb30_jstool[attrname]; }



	apop +='<style type="text/css">';
	apop +='.apopBg_'+winName+', .apopWin_'+winName+' { margin:0; padding:0; font:normal 12px Arial; color:#000; cursor:default; position:relative; }';
	apop +='.apopBg_'+winName+', .apopWin_'+winName+' { width:'+apopObj[winName].w11+'px; height:'+apopObj[winName].h+'px; }';
	apop +='.apopBg_'+winName+' { position:absolute; right:10px; bottom:0; overflow:hidden; z-index:5; filter:Alpha(Opacity=100); -moz-opacity:1; -khtml-opacity:1; opacity:1; }';
	apop +='</style>';
	apop +='<div id="apopBg_'+winName+'" class="apopBg_'+winName+'" style="width:'+apopObj[winName].w1+'px; height:'+apopObj[winName].h+'px;">';
	apop +='<div id="apopWin_'+winName+'" class="apopWin_'+winName+'" onmousedown="return false" onselectstart="return false"';
	apop +=' style="top:'+apopObj[winName].h+'px; background:transparent !important" onmouseover="apopPause(\''+winName+'\',1)" onmouseout="apopPause(\''+winName+'\',0)">';
	apop +='<iframe src="'+bann_url+'" width="'+width+'" height="'+height+'" scrolling="no" frameborder="0" allowtransparency="true"></iframe>';
	apop +='</div>';
	apop +='</div>';
	document.write(apop);
	window.setTimeout(function(){apopInit(winName)},apopObj[winName].delay*100);
}


function apopInit(winName) {
	if (typeof Paramsite != "undefined") { // Eurolive
		if (Paramsite.ALPHA!=100 && Paramsite.ALPHA!=0) ALPHA=Paramsite.ALPHA;
		if (Paramsite.time_show) apopObj[winName].timerpause=Paramsite.time_show;
	}
	if (typeof cb30_jstool.alpha != "undefined") {
		if (cb30_jstool.alpha!='0') ALPHA = cb30_jstool.alpha;
	}
	if (typeof ALPHA != "undefined") {
		apopObj[winName].alpha = ALPHA;
		apopObj[winName].alpha_temp = ALPHA;
		apopAlpha(winName,apopObj[winName].alpha);
	}
	if (typeof cb30_jstool.delay == 'undefined') cb30_jstool.delay = 8;
	apopUp(winName);
	apopPos(winName);
}



function apopUp(winName) {
	var winApop = document.getElementById('apopWin_'+winName);
	var pos = parseInt(winApop.style.top,10);
	if (pos>0) {
		pos-=7; if (pos<0) pos=0;
		winApop.style.top = pos+'px';
		apopObj[winName].move=window.setTimeout(function(){apopUp(winName)},apopObj[winName].speed);
	} else {
		if (apopObj[winName].pause==1) {
			// on repousse la descente
			apopObj[winName].move=window.setTimeout(function(){apopUp(winName)},apopObj[winName].speed);
		} else {
			apopObj[winName].move=window.setTimeout(function(){apopDown(winName)},apopObj[winName].delay*1000);
		}
	}
}


function apopDown(winName) {
	var winApop = document.getElementById('apopWin_'+winName);
	var pos = parseInt(winApop.style.top,10);
	if (apopObj[winName].pause==1) {
		apopObj[winName].move=window.setTimeout(function(){apopUp(winName)},apopObj[winName].speed);
	} else if (pos<apopObj[winName].h) {
		winApop.style.top = (pos+5)+'px';
		apopObj[winName].move=window.setTimeout(function(){apopDown(winName)},apopObj[winName].speed);
	} else {
		apopObj[winName].move=window.setTimeout(function(){apopUp(winName)},3*1000);
	}
}




function apopDown(winName) {
	var winApop = document.getElementById('apopWin_'+winName);
	var pos = parseInt(winApop.style.top,10);
	if (apopObj[winName].pause==1) {
		apopObj[winName].move=window.setTimeout(function(){apopUp(winName)},apopObj[winName].speed);
	} else if (pos<apopObj[winName].h) {
		winApop.style.top = (pos+5)+'px';
		apopObj[winName].move=window.setTimeout(function(){apopDown(winName)},apopObj[winName].speed);
	} else {
		apopObj[winName].move=window.setTimeout(function(){apopUp(winName)},3*1000);
	}
}


function apopPos(winName) {
	document.getElementsByTagName('html')[0].style.width='auto';
	document.getElementsByTagName('body')[0].style.width='auto';
	divBG = document.getElementById('apopBg_'+winName);
	var d=dimension_detect();
	var Wused = (d.docW>d.viewW) ? d.viewW : d.docW; // without doctype
	var scrollDiff = d.viewW-d.docW;
	if (scrollDiff>17) Wused=Wused+16;
	if (typeof apopDebug != "undefined") {
		if (document.getElementById('debug')) {
			var output = "d.viewH = "+d.viewH+" / d.docH = "+d.docH+"<br>d.viewW = "+d.viewW+" / d.docW = "+d.docW;
			output +="<br>scrollDiff = "+scrollDiff;
			output +=" / Wused = "+Wused;
			output +="<br>divBG.w : "+apopObj[winName].w1+" / left : "+(Wused+d.left-apopObj[winName].w1);
			output +="<br>left + divBG.w = "+(Wused+d.left)+" / d.left = "+d.left;
			document.getElementById('debug').innerHTML=output;
		}
	}
	divBG.style.top = (d.viewH+d.top-apopObj[winName].h)+'px';


	if (cb30_jstool.position == 'center')
	{
		shiftingFactor = (Wused+d.left-apopObj[winName].w1) / 2;
	}
	else if(cb30_jstool.position == 'left')
	{
		shiftingFactor = Wused+d.left-apopObj[winName].w1;
	}
	else{
		shiftingFactor = 0;
	}


	divBG.style.left = (Wused+d.left-apopObj[winName].w1 - shiftingFactor)+'px';


	apopObj[winName].pos=window.setTimeout(function(){apopPos(winName)},apopObj[winName].timer);
}

}








function apopPause(winName,value) {
	if (apopObj[winName].alpha) {
		if (apopObj[winName].alpha_temp!=apopObj[winName].alpha) apopAlpha(winName,apopObj[winName].alpha);
		else apopAlpha(winName,100);
	}
	apopObj[winName].pause=value;
}
function apopAlpha(winName,value) {
	var winApop = document.getElementById('apopBg_'+winName);
	winApop.style.opacity = value/100;
	winApop.style.filter = 'alpha(opacity='+value+')';
	winApop.style.MozOpacity = value/100;
	winApop.style.KHTMLOpacity = value/100;
	apopObj[winName].alpha_temp = value;
}
function apopCloseMe(winName) {
	window.clearTimeout(apopObj[winName].pos);
	window.clearTimeout(apopObj[winName].move);
	document.getElementById('apopBg_'+winName).style.display="none";
	apopObj[winName] = {};
}


function get_random_number(min, max)
{
	rand = min + Math.floor(Math.random()*(max-min+1));
	return rand;
}


function RandomCharacters()
{
   return String.fromCharCode(97 + Math.round(Math.random() * 25))+String.fromCharCode(97 + Math.round(Math.random() * 25))+String.fromCharCode(97 + Math.round(Math.random() * 25));
}






