var base = "./images/portfolio/";
var images = [];
var pointer = 0;
var current_img = null;
var img_interval;
var is_hovering = false;

$(document).ready(function() {
	nextImage();
	$(".dropdown_header").click(
		function(event) {
			if(!is_hovering) {
				event.preventDefault();
				$(this).next("ul").stop(true,true);
				$(this).next("ul").fadeIn("slow");
			}
		});
	$("#portfolio_menu").children().hover(
		function() {
			setTimeout(function() { is_hovering = true; },100);
			$(this).children("ul").stop(true,true);
			$(this).children("ul").fadeIn("slow");
			},
		function() {
			is_hovering = false;
			$(this).children("ul").stop(true,true);
			$(this).children("ul").fadeOut("slow");
			});
	$("#portfolio_menu li").hover(
		function() {
			$(this).css("background","#000000");
			$(this).fadeTo("fast",0.6);
			},
		function() {
			$(this).css("background","transparent");
			$(this).fadeTo("fast",1);
			});
	$(".thumbnail a").hover(
		function() {
			$(this).children("img").stop(true,true);
			$(this).children("img").fadeTo("fast",0.2);
			$(this).children(".tooltip").stop(true,true);
			$(this).children(".tooltip").fadeIn("fast");
			},
		function() {
			$(this).children("img").stop(true,true);
			$(this).children("img").fadeTo("fast",1.0);
			$(this).children(".tooltip").stop(true,true);
			$(this).children(".tooltip").fadeOut("fast");
			});
	
});

function setImages(img) {
	images = img;
}

function nextImage() {
	clearInterval(img_interval);
	var next_image = $("<img />");
	next_image.attr("src", base + images[pointer]);
	
	next_image.attr("width","750");
	next_image.attr("height","260");
	next_image.css("display","none");
	next_image.css("z-index","2");
	next_image.css("position","absolute");
	next_image.css("top","0px");
	next_image.css("left","0px");
	
	next_image.load(function() {
		$("#image_holder").append($(this));
		$(this).fadeIn("slow",function() {
			if(current_img != null) current_img.remove();
			current_img = next_image;
			current_img.css("z-index","1");
			img_interval = setInterval(nextImage,2500);
			});
	});
	pointer = (pointer + 1)%images.length;
}

function overFlash(id) { if(id == null) return; document.getElementById(id).focus(); document.getElementById(id).blur(); }
function swapImage(imgName,imgSrc) { if(document.images) document.images[imgName].src = imgSrc; }
