$(document).ready(function()
{
	//TOP ADS
	
	var imgWidth = $(".window").width();
	var imgSum = $(".reel img").length;
	
	var reelWidth = imgWidth * imgSum;
	
	for(var i = 1; i <= imgSum; i++)
	{
		$('.paging').append('<a href="#" rel="'+ i +'"></a>');
	}
	
	$('.paging').show();
	$('.paging a:first').addClass('active');	
	$(".reel").css({'width': reelWidth});
	
	rotate = function()
	{
		var id = $active.attr("rel") -1;
		var pos = id * imgWidth;
		
		$('.paging a').removeClass('active');
		$active.addClass('active');
		
		$('.reel').animate({left: -pos},500);
	};
	
	rotateSwitch = function() //Handles rotating the ads
	{
		play = setInterval(function() {
			$active = $('.paging a.active').next();
			if( $active.length === 0) {
				$active = $('.paging a:first');
			}
			rotate();
		}, 5000);
	};
	rotateSwitch(); //Call to begin the interval
	
	$('.reel a').hover(
	function()//OVER HANDLER
	{
		clearInterval(play);
	}, 
	function() //OUT HANDLER
	{
		rotateSwitch();
	});
	
	
	$('.paging a').click(function() {
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});	
	
	
	//NEWS TICKER
	//PARSE JS
	$('.article').empty();
	$.get('index.xml',function(xml) { parseRSS(xml); },'xml');
	
	parseRSS = function(xml)
	{
		$(xml).find('item').each(function()
		{
			var title = $(this).find('title').text();
			var link = $(this).find('link').text();
			var html = "<li><a href=\"" + link + "\" target=\"_new\">"+ title + "</a></li>";
			
			$('.article').append($(html));
		});
		
		$('.article').ticker({
				speed: 'normal',
				timeout: 5000,
				type: 'sequence',
				containerheight: '1.5em'
			});
	};	
});



