var images = [];
var links = [];
var pointer = 0;
var current_img = null;
var current_lnk = null;
var img_interval;

$(document).ready(function() {
	
	$(".dropdown").hover(
		function() {
            $(this).addClass('rollover');
			$(this).children(".submenu").stop(true,true).fadeIn("slow");
		},
		function() {
			$(this).removeClass('rollover');
			$(this).children(".submenu").stop(true,true).fadeOut("fast");
		}
	);
	$(".dropdown_2 a").hover(
		function() {
			$(this).stop(true,true).fadeTo("fast",0.6);
		},
		function() {
			$(this).stop(true,true).fadeTo("fast",1);
		}
	);
	
	$(".fade_out").hover(
		function() {
			$(this).stop(true,true).fadeTo("fast",0.6);
		},
		function() {
			$(this).stop(true,true).fadeTo("fast",1);
		}
	);
	
	nextImage();
	
});

function setImages(img,lnk) {
	images = img;
	links = lnk;
}

function nextImage() {
	clearInterval(img_interval);
	var next_image = $("<img />");	
	next_image.attr("src",images[pointer]);
	next_image.css("display","none");
	var next_link = links[pointer] == "" ? $("<span />") : $("<a href=\"" + links[pointer] + "\" />");
	next_link.append(next_image);
	
	next_image.load(function() {		
		$("#main_img").append(next_link);		
		$(this).fadeIn("slow",function() {
			if(current_img != null) {
				current_lnk.remove();
				current_img.remove();
			}
			current_img = next_image;
			current_lnk = next_link;
			current_img.css("z-index","1");
			if(images.length > 1) img_interval = setInterval(nextImage,2500);
		});
	});
	pointer = (pointer + 1)%images.length;
}
