var ktuScrollDiff = 0;

function hide_cb30popmedia()
{	

	// -> Url qui s'ouvre lorsque la popdhtml est fermée
	// paramètre caché
	if (typeof Params_popmedia['onclose'] != 'undefined') {
		var win2 = window.open(''+Params_popmedia['onclose']+'', '', 'width='+screen.width+', height='+screen.height+', toolbar=1, location=1, directories=1, status=1, scrollbars=1, resizable=1, copyhistory=1, menuBar=1');
		win2.blur();
		window.focus();
	}
	
	document.getElementById("cb30popmedia").style.width 			= "1px";
	document.getElementById("cb30popmedia").style.height 			= "1px";
	document.getElementById("cb30popmedia").style.visibility 		= 'hidden';
	document.getElementById("cb30popmedia").style.top				= '-50px'; 
	document.getElementById("cb30popmedia").style.left				= '-30px';
	
	document.getElementById("cb30popmedia_iframe").src				='about:blank';
	document.getElementById("cb30popmedia_iframe").style.width 		= "1px";
	document.getElementById("cb30popmedia_iframe").style.height 	= "1px";
	document.getElementById("cb30popmedia_iframe").style.visibility = 'hidden';
	
	document.getElementById("cb30popmedia_innerdiv").style.width 	= "1px";	
	document.getElementById("cb30popmedia_innerdiv").style.height 	= "1px";
	document.getElementById("cb30popmedia_innerdiv").style.top		= '-50px'; 
	document.getElementById("cb30popmedia_innerdiv").style.left		= '-30px';	
	
}		

function dimension_detect()
{
	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;
}

function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) 
	{
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);   
			
		i = document.cookie.indexOf(" ", i) + 1;    
		
		if (i == 0) break;   
	}
  
	return 0;
}

function SetCookie (name, value) 
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  

	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

document.write('<div id="cb30popmedia"  style="visibility:hidden; z-index:auto">');
document.write('	<div id="cb30popmedia_innerdiv" style="overflow: hidden; z-index:auto; position: absolute; border:0; top: 0; left: 0;">');
document.write('		<table cellpadding="0" cellspacing="0" style="border: 0; margin: 0; padding: 0; font-size: 0; height: 24px;">');
document.write('			<tr>');
document.write('				<td height="24"><img src="http://www.securitetotale.com/cb30popmedia/all/fr/titre_01.gif" height="24" width="177"></td>');
document.write('				<td height="24" id="cb30popmedia_title" style="background: url(http://www.securitetotale.com/cb30popmedia/all/fr/titre_bg.gif) repeat-x;"></td>');
document.write('				<td height="24"><img src="http://www.securitetotale.com/cb30popmedia/all/fr/titre_02.gif" width="119" height="24" onClick="hide_cb30popmedia()"></td>');
document.write('			</tr>');
document.write('		</table>');
document.write('		<div id="ktucontent" style="margin: 0; padding: 0; font-size: 0;"><iframe id="cb30popmedia_iframe" frameborder="0" scrolling="no" style="width:665px;height:400px" allowtransparency="true" src="about:blank"></iframe></div>');
document.write('	</div>');
document.write('</div>');

function show_cb30popmedia()
{
	if(Params_popmedia['session'] == 1) 
	{
		// Une fois par session :
		if(GetCookie("seen") != 1)
		{
			// Cookie :
			SetCookie ("seen", 1, null, "/", null, false);
			
			// Display :
			document.getElementById("cb30popmedia").style.visibility 			= 'visible';	
			document.getElementById("cb30popmedia").style.top					= '50px'; 	
			document.getElementById("cb30popmedia").style.left					= '30px';	
	
			document.getElementById("cb30popmedia_innerdiv").style.margin		= 'auto';
			document.getElementById("cb30popmedia_innerdiv").style.width 		= Params_popmedia['width'] + "px";	
			document.getElementById("cb30popmedia_innerdiv").style.height 		= Params_popmedia['height']+24 + "px";	
	
			document.getElementById("cb30popmedia_iframe").src 					= Params_popmedia['src'];	
			document.getElementById("cb30popmedia_iframe").style.width 			= Params_popmedia['width']+"px";	
			document.getElementById("cb30popmedia_iframe").style.height 		= Params_popmedia['height']+"px";	
			document.getElementById("cb30popmedia_iframe").style.visibility 	= 'visible';

			document.getElementById("cb30popmedia_title").style.width 			= (Params_popmedia['width']-296)+"px";
			document.getElementById("cb30popmedia_title").style.height 			= "24px";
			
			carpediem_add_load_event(mvSticker());
			window.onresize=function(){	carpediem_add_load_event(mvSticker()); };
		}
	} else {
		// A chaque affichage :
		document.getElementById("cb30popmedia").style.visibility 			= 'visible';	
		document.getElementById("cb30popmedia").style.top					= '50px'; 	
		document.getElementById("cb30popmedia").style.left					= '30px';	
	
		document.getElementById("cb30popmedia_innerdiv").style.margin		= 'auto';
		document.getElementById("cb30popmedia_innerdiv").style.width 		= Params_popmedia['width'] + "px";	
		document.getElementById("cb30popmedia_innerdiv").style.height 		= Params_popmedia['height'] + "px";	
	
		document.getElementById("cb30popmedia_iframe").src 					= Params_popmedia['src'];	
		document.getElementById("cb30popmedia_iframe").style.width 			= Params_popmedia['width']+"px";	
		document.getElementById("cb30popmedia_iframe").style.height 		= Params_popmedia['height']+"px";	
		document.getElementById("cb30popmedia_iframe").style.visibility 	= 'visible';

		document.getElementById("cb30popmedia_title").style.width 			= (Params_popmedia['width']-296)+"px";
		
		carpediem_add_load_event(mvSticker());
		window.onresize=function(){	carpediem_add_load_event(mvSticker()); };
	}
}


function mvSticker() 
{
	var d 		= dimension_detect();
	var newTop 	= (d.viewH-Params_popmedia['height'])/2 ;
	var newLeft = (d.viewW-Params_popmedia['width'])/2;
	
	if (self.innerWidth)
	{
		var mytop = window.pageYOffset+newTop;
	} else {
		var ie=(document.compatMode&&document.compatMode!='BackCompat')?document.documentElement:document.body;
		var mytop = ie.scrollTop+newTop;
	}
	document.getElementById("cb30popmedia_innerdiv").style.top  = mytop +'px';
	document.getElementById("cb30popmedia_innerdiv").style.left = newLeft +'px';
	setTimeout("mvSticker()", 10);
}

var carpediem_add_load_event=function(func){
	var oldonload = window.onload;
	if (typeof(window.onload)!='function') window.onload=func;
	else { window.onload=function(){ oldonload(); func(); }; }
};