/* 2010 by Mark de Jong @ Eggplant Digital */
jQuery(document).ready(function(){
	var delay=300;
	jQuery("#tab1").hover(
		function () {
			clearInterval(sh);
			showItem(1);
		},
		function () {
			sh = setInterval(autoRotate, timer);;
		}
	);
	jQuery("#tab2").hover(
		function () {
			clearInterval(sh);
			showItem(2);
		},
		function () {
			sh = setInterval(autoRotate, timer);;
		}
	);
	jQuery("#tab3").hover(
		function () {
			clearInterval(sh);
			showItem(3);
		},
		function () {
			sh = setInterval(autoRotate, timer);;
		}
	);
	jQuery("#tab4").hover(
		function () {
			clearInterval(sh);
			showItem(4);
		},
		function () {
			sh = setInterval(autoRotate, timer);;
		}
	);
	jQuery("#tab5").hover(
		function () {
			clearInterval(sh);
			showItem(5);
		},
		function () {
			sh = setInterval(autoRotate, timer);;
		}
	);

var curr_no=1;
var timer_no=1;
var rotate_timer="";
var timer=4000;
var sh;

function showItem(no){
	if(curr_no!=no){
		resetItems();
		jQuery("#slide-"+no).fadeIn();
		t=(no-1)*107+50; //step distance + start position
		jQuery("#tab-arrow").css("left",t+"px");
		jQuery("#tab"+no).addClass("hdr_news_act");
		curr_no=no;
	}
}

function resetItems(){
	jQuery("#slide-"+curr_no).fadeOut();
	jQuery("#tab"+curr_no).removeClass("hdr_news_act");
}
function autoRotate(){
	showItem(timer_no);
	timer_no++;
	if(timer_no >5){
		timer_no=1;
	}
}
sh = setInterval(autoRotate, timer);
});


// Original Author: Jeffrey Way (http://net.tutsplus.com/author/jeffreyway/)
// Link: http://net.tutsplus.com/videos/screencasts/how-to-build-a-super-duper-news-scroller/
 
// Extended by Kyle Stevenson (Ticker now Pauses on Hover)
// New Business Media, 2009 - http://nbm.com.au/
 
jQuery.fn.newsScroll = function(options) {
	return this.each(function() {
		var  
			jQuerythis = jQuery(this),
			defaults = {  
				speed: 1000,   
				delay: 3000,   
				list_item_width: jQuerythis.children('li').outerWidth()   
			},
 
			settings = jQuery.extend({}, defaults, options),
			timer = false;
 
		// On MouseOut (Start)
		jQuerythis.mouseout(function() {
			timer = setInterval(function() {
				jQuerythis.children('li:first')
					.animate({
							marginLeft : '-' + settings.list_item_width,
							opacity: 'hide'
					},
					settings.speed,
					function() {
						jQuerythis
							.children('li:first')
							.appendTo(jQuerythis)
							.css('marginLeft', 0)
							.fadeIn(300);
					}
				); // end animate
			}, settings.delay);
		}).mouseout(); // Start Ticker by default
 
		// On MouseOver (Pause)
		jQuerythis.mouseover(function() {
			clearInterval(timer);
		});
	});
}