﻿var delta=0.15;
var theFloaters;
var closeB=false;
function aditem(inputurl,inputimg)
{
	
	this.url = inputurl;
	this.img=inputimg;
	this.getcontent=function(){
		var  atemp = document.createElement("a");
		$(atemp).attr("href",this.url);
		var imgtemp = document.createElement("img");
		$(imgtemp).attr("src",this.img);
		$(atemp).append($(imgtemp));
		return  atemp;
	}
}
function floaters() {
		this.items	= [];
		this.addItem	= function(content)
				  {
					  id= "followDiv"+this.items.length;
					  var x;
					  var y;
					  if( this.items.length%2 == 0 )
					  {
						 x=6; 
					 }
					 else
					 {
						x=document.body.clientWidth-106;
					 }
					 var temp = this.items.length/2;
					 var repeat = parseInt(temp);
					 y=90+repeat*(340);
					 var tempdiv = document.createElement("div");
					 $(tempdiv).attr("id",id);
					 $(tempdiv).css("z-index",10);
					 $(tempdiv).css("position","absolute");
					 $(tempdiv).css("width","80px");
					 $(tempdiv).css("height","60px");
					 $(tempdiv).css("left",x+"px");
					 $(tempdiv).css("top",y+"px");
					 $(tempdiv).append(content.getcontent());
					 $(tempdiv).append("<br/>");
				     var closeb=$(tempdiv).append("<img src=\"images/adclose.gif\"/>")
					 closeb.click(closeBanner);
					 closeb.css("cursor","pointer");
  				     $(document.body).append($(tempdiv));
					 this.items[this.items.length]		= $(tempdiv);
				  }
	         	this.play	= function()
				  {
					collection = this.items
					setInterval('play()',10);
				  }
		}
		function play()
		{
			
			if( document.body.clientWidth<=648 || closeB)
			{
			    
				for(var i=0;i<theFloaters.items.length;i++)
				{
						theFloaters.items[i].hide();
				}
				return;
			}
			
			for(var i=0;i<theFloaters.items.length;i++)
			{
				
				var followObj		=  theFloaters.items[i];
				var followObj_y = 90;
				if( i%2 == 0 )
				{
					var followObj_x	=  6;
					
				}
				else
				{
					var followObj_x = document.body.clientWidth-106;
				}
				if( followObj.attr("offsetLeft")!=(document.body.scrollLeft+followObj_x)) {
					var dx=(document.body.scrollLeft+followObj_x-followObj.attr("offsetLeft"))*delta;
					dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
					followObj.css("left",(followObj.attr("offsetLeft")+dx)+"px");
					}
				followObj.show();
			}
		}	
		function closeBanner()
		{
			closeB=true;
			return;
		}
		function getlength(strlength)
		{
			var result;
			if(strlength.indexOf("px")>=0)
			{
				strlength = strlength.replace("px","");
			}
			result = parseInt(strlength);
			if( isNaN(result))
			{
				result = 0;
			}
			return result;
		}
function resetad()
{
	play();
}

