﻿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);
	}
}

// xDocSize r1, Copyright 2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDocSize()
{
  var b=document.body, e=document.documentElement;
  var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0;
  if (e) {
	esw = e.scrollWidth;
	eow = e.offsetWidth;
	esh = e.scrollHeight;
	eoh = e.offsetHeight;
  }
  if (b) {
	bsw = b.scrollWidth;
	bow = b.offsetWidth;
	bsh = b.scrollHeight;
	boh = b.offsetHeight;
  }
//  alert('compatMode: ' + document.compatMode + '\n\ndocumentElement.scrollHeight: ' + esh + '\ndocumentElement.offsetHeight: ' + eoh + '\nbody.scrollHeight: ' + bsh + '\nbody.offsetHeight: ' + boh + '\n\ndocumentElement.scrollWidth: ' + esw + '\ndocumentElement.offsetWidth: ' + eow + '\nbody.scrollWidth: ' + bsw + '\nbody.offsetWidth: ' + bow);
  return {w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

function closePlayer()
{
	var holder = $(".winBGHolder");
	$(holder).css("height", 0);
	$(holder).css("width", 0);
	
	
	$(holder).html("");

}


function openTour()
{

	if (isMobile())
	{
		var src = "http://www.snaprecordings.com/common/demos/tour_h.264/Snap_Introduction.mp4";
		
		var w = 772;
		var h = 448;
		var top = 50;
		
		//add the video as HTML5
		var holder = $(".winBGHolder");
		
		var holderBG = document.createElement("div");
		
		var docW = xDocSize().w;
		var docH = xDocSize().h;
		
		holderBG.style.width = docW+"px";
		holderBG.style.height = docH+"px";
		holderBG.style.backgroundColor = "#000000";
		holderBG.style.opacity = 0.5;
		holderBG.style.position = "absolute";
		
		$(holder).append(holderBG);
		
		var wDiff = docW - w;
			
		var vidHolder = document.createElement("div");
		vidHolder.style.position = "absolute";
		vidHolder.style.width = (docW-(wDiff/2))+"px";
		vidHolder.style.top = top+"px";
		vidHolder.style.left = (wDiff/2)+"px";
		
		$(holder).append(vidHolder);
		
		var vidHTML = "<div style='padding-bottom: 3px;text-align: right;width:"+w+"px;'><a style='text-decoration:none;' href='javascript:closePlayer();'><img border='0' src='common/images/close.png' /></a></div><video id='svideo' controls='controls' width='"+w+"' height='"+h+"'><source src='"+src+"' type='video/mp4' /></video>";
		
		$(vidHolder).html(vidHTML);
		
		document.getElementById("svideo").load();
		
		
	}
	else 
	{
	
		popup("http://www.snaprecordings.com/common/demos/tour/controller.html", "Snap_Tour", 803, 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);
	

}
