/* FOOTER TRANSITION PICS */
var footerMaxPics = 0;
var curFooterPic = 1;
var footerPicSwapTime = 6000;
var footerPicTimer;
var footerPicSpeed1 = 1000;
var footerPicSpeed2 = 1000;
var footerPicWidth = 248;

/* HOME TRANSITION PICS */
var homeMaxPics = 5;
var curHomePic = 1;
var homePicSwapTime = 6000;
var homePicTimer;
var homePicSpeed1 = 1000;
var homePicSpeed2 = 1000;
var homePicWidth = 901;

/* DROPDOWN */
var isDropped = false;
var dropIsMoving = false;

$(document).ready(function() {
		
    setupHovers();
	
    footerMaxPics = $("#preFooterTop #mBox a").length;
	if (footerMaxPics > 1) footerPicTimer = setTimeout("transitionFooterPics()",footerPicSwapTime);
	
	if ($("#picHome").length > 0) homePicTimer = setTimeout("transitionHomePics()",homePicSwapTime);
});

function setupHovers()
{
	/* HANDLE HOVER IMAGE CHANGES */
	$(".flip").hover(function() {
        if ($(this).attr("class").indexOf("flip") < 0) return false;
        if ($(this).attr("src").indexOf("images/images/") < 0)
        {
        	$(this).attr({"src":$(this).attr("src").replace("images/","images/images/")});
        }
	},function() {
		if ($(this).attr("class").indexOf("flip") < 0) return false;
       	$(this).attr({"src":$(this).attr("src").replace("images/images/","images/")});
	});
	/* END HOVER IMAGE CHANGES */	
}

function transitionFooterPics()
{
	clearTimeout(footerPicTimer);
	var nextId = curFooterPic + 1;
    if (nextId > footerMaxPics) nextId = 1;
    var prevId = curFooterPic - 1;
    if (prevId == 0) prevId = footerMaxPics;
    
    $("#preFooterTop #mBox #mb"+prevId).css({"left":footerPicWidth});
	$("#preFooterTop #mBox #mb"+nextId).css({"display":"none","left":"0px"}).fadeIn(footerPicSpeed2,null);   
	$("#preFooterTop #mBox #mb"+curFooterPic).fadeOut(footerPicSpeed1,null);
    
    curFooterPic = nextId;
    footerPicTimer = setTimeout("transitionFooterPics()",footerPicSwapTime);  
}

function transitionHomePics()
{
	clearTimeout(homePicTimer);
	var nextId = curHomePic + 1;
    if (nextId > homeMaxPics) nextId = 1;
    var prevId = curHomePic - 1;
    if (prevId == 0) prevId = homeMaxPics;
    
    $("#picHome #p"+prevId).css({"left":homePicWidth});
	$("#picHome #p"+nextId).css({"display":"none","left":"0px"}).fadeIn(homePicSpeed2,null);   
	$("#picHome #p"+curHomePic).fadeOut(homePicSpeed1,null);
	
	$("#mid"+curHomePic).removeClass("selected");//.attr({"src":"/images/hs"+curHomePic+".png"});
	$("#mid"+nextId).addClass("selected");//.attr({"src":"/images/images/hs"+nextId+".png"});
	setupHovers();
    
    curHomePic = nextId;
    homePicTimer = setTimeout("transitionHomePics()",homePicSwapTime);  
}

function jumpToHomePic(i)
{
	clearTimeout(homePicTimer);
	
	var nextId = i;
    var prevId = curHomePic - 1;
	
	$("#picHome #p"+prevId).css({"left":homePicWidth});
	$("#picHome #p"+nextId).css({"display":"none","left":"0px"}).fadeIn(homePicSpeed2,null);   
	$("#picHome #p"+curHomePic).fadeOut(homePicSpeed1,null);
	
	$("#mid"+curHomePic).removeClass("selected");//.attr({"src":"/images/hs"+curHomePic+".png"});
	$("#mid"+nextId).addClass("selected");//.attr({"src":"/images/images/hs"+nextId+".png"});
	setupHovers();
	curHomePic = i;
	
	return false;
}

function toggleDrop()
{
	if (isDropped) closeDrop();
	else openDrop();
}

function openDrop()
{
	if (dropIsMoving)
	{
		setTimeout("toggleDrop()",500);	
	}
	else
	{
		$("#topn1").removeClass("flip").attr({"src":"/images/images/n1.png"});
		dropIsMoving = true;
		$("#navDrop").slideDown("fast",function() {
			isDropped = true;
			dropIsMoving = false;
		});
	}	
}

function closeDrop()
{
	if (dropIsMoving)
	{
		setTimeout("closeDrop()",500);	
	}
	else
	{
		$("#topn1").addClass("flip").attr({"src":"/images/n1.png"});
		dropIsMoving = true;
		$("#navDrop").slideUp("fast",function() {
			isDropped = false;
			dropIsMoving = false;
		});
	}
}
