var fadeTimeOut=6; //Set timeout between attractor panels
var scrollSpeed=500; //Set scroll speed for news carousel

//JQuery document enhancement
$(document).ready(function(){

	//Image rollovers
	$("img.rollover,input.rollover").hover(
		function(){
			if($(this).attr("src").indexOf("-over")==-1) {
				var newSrc = $(this).attr("src").replace(".gif","-over.gif");
				newSrc = newSrc.replace(".png","-over.png");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("-over")!=-1) {
				var oldSrc = $(this).attr("src").replace("-over.gif",".gif");
				oldSrc = oldSrc.replace("-over.png",".png");
				$(this).attr("src",oldSrc);
			}
		}
	);

	//Call home page publications carousel function
	if ($(".pub-carousel").length) {
		publicationsHomeCarousel();
	}
	
	//Call latest news carousel function
	if ($(".cats-display .carousel").length) {
		newsCarousel();
	}

	//Call latest news carousel 1 function
	if ($(".carousel1").length) {
		news1Carousel();
	}

	//Call latest news carousel 2 function
	if ($(".carousel2").length) {
		news2Carousel();
	}

	//Call latest news carousel 3 function
	if ($(".carousel3").length) {
		news3Carousel();
	}

	//Call latest news carousel 4 function
	if ($(".carousel4").length) {
		news4Carousel();
	}

	//Call latest news carousel 5 function
	if ($(".carousel5").length) {
		news5Carousel();
	}

});


	
//Home page publications carousel function
function publicationsHomeCarousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".pub-scroller div.entry").length; //Define number of items

	$("a#pub-prev").click(function(){ //Previous publication
		prevItem();
		return false;
	});
	
	$("a#pub-next").click(function(){ //Next publication
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".pub-scroller").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.pub-carousel-controls li.thumbnail img").attr("src","healthpromotion_ie_files/thumbnail.gif");
		$("ul.pub-carousel-controls li.thumbnail img:eq("+currentItem+")").attr("src","healthpromotion_ie_files/thumbnail-over.gif");
	};
};

//News carousel function
function newsCarousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".scroller div.entry").length; //Define number of items

	$("a#entry-prev").click(function(){ //Previous item
		prevItem();
		return false;
	});
	
	$("a#entry-next").click(function(){ //Next item
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".scroller").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.carousel-controls li.thumbnail img").attr("src","/images/buttons/thumbnail.gif");
		$("ul.carousel-controls li.thumbnail img:eq("+currentItem+")").attr("src","/images/buttons/thumbnail-over.gif");
	};
};

//News 1 carousel function
function news1Carousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".scroller1 div.entry1").length; //Define number of items

	$("a#entry1-prev").click(function(){ //Previous item
		prevItem();
		return false;
	});
	
	$("a#entry1-next").click(function(){ //Next item
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".scroller1").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.carousel1-controls li.thumbnail img").attr("src","/images/buttons/thumbnail.gif");
		$("ul.carousel1-controls li.thumbnail img:eq("+currentItem+")").attr("src","/images/buttons/thumbnail-over.gif");
	};
};


//News 2 carousel function
function news2Carousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".scroller2 div.entry2").length; //Define number of items

	$("a#entry2-prev").click(function(){ //Previous item
		prevItem();
		return false;
	});
	
	$("a#entry2-next").click(function(){ //Next item
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".scroller2").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.carousel2-controls li.thumbnail img").attr("src","/images/buttons/thumbnail.gif");
		$("ul.carousel2-controls li.thumbnail img:eq("+currentItem+")").attr("src","/images/buttons/thumbnail-over.gif");
	};
};


//News 3 carousel function
function news3Carousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".scroller3 div.entry3").length; //Define number of items

	$("a#entry3-prev").click(function(){ //Previous item
		prevItem();
		return false;
	});
	
	$("a#entry3-next").click(function(){ //Next item
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".scroller3").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.carousel3-controls li.thumbnail img").attr("src","/images/buttons/thumbnail.gif");
		$("ul.carousel3-controls li.thumbnail img:eq("+currentItem+")").attr("src","/images/buttons/thumbnail-over.gif");
	};
};


//News 4 carousel function
function news4Carousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".scroller4 div.entry4").length; //Define number of items

	$("a#entry4-prev").click(function(){ //Previous item
		prevItem();
		return false;
	});
	
	$("a#entry4-next").click(function(){ //Next item
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".scroller4").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.carousel4-controls li.thumbnail img").attr("src","/images/buttons/thumbnail.gif");
		$("ul.carousel4-controls li.thumbnail img:eq("+currentItem+")").attr("src","/images/buttons/thumbnail-over.gif");
	};
};


//News 5 carousel function
function news5Carousel() {
	var numberOfItems=0; //Initialise function globals
	var currentItem=0;

	numberOfItems=$(".scroller5 div.entry5").length; //Define number of items

	$("a#entry5-prev").click(function(){ //Previous item
		prevItem();
		return false;
	});
	
	$("a#entry5-next").click(function(){ //Next item
		nextItem();
		return false;
	});
	
	function nextItem() { //Scroll functions
		if (currentItem<numberOfItems-1) {
			currentItem++;
			scrollCarousel();
		}
	};

	function prevItem() {
		if (currentItem>0) {
			currentItem--;
			scrollCarousel();
		}
	};

	function scrollCarousel() { //Tween carousel to destination
		$(".scroller5").animate({left: (165*(currentItem)*-1)}, {duration: scrollSpeed, easeMethod: "easeInOut"});

		setThumbnails();
	};

	function setThumbnails() { //Set active thubnail
		$("ul.carousel5-controls li.thumbnail img").attr("src","/images/buttons/thumbnail.gif");
		$("ul.carousel5-controls li.thumbnail img:eq("+currentItem+")").attr("src","/images/buttons/thumbnail-over.gif");
	};
};