﻿var imagesDir = "marketing/images/home/";


if (document.images)
{
	var img1 = new Image();
	img1.src = imagesDir+"works_voice_over.png";
	
	var img2 = new Image();
	img2.src = imagesDir+"works_script_over.png";
	
	var img3 = new Image();
	img3.src = imagesDir+"works_record_over.png";
	
	var img4 = new Image();
	img4.src = imagesDir+"works_download_over.png";
	
	

}


var liveArr = new Array();

var current = null;
var timing = false;

function begin()
{
	$(".headerMenu").find("a").bind("mouseover", navOver);
	$(".headerMenu").find("a").bind("mouseout", navOut);
	
	//.rolloverItem is the a tag whose alpha is set to 0
	$(".rolloverItem").find("a").bind("mouseover", bubbleOver);
	$(".rolloverItem").find("a").bind("mouseout", bubbleOut);
	
	//.bubble is the bubble that pops up when you roll over .rolloverItem
	//this has to handle the event when .rolloverItem doesn't, 
	//otherwise mass chaos ensues.
	$(".bubble").bind("mouseover", tagOver);
	$(".bubble").bind("mouseout", tagOut);
	

	
}



function tagOver(e)
{
	//$(".traceOver").empty();
	//$(".traceOver").html(e.target.nodeName+":"+e.currentTarget.nodeName+":"+e.relatedTarget.nodeName);
	//when the bubble is rolled over:
	//stop the current animation, otherwise it will finish and set the a tag
	//		to alpha 0, when we want it to be visible here
	//clear any remaining functions in the queue
	//remove mouse events on the a tag so that mass chaos is controlled
	//finally, change the class on the a tag so that its visible while we're
	//		hovering over the bubble tag
	$(e.currentTarget).css("display", "block");
	$(e.currentTarget).parent().find(".worksItem").stop();
	$(e.currentTarget).parent().find(".worksItem").clearQueue();
	$(e.currentTarget).parent().find(".worksItem").unbind("mouseover");
	$(e.currentTarget).parent().find(".worksItem").unbind("mouseout");		
	$(e.currentTarget).parent().find("a").removeClass("worksItem");
	$(e.currentTarget).parent().find("a").addClass("worksItemOpen");
	
	
	
}

function tagOut(e)
{
	
	//change everything back from the over event
	$(e.currentTarget).parent().find("a").addClass("worksItem");
	$(e.currentTarget).parent().find(".worksItem").bind("mouseover", bubbleOver);
	$(e.currentTarget).parent().find(".worksItem").bind("mouseout", bubbleOut);
	
	//push the id of the bubble tag into the liveArr
	//if we move the mouse to the a tag, then the a tag event will remove
	//	this id from the list so it won't be removed
	//otherwsie, after the timeout, it will be removed from the list and displayed to none
	liveArr.push(e.currentTarget.id);
	setTimeout("completeOver()", 10);

}

function completeOver()
{
	//if there's objects in here, take the necessary "out" actions and then
	//remove them from the array
	while(liveArr.length > 0)
	{
		if (document.getElementById(liveArr[liveArr.length-1]) != null)
		{
			$("#"+liveArr[liveArr.length-1]).parent().find(".worksItem").fadeTo(100, 0);
			$("#"+liveArr[liveArr.length-1]).css("display", "none");
			liveArr.pop();
		}
	}
}

function bubbleOver(e)
{
	
			var bubble = $(e.currentTarget).parent().parent().find(".bubble").attr("id");
			//the id of the bubble that represents this a tag will be removed
			//from the list of ids that are about to be processed.
			removeLive(bubble);

			$(e.currentTarget).fadeTo(300, 1);
			
		
			$(e.currentTarget).parent().parent().find(".bubble").css("display", "block");
		
	
}



function bubbleOut(e)
{
	
		$(e.currentTarget).fadeTo(200, 0);
		
		$(e.currentTarget).parent().parent().find(".bubble").css("display", "none");

}


function removeLive(id)
{

	var index = -1;
	for(var i=0; i < liveArr.length; i++)
	{
		if (liveArr[i] == id)
		{
			index = i;
		}
	}
	
	if (index > -1)
	{
		liveArr.splice(index, 1);
	}
}


function openTour()
{
	popup("common/demos/marketing/tour/controller.html", "Snap_Tour", 801, 532, false, false);
}

function navOver(e)
{

	$(e.target).fadeTo(200, 1);
	
	
}

function navOut(e)
{
	$(e.target).fadeTo(100, 0);

	
}

function switchSrc(txt, val)
{
	var index = txt.lastIndexOf("_");
	var dot = txt.lastIndexOf(".");
	return txt.substring(0, index)+"_"+val+txt.substring(dot, txt.length);
	

}