(function($) {
	var ik= typeof jQuery == 'function',
	ml		= [31,28,31,30,31,30,31,31,30,31,30,31],
	$tar,
	url,
	ikt,
	cw,
	tw,
	dx,
	ix,
	md,
	or		=	['width','left','clientX'],//['height','top'],
	$ikt;
	function tick(e){
		alert($(e.target).parent().attr('id'));
	}
	function expired(t){																				//	>>	EXPIRATION CHECK 14 DAYS
		var d 	= new Date(),																						//			date object
		dd	= d.getDate()-14,																				//			get expiration day
		m	= (d.getMonth()+1)-parseFloat(t.find('div#date').text().substring(2,4));			//			compare news month to current month
		if(m==0){																								//			news month equals current month
			if(dd>parseFloat(t.find('div#date').text().substring(0,2)))return false;		//	<<	news day expired
			return true;																								//	++	news valid	
		}else{
			if(m>1)return false;																			//	<<	difference exceeds 1 month
			dd=ml[d.getMonth()-m]+dd;																//			translate expiration day to previous month
			if(dd>parseFloat(t.find('div#date').text().substring(0,2)))return false;		//	<<	news day expired
			return true;																								//	++	news valid	
		}
		return false;																								//	++	news valid	
	}
	
	function initTicker($t)	{	
		$ikt=$t;
		$.get( url, 
			function( data ) { 
				var t 	= $('<div></div>').append(data)
				if(!expired(t))return false;									//	<<	news expired
				var w=0,$th;											//	>>	INIT TICKER
				t.find('div#item').appendTo( $ikt );			//			insert ticker content
				$ikt.addClass('active');							//			apply ticker css
				$ikt.find('div#item a').each(function(){		//				calculate aggregated content width
					w+=(($th=$(this))[or[0]]()+((parseFloat($th.css(or[1])))?parseFloat($th.css(or[1])):0)+80);
				})
				$ikt.find('div#item')[or[0]](w);					//			set content container width to content width
				cw=w;													//			ticker content width
				tw=$ikt[or[0]]();										//			ticker width [stylesheet]
				ix=tw;													//			init x animated ticker
				md=$ikt.offset()[or[1]]+(tw*0.5);					//			ticker horizontal center reference for mouse handling
				dx=-cw;													//			target x animated ticker
				if(w>tw){												//				if ticker content width exceeds ticker width
					$ikt.hover(function(e){
									  if(parseInt(Math.abs(e[or[2]]-md)/50)==0)return $ikt.find('div#item').stop();		//	<<	cancel on horizontal center zone
									  var td=((e[or[2]]<md)?-cw:tw),				//			set temp target x to relation mousex to ticker
									  ti=((e[or[2]]<md)?tw:-cw);					//			set temp init x to relation mousex to ticker
									  if(td==dx)return false;							//	<<	cancel to prevent double action
									  $ikt.find('div#item').stop();					//			cancel ongoing animations
									  dx=td;													//			set target x to temp
									  ix=ti;													//			set init x to temp
									  var sc=parseInt((Math.abs(dx-$ikt.find('div#item').position()[or[1]])/tw)*15000);		//	calculate animation duration
									  ticker(sc);											//			call animation
								},
								function(e){
									if($ikt.find('div#item:animated').length&&$ikt.find('div#item:animated').length>0)return false;
									  var sc=parseInt((Math.abs(dx-$ikt.find('div#item').position()[or[1]])/tw)*15000);
									ticker(sc);
								});
					ticker(parseInt((Math.abs(dx-ix)/tw)*15000),true);
				}
			});
		return this;
	}
	
	function ticker(sc,b)	{	
	if(b)$ikt.find('div#item').css(or[1],ix+'px');
	$ikt.find('div#item').animate(
												((or[1]=='left')?{	'left'		: 	dx}:{'top':dx}),
												{	duration		: 	sc,
													queue		: 	false,
												  	easing		: 	'linear',
												  	complete	: 	function(){
																	  		ticker(parseInt((Math.abs(dx-ix)/tw)*15000),true);
																 		}
												});
	}
	
	var public_met	=	{
		set:	function($st){
					$st.each(function(){
						return ticker($(this));
					});
		}
	}

	if(ik){	
	   	$.fn.ikticker	=	function(h) {
			var config	=	{
				ns			:	null	
			};
			
			this.set=public_met.set;
			if(typeof h!='undefined'){
				url=h;
			}
			
			ikt=initTicker($(this));
			if(ikt){
				return this;
			}
			return null
	   	};
	}
	
		
})(jQuery);
