$(function(){
	$(".jCarouselLite").jCarouselLite({
		visible: 1,
		start: 0,
		btnNext: ".next",
		btnPrev: ".prev",
		easing: "easeout",
		speed: 1000,
		btnGo:
		[".externalControl .1", ".externalControl .2",
		".externalControl .3", ".externalControl .4",
		".externalControl .5"]
	});
	slideControl = setInterval("slideCarousel()",5000);
	autoSlide = true;
	animating = false;
	$('.externalControl a').click(function(){
		animating = true;
		c = null;
		$('.externalControl a').each(function(index){
			$(this).children('img').attr('src','http://www.dualtron.ie/wp-content/themes/dualtron/img/carousel-icon-off.png');
		});
		$(this).children('img').attr('src','http://www.dualtron.ie/wp-content/themes/dualtron/img/carousel-icon-on.png');
		c = $(this).attr('class');
		con = $('.service-text-'+c).html();
		$('#service-content #con').fadeOut(200,function(){$(this).html(con);})
							 	  .delay(500)
							      .fadeIn(200,function(){animating = false;})
							      .end();
	});
	$('.externalControl img').click(function(){
		clearInterval(slideControl);
	});
	
	$('.service-tab').hover(
		function(){
			clearInterval(slideControl);
			$('.service-tab').each(function(index){
				$(this).removeClass('on-4');
				$(this).removeClass('highlight');
			});
			if(!animating){
				if(typeof to !== "undefined"){
				  clearTimeout(to);
				}
				$(this).removeClass('service-4');
				$(this).addClass('highlight');
				c = $(this).attr('id');
				c = c.substring(4,c.length);
				$('.externalControl a.'+c).trigger('click');
			} else {
				id = $(this).attr('id');
				param = 'p = ".'+id+'"';
				to = setTimeout("triggerTab("+param+")",2000);
			}
		},
		function(){/*NA*/}
	);

});
count = 1;
function slideCarousel(){
	count++;
	$('.externalControl a.'+count).trigger('click');
	if(count==5){
		count = 0;
	}
}
function triggerTab(tab){
	clearTimeout(to);
	$(tab).removeClass('service-4');
	$(tab).addClass('highlight');
	c = tab.substring(5,tab.length);
	$('.externalControl a.'+c).trigger('click');
}
