/* HOME TRANSITION PICS */
var homeMaxPics = 5;
var curHomePic = 1;
var homePicSwapTime = 6000;
var homePicTimer;
var homePicSpeed1 = 1000;
var homePicSpeed2 = 1000;
var homePicWidth = 501;

function killColor()
{
	$.fn.colorbox.close();
}

$(document).ready(function() {
		
    setupHovers();
	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/")});
	});
	
	$(".flipDynamic").hover(function() {
        if ($(this).attr("class").indexOf("flip") < 0) return false;
        if ($(this).attr("src").indexOf("images/dynamic/on/") < 0)
        {
        	$(this).attr({"src":$(this).attr("src").replace("images/dynamic/","images/dynamic/on/")});
        }
	},function() {
		if ($(this).attr("class").indexOf("flip") < 0) return false;
       	$(this).attr({"src":$(this).attr("src").replace("images/dynamic/on/","images/dynamic/")});
	});
	/* END HOVER IMAGE CHANGES */	
}

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);
	
	curHomePic = nextId;
    homePicTimer = setTimeout("transitionHomePics()",homePicSwapTime);  
}

function openPop(url)
{
	var useW = "567px";
	var useH = "617px";
	if (url.charAt(0) != '/' && url.indexOf('http') < 0) url = '/' + url;
	if (url.indexOf('ource.php') > 0) useH = "350px";
	
			
	
	$("body").prepend("<a style='display:none;' id='popMe'>&nbsp;</a>");

	var useOverlayClose = true;
		
	$("#popMe").colorbox({href:url, width:useW,height:useH, open: true, iframe:true, overlayClose:useOverlayClose});
	$("#popMe").remove();
	return false;
} 
