(function($){
/*----------------------------------------------------------------------------------
Class: FloatObject
-------------------------------------------------------------------------------------*/
	function FloatObject(jqObj, params)
	{
		this.jqObj = jqObj;
		
		switch(params.speed)
		{
			case 'fast': this.steps = 5; break;
			case 'normal': this.steps = 10; break;
			case 'slow': this.steps = 20; break;
			default: this.steps = 10;
		};
		
		var offset = this.jqObj.offset();
		
		this.currentX = offset.left;
		this.currentY = offset.top;
		
		
		this.origX = typeof(params.x) == "string" ?  this.currentX : params.x;
		this.origY = typeof(params.y) == "string" ?  this.currentY : params.y;
		//if( params.y) this.origY = params.y;
		
		
		//now we make sure the object is in absolute positions.
		this.jqObj.css({'position':'absolute' , 'top':this.currentY ,'left':this.currentX});
	}
	
	FloatObject.prototype.updateLocation = function()
	{
		this.updatedX = $(window).scrollLeft() + this.origX;
		this.updatedY = $(window).scrollTop()+ this.origY;
		
		this.dx = Math.abs(this.updatedX - this.currentX );
		this.dy = Math.abs(this.updatedY - this.currentY );
		
		return this.dx || this.dy;
	}
	
	FloatObject.prototype.move = function()
	{
		if( this.jqObj.css("position") != "absolute" ) return;
		var cx = 0;
		var cy = 0;
		
		if( this.dx > 0 )
		{			
			if( this.dx < this.steps / 2 )
				cx = (this.dx >= 1) ? 1 : 0;
			else
				cx = Math.round(this.dx/this.steps);
			
			if( this.currentX < this.updatedX )
				this.currentX += cx;
			else
				this.currentX -= cx;
		}
		
		if( this.dy > 0 )
		{
			if( this.dy < this.steps / 2 )
				cy = (this.dy >= 1) ? 1 : 0;
			else
				cy = Math.round(this.dy/this.steps);
			
			if( this.currentY < this.updatedY )
				this.currentY += cy;
			else
				this.currentY -= cy;
		}
		
		this.jqObj.css({'left':this.currentX, 'top': this.currentY });			
	}

	
	
/*----------------------------------------------------------------------------------
Object: floatMgr
-------------------------------------------------------------------------------------*/		
	$.floatMgr = {
		
		FOArray: new Array() ,
		
		timer: null ,
		
		initializeFO: function(jqObj,params) 
		{
			var settings =  $.extend({
				x: 0 ,
				y: 0 ,
				speed: 'normal'	},params||{});
			var newFO = new FloatObject(jqObj,settings);
			
			$.floatMgr.FOArray.push(newFO);
			
			if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
			
			//now making sure we are registered to all required window events
			if( !$.floatMgr.registeredEvents ) 
			{
					$(window).bind("resize", $.floatMgr.onChange);
					$(window).bind("scroll", $.floatMgr.onChange);
					$.floatMgr.registeredEvents = true;
			}		
		} , 
		
		adjustFO: function() 
		{
			$.floatMgr.timer = null;
			
			var moveFO = false;
			
			for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
			{
				 FO = $.floatMgr.FOArray[i];
				 if( FO.updateLocation() )  moveFO = true;
			}
			
			if( moveFO )
			{
				for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
				{
					FO = $.floatMgr.FOArray[i];
					FO.move();
				}
				
				if( !$.floatMgr.timer ) $.floatMgr.timer = setTimeout($.floatMgr.adjustFO,50);
			}
		}	,
		
		onChange: function()
		{
			if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
		}
	};
	
/*----------------------------------------------------------------------------------
Function: makeFloat
-------------------------------------------------------------------------------------*/		
	$.fn.makeFloat = function(params) {
		var obj = this.eq(0); //we only operate on the first selected object;
		$.floatMgr.initializeFO(obj,params); 
		if( $.floatMgr.timer == null ) $.floatMgr.adjustFO();
		return obj;
	};
})(jQuery);




/*----------------------------------------------------------------------------------
Function: Logic for splash component
-------------------------------------------------------------------------------------*/		

// Place the splash div to the document
	$(document).ready(function(){
		var ezineURL = (typeof ezineURL != "undefined") ? ezineURL : "http://searchcio.techtarget.com/regPage1/1,296503,sid182,00.html?Offer=CIOmbox121310";
		var column2 = $("div").find("div.col2");
		if(column2!=null){
			var column2Text = column2.text();
			if(column2Text !=null){
//				if(jQuery.trim(column2Text).length == 0){
//					var outerContainer = $("#containerOuter");
//					var pos_outerContainer = outerContainer.offset();
//					var leftPos = parseInt(pos_outerContainer.left) - parseInt(160);
//					var topPos=parseInt("240");
//					$(outerContainer).before("<div id='splash2Col'><a href='" + ezineURL + "'>Go to searchcio-midmarket.bitpipe.com</a></div>");
//					$("#splash2Col").makeFloat({x:leftPos,y:topPos,speed:"fast"});
//				}else{
					column2.prepend("<div id='splash3Col'><a href='" + ezineURL + "'>Go to searchcio-midmarket.bitpipe.com</a></div>");
//				}
			}
		}
	});

// Change the div status when window is resized
	$(window).resize(function(){
		var splashDiv = $("#splash2Col");
		if(splashDiv != null){
			var outerContainer = $("#containerOuter");
			var pos_outerContainer = outerContainer.offset();
			var leftPos = parseInt(pos_outerContainer.left) - parseInt(160);
			var topPos=parseInt("240");
			$("#splash2Col").makeFloat({x:leftPos,y:topPos,speed:"fast"});
		}
	});

