var swfObjectFile = 'js/swfobject.js';
var imgFile = "images/float.gif";
var swfFile = "float.swf";
var pngfixFile = null;

/*var swfObjectFile = 'js/swfobject.js';
var imgFile = "img/float.png";
var swfFile = "float.swf";
var pngfixFile = "js/pngfix.htc";*/

if(typeof(floatPosition) == "undefined")
	var floatPosition = 'fixed';

if(typeof(floatWidth) == "undefined")
	var floatWidth = 372;

if(typeof(floatHeight) == "undefined")
	var floatHeight = 224;

if(typeof(floatID) == "undefined")
	var floatID = 0;

var floatFullHTMLcode = '';

function absolutizeFloat() {
	//floatID = parseInt(floatID);
	//floatID++;	
	
	var bodyElem = document.getElementsByTagName('body')[0];
	var divId = 'floatDiv'+floatID;		
	
	obj = document.getElementById(divId);	
	
	if(!obj) {
		return false;
	}
	
	obj.className = 'floatDiv';
	obj.style.zIndex = '99999';	
	obj.style.width=floatWidth+'px';
	obj.style.height=floatHeight+'px';

	if(floatPosition != 'fixed') {
		obj.style.position='absolute';
		var s = getViewportSize();
		var st = (window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop);
		
		//bottom
		if(floatPosition.indexOf('bottom')>-1) {
			t = s[1] - obj.offsetHeight + st;
		}
		
		//top
		else {
			t = st;
		}
		
		//left
		if(floatPosition.indexOf('left')>-1) {
			l = 0;
		}		
		
		//right
		else {
			l = bodyElem.offsetWidth-obj.offsetWidth;
		}
		
		obj.style.top = t+'px';
		obj.style.left = l+'px';
	}
}	

function createFloat() {			
	
	var bodyElem = document.getElementsByTagName('body')[0];
	var divId = 'floatDiv'+floatID;	
	if(!document.getElementById(divId)) {				
		var html = '';
		html += '<div class="floatDiv" id="'+divId+'">';
		html += '<div id="'+divId+'c">';
		html += '<img src="'+imgFile+'" usemap="#'+divId+'map" alt="" border="0" width="'+floatWidth+'" height="'+floatHeight+'" '+(pngfixFile != null ? ' style="behavior: url('+pngfixFile+');"' : '')+' />';
		html += '<map name="'+divId+'map">';
		html += '<area shape="rect" coords="204,  82,  283,  97" href="http://go.icamo.fi/1533/?"/>';
		html += '<area shape="rect" coords="205,  69,  294,  80" href="http://go.icamo.fi/1532/?"/>';
		html += '<area shape="rect" coords="204,  99,  349,  112" href="http://go.icamo.fi/1534/?"/>';
		html += '<area shape="rect" coords="203,  115,  345,  126" href="http://go.icamo.fi/1535/?"/>';
		html += '<area shape="rect" coords="202,  127,  276,  142" href="http://go.icamo.fi/1536/?"/>';
		html += '<area shape="rect" coords="200,  173,  249,  189" href="javascript:closeFloat()"/>';
		html += '<area shape="rect" coords="203,  152,  307,  168" href="http://go.icamo.fi/1537/?http://ad.fi.doubleclick.net/clk;209558836;31437821;o"/>';
		html += '</map>';
		html += '</div>';
		html += '</div>';

		if(floatPosition != 'fixed') {					
			bodyElem.innerHTML += html;
			floatEmbedSwf();
		}
	}			
	
	if(floatPosition != 'fixed') {				
		absolutizeFloat();
	}
	
	return html;
}

function floatEmbedSwf() {
	var divId = 'floatDiv'+floatID;
	var params = {};
	params.allowScriptAccess = "always";
	params.wmode = 'transparent';
	swfobject.embedSWF(swfFile, divId+'c', floatWidth, floatHeight, "8.0.0",null,null,params);	
}

function writeFloat() {
	if(floatPosition == 'fixed') {
		document.write(createFloat());
		absolutizeFloat();
		setTimeout("floatEmbedSwf()",100);
	}
}

function closeFloat() {
	var divId = 'floatDiv'+floatID;
	obj = document.getElementById(divId);
	if(obj) {
		obj.style.display='none';
	}
}
	
function getViewportSize() {
	
	 var viewportwidth;
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	 
	 var a = new Array();
	 a[0] = viewportwidth;
	 a[1] = viewportheight;
	 
	 return a;	
}

function addSwfObject() {	
	if(typeof(swfobject) == "undefined") {
		document.write('<script language="javascript" type="text/javascript" src="'+swfObjectFile+'"></script>');
	}	
}
addSwfObject();

if(floatPosition != 'fixed') { 
	setTimeout("createFloat()",100);
	window.onresize = function () {
		absolutizeFloat();
	}
}
else {
	writeFloat();
}