//Global variables.
var checkInterval="";
var getStatus;
var globalCompetitors;

function swapImage(itemID){    //Get a referenc to the incoming item id.	var x = LA_findObj(itemID);		//Set this object to the "on" state.	x.oSrc = "images/" + itemID + "_on.png";	x.src = "images/" + itemID + "_on.png";}
function restoreImage(itemID) {    //Get a reference to the incoming item id.	var x = LA_findObj(itemID);		//Set this object to the "off" state.	x.oSrc = "images/" + itemID + "_off.png"; 	x.src = "images/" + itemID + "_off.png";}

//This function finds the target object anywhere within the document object.
function LA_findObj(n, d) {//v4.01  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=LA_findObj(n,d.layers[i].document);  if(!x && d.getElementById) x=d.getElementById(n); return x;}

function playIntro()
{
    //Set the text after the first timer has completed.
    var connectionDiv = document.getElementById("connection");
    connectionDiv.innerHTML = "Video calling enabled.";
    
    //Set up a second timer to advance the page.
    setTimeout('playIntro2()',1000);
}

function playIntro2()
{
    //Change the content's iframe source.
    changePage('videoCall');
}

function videoCall()
{
    document.getElementById("jay").innerHTML = '<img src="images/jay.png" title="Jay calling" />';
    setTimeout('videoCall2()',13000);
}

function videoCall2()
{
    changePage('introduction');
}

function showHideText(tab)
{
    //Get a reference to the textArea and the tab buttons.
    var layer;
	var tabButtons;
	var text = "";

    //Based on the tab type, switch the buttons.
	if (tab == "subcloseProfiles")
	{
	    layer = parent.document.getElementById("textArea");
	    tabButtons = parent.document.getElementById("tabButtons");
	}
	else
	{
	    layer = document.getElementById("textArea");
	    tabButtons = document.getElementById("tabButtons");
	}
	
    //Check the incoming tab type.
    if (tab == "close" || tab == "subclose")
	{
	    //The subclose is the close button at the top of the video and profile pages. This call is from 
	    //a child page and thus needs a slightly different reference to the textArea and tab buttons.
	    if (tab == "subclose")
	    {
	        layer = parent.document.getElementById("textArea");
	        tabButtons = parent.document.getElementById("tabButtons");
        }
        
        //Reset the tab button states.
        text += '<a href="javascript:showHideText(\'videos\');" onmouseover="swapImage(\'video\');" onmouseout="restoreImage(\'video\');"><img id="video" src="images/video_off.png" id="videoButton" title="Video List" /></a><br />';
	    text += '<a href="javascript:showHideText(\'profiles\');" onmouseover="swapImage(\'profiles\');" onmouseout="restoreImage(\'profiles\');"><img id="profiles" src="images/profiles_off.png" id="profilesButton" title="Profiles" /></a><br />';
        tabButtons.innerHTML = text;
	    
	    //Clear the text area, effectively closing it.
	    layer.innerHTML = '';
	}
	else
	{
	    //Check the text area to see if it contains any information.
		if (layer.innerHTML == "" || layer.innerHTML.indexOf(tab) == -1)
		{
		    //A descision was made (July 25, 2008) that whenever the profiles tab is closed, open up the video tab.
		    if (tab == "videos" || tab == "subcloseProfiles" || tab == "closeProfiles")
			{
			    //Set the buttons for the video tab.
			    text += '<a href="javascript:showHideText(\'close\');"><img id="video" src="images/video_on.png" id="videoButton" title="Video List" /></a><br />';
				text += '<a href="javascript:showHideText(\'profiles\');" onmouseover="swapImage(\'profiles\');" onmouseout="restoreImage(\'profiles\');"><img id="profiles" src="images/profiles_off.png" id="profilesButton" title="Profiles" /></a><br />';
                tabButtons.innerHTML = text;								
				
				//Reload the text area.
				layer.innerHTML = '<iframe name="videoPage" src="videos.html" height="100%" width="81" frameborder="0" scrolling="no"></iframe>';
			}
			else
			{
			    //Set the buttons for the profiles tab.
				text += '<a href="javascript:showHideText(\'videos\');" onmouseover="swapImage(\'video\');" onmouseout="restoreImage(\'video\');"><img id="video" src="images/video_off.png" id="videoButton" title="Video List" /></a><br />';
				text += '<a href="javascript:showHideText(\'closeProfiles\');"><img id="profiles" src="images/profiles_on.png" id="profilesButton" title="Profiles" /></a><br />';
                tabButtons.innerHTML = text;
				
				//Reload the text area.
				layer.innerHTML = '<iframe name="profilesPage" src="profiles.html" height="100%" width="575" frameborder="0" scrolling="no"></iframe>';
				
				//Clear the video check interval - this is the check for the end of movie.
				//The variable interval is set on the event.html page as a reference to the setInterval function.
				window.clearInterval(interval);
				
				//Clear the movie window.
				frames['eventMovie'].document.body.innerHTML = "";
				
				//Reset the title on the event window.
				var eventTitle = document.getElementById("eventTitle");
                var parentLoc = parent.window.location.toString();
			    var mapLocation = parentLoc.substring(parentLoc.indexOf("location=") + 9, parentLoc.length).replace(/_/g," ").replace("&launch=true","").replace(/%20/g," ").replace("%C3%B4","ô").replace("%C3%A2","â").replace("%C3%A9","é").replace("%C3%89","É").replace("%E2%80%99","’");
			    
			    if (mapLocation == "Womens Apparel Design") mapLocation = "Women's Apparel Design";
			    
			    eventTitle.innerHTML = "Event: " + mapLocation;
			}
		}
	}
}

//This function opens the footer assets.
function OpenFooterAsset(URL) 
{
	window.open(URL,"WorldOfSkills","toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,scrolling=yes,resizable=yes,width=750,height=550,left=0,top=0");
}

//This function embeds the Flash objects.
function embedFlashObject(asset, height, width, color)
{
	document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ');
	    document.write('width="' + width + '"');
	    document.write('height="' + height + '"');
	    document.write('align="middle"');
	    document.write('id="' + asset.substring(0,asset.indexOf(".")).replace(/ /g,"_") + '"');
	    document.write('name="' + asset.substring(0,asset.indexOf(".")).replace(/ /g,"_") + '"');
	    document.write('classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" >');
	    document.write('<param name="src" value="' + asset + '" />');
	    document.write('<param name="quality" value="high" />');
	    document.write('<param name="wmode" value="transparent" />');
	    document.write('<param name="bgcolor" value="' + color + '" />');
	    document.write('<param name="menu" value="false" />');
	    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    	
	    document.write('<embed ' );
	    document.write('  width="' + width + '" ' );
	    document.write('  height="' + height + '" ' );
	    document.write('  src="' + asset + '" ' );
	    document.write('  quality="high" ' );
	    document.write('  pluginspage="http://www.macromedia.com/go/getflashplayer" ' );
	    document.write('  align="middle" ' );
	    document.write('  wmode="transparent"' );
	    document.write('  bgcolor="' + color + '" ' );
	    document.write('  id="' + asset.substring(0,asset.indexOf(".")).replace(/ /g,"_") + '"' );
	    document.write('  name="' + asset.substring(0,asset.indexOf(".")).replace(/ /g,"_") + '"' );
	    document.write('  menu="false" ');
	    document.write('  allowScriptAccess="sameDomain" ' );
	    document.write('  type="application/x-shockwave-flash" />' );
	document.write('</object>');
}

//This function embeds the QuickTime objects with the movie playing by default.
function embedQuicktimeObject(movie, width, height, id) 
{
    document.write("<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='"+width+"' height='"+height+"' codebase='http://www.apple.com/qtactivex/qtplugin.cab' id='"+id+"'>");		
	    document.write("<param name='src' value='" + movie + "' />");
	    
	    if (movie.indexOf("blank") > -1)
	    {
	        document.write("<param name='controller' value='false' />");
	        document.write("<param name='autoplay' value='false' />");
	    }
	    else
	    {
	        document.write("<param name='controller' value='true' />");
	        document.write("<param name='autoplay' value='true' />");
	    }
	    
	    document.write("<param name='enablejavascript' value='true' />");
	    document.write("<param name='scale' value='aspect' />");
	    document.write("<param name='kioskmode' value='true' />");
	    document.write("<param name='bgcolor' value='#000000' />");
		
		if (movie.indexOf("blank") > -1)
		{
	        document.write("<embed ");
	            document.write("name='"+id+"'");
	            document.write("src='" + movie + "'");
		        document.write("width='"+width+"'");
		        document.write("height='"+height+"'");
		        document.write("autoplay='false'");
		        document.write("scale='aspect'");
		        document.write("kioskmode='true'");
		        document.write("bgcolor='#000000'");
		        document.write("type='video/quicktime'");
		        document.write("pluginspage='http://www.apple.com/quicktime/download/'");
		        document.write("enablejavascript='true'");
		        document.write("controller='false'");
	        document.write(" />");
        }
        else
        {
            document.write("<embed ");
	            document.write("name='"+id+"'");
	            document.write("src='" + movie + "'");
		        document.write("width='"+width+"'");
		        document.write("height='"+height+"'");
		        document.write("autoplay='true'");
		        document.write("scale='aspect'");
		        document.write("kioskmode='true'");
		        document.write("bgcolor='#000000'");
		        document.write("type='video/quicktime'");
		        document.write("pluginspage='http://www.apple.com/quicktime/download/'");
		        document.write("enablejavascript='true'");
		        document.write("controller='true'");
	        document.write(" />");
        }
    document.write("</object>");
}

//This function embeds the QuickTime objects with the movie stopped by default.
function embedQuicktimeObjectStopped(movie, width, height, id) 
{
    document.write("<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' width='"+width+"' height='"+height+"' codebase='http://www.apple.com/qtactivex/qtplugin.cab' id='"+id+"'>");		
	    document.write("<param name='src' value='" + movie + "' />");
	    document.write("<param name='controller' value='true' />");
	    document.write("<param name='autoplay' value='false' />");
	    document.write("<param name='enablejavascript' value='true' />");
	    document.write("<param name='scale' value='aspect' />");
	    document.write("<param name='kioskmode' value='true' />");
	    document.write("<param name='bgcolor' value='#000000' />");
			
	    document.write("<embed ");
		    document.write("name='"+id+"'");
		    document.write("src='" + movie + "'");
		    document.write("width='"+width+"'");
		    document.write("height='"+height+"'");
		    document.write("autoplay='false'");
		    document.write("scale='aspect'");
		    document.write("kioskmode='true'");
		    document.write("bgcolor='#000000'");
		    document.write("type='video/quicktime'");
		    document.write("pluginspage='http://www.apple.com/quicktime/download/'");
		    document.write("enablejavascript='true'");
		    document.write("controller='true'");
	    document.write(" />");
    document.write("</object>");
}

//This function embeds the Shockwave camera tool.
function embedDCR()
{
    document.write("<object classid='clsid:166B1BCA-3F9C-11CF-8075-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0' id='cameraTool' width='0' height='0'>");
        document.write("<param name='src' value='dswmedia/cameraTool.dcr'>");
        document.write("<param name='swRemote' value='swSaveEnabled=\'false\' swVolume=\'false\' swRestart=\'false\' swPausePlay=\'false\' swFastForward=\'false\' swContextMenu=\'false\' '>");
        document.write("<param name='swStretchStyle' value='none'>");
        document.write("<param name='bgColor' value='#000000'>");
        document.write("<param name='name' value='cameraTool'>");
        document.write("<param name='progress' value='false'>");
        document.write("<param name='logo' value='false'>");
        document.write("<param name='swLiveConnect' value='true'>");
        document.write("<param name='pluginspage' value='http://www.macromedia.com/shockwave/download/'>");
    
        document.write("<embed ");
            document.write("src='dswmedia/cameraTool.dcr' ");
            document.write("bgColor='#000000' ");
            document.write("name='cameraTool' ");
            document.write("swLiveConnect='true' ");
            document.write("progress='false' ");
            document.write("logo='false' ");
            document.write("width='0' ");
            document.write("height='0' ");
            document.write("swRemote='swSaveEnabled=\'false\' swVolume=\'false\' swRestart=\'false\' swPausePlay=\'false\' swFastForward=\'false\' swContextMenu=\'false\' ' ");
            document.write("swStretchStyle='none'");
            document.write("type='application/x-director' ");
            document.write("pluginspage='http://www.macromedia.com/shockwave/download/' />");
    document.write("</object>");
}

//This function is called whenever the user changes the page or view.
function changePage(incomingPage, incomingLocation)
{
    //Change the parent querystring.
    if (incomingLocation) parent.window.location.href = "index.html#page=" + incomingPage + "&location=" + incomingLocation;
    else parent.window.location.href = "index.html#page=" + incomingPage;

    //Get a reference to the camera button and set the camera to that it is usable.
	//var cameraCell = parent.document.getElementById("cameraCell");
    //cameraCell.innerHTML = '<a href="javascript:camClick();" onmouseover="swapImage(\'camera\');" onmouseout="restoreImage(\'camera\');"><img id="camera" src="images/camera_off.png" title="Photo Capture to Clipboard" /></a>';
    
    //Get a reference to the content cell and set its source to the incoming page.
    var contentCell = parent.document.getElementById("contentCell");
    contentCell.innerHTML = "<iframe name='content' src='" + incomingPage + ".html' height='100%' width='100%' marginwidth='0' marginheight='0' frameborder='0' scrolling='none'></iframe>";
}

function checkEndOfMovie(incomingMovie)
{
    var getState;

    if (incomingMovie == "introduction") getState = $f().getState();
    else getState = frames['eventMovie'].$f().getState();

	//Check to see if the incoming movie is at the end.
	if (getState == 1)
	{
	    //If the incoming page is the introduction movie, then redirect the browser to the map page.
	    if (incomingMovie == "introduction") changePage('map');
	    
	    //If the incoming page is an event movie, then pop open the video tab and clear the interval set on the event.html page
	    //so that the tab doesn't keep popping open.
	    if (incomingMovie == "event")
	    {
	        showHideText('videos');
	        window.clearInterval(interval); //The variable interval is set on the event.html page as a reference to the setInterval function.
	    }
	}
}

function switchMovie(incomingEvent, incomingMovie)
{
    //Set the event movie iframe's location to the incoming event and play the selected movie.
    parent.frames['eventMovie'].location = "eventMovie.html?location=" + incomingEvent + "-" + incomingMovie;
}

function browserDiv(url)
{
    //Set the browser div layer to visibile.
    document.getElementById("browserDiv").style.visibility = "visible";
    
    //Display the offsite link information to the user.
    document.getElementById("browserDiv").innerHTML = '<iframe name="browserDiv" src="browserDiv.html?url=' + url + '" height="120" width="250" frameborder="0" scrolling="no"></iframe>';
}

function closeDiv()
{
    //Set the browser div layer to invisible.
    parent.document.getElementById("browserDiv").style.visibility = "hidden";
}

function browserLink(url)
{
    //Close the browser div layer.
    closeDiv();
    
    //Open the selected link in a new window.
    window.open(url,"WorldofSkills","toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,scrolling=yes,resizable=yes,width=950,height=550,left=50,top=125");
}

function resetLens()
{
    var lens = document.getElementById("lens");
    lens.src = "images/lens.png";
}

function camClick() 
{
    if (window.navigator.appName == "Microsoft Internet Explorer") 
    {
        //Get a reference to the QuickTime movie that contains the camera sound and play the "click" sound.
        var cameraSound = document.getElementById("cameraSound");
        cameraSound.play();
    }
    
    //Get the camera tool's absolute left position.
    var obj = document.getElementById("cameraTool");
    var curleft = 0;
    var curtop = 0;
    
    if(obj.offsetParent)
        while(1) 
        {
            curleft += obj.offsetLeft;
            
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;

    var obj = document.getElementById("cameraTool");
    
    //Get the camera tool's absolute top position.
    if(obj.offsetParent)
        while(1)
        {
            curtop += obj.offsetTop;
            
            if(!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;

    /* INTERNET EXPLORER */
    if (window.navigator.appName == "Microsoft Internet Explorer") 
    {
        var winID = 0;
        
        curtop += window.screenTop;	    // Screen X Position
        curleft += window.screenLeft;	// Screen Y Position
    }
    else
    {
    /* 
		Firefox-Netscape-Safari 
		
		Step 1 - Get the current X, Y position of the browser.
		Step 2 - Get the current width and height of the browser.
		Step 3 - Move the browser to 0,0 {x,y} using window.moveTo
		Step 4 - Resize browser to full screen using window.resizeTo
		Step 5 - Calculate size of menubar
		Step 6 - Resize browser back to original size
		Step 7 - Move the browser back to original x,y position
	*/

		// Step 1
	    var winID = 1;
		var tempX = window.screenX;
		var tempY = window.screenY;
		
		if (window.screenY < 0 )
		{
			tempY = 0;	// firefox sometimes gets the ScreenY as -4, thus set to 0
			resizeAdjust = 1;
		}
		else
		{
			tempY = window.screenY;
			resizeAdjust = 16;	// firefox doesn't calculate 8 pixels of width for some reason, add it back when resizing
		}
		
		// Step 2
		var tempWidth = document.body.clientWidth;
		var tempHeight = document.body.clientHeight;
		
		// Step 3 and 4
		window.moveTo(0,0);
		window.resizeTo(window.screen.availWidth, window.screen.availHeight);
		
		/* Step 5 */
		// if safari
		if (window.navigator.appVersion.indexOf("Safari") > -1) 
		{
			var menuBarHeight = window.screen.availHeight - document.body.scrollHeight;
			
			/* Step 6 Move Window back to Original Location and Resize */
			window.resizeTo(tempWidth - 15, tempHeight + menuBarHeight);
			window.moveTo(tempX, tempY);	
			curtop += menuBarHeight;					
		}
		else
		{
			/* Step 6 Move Window back to Original Location and Resize */
			var statusBarHeight = 25;
			var menuBarHeight = window.screen.availHeight - document.body.offsetHeight;
			
			window.resizeTo(tempWidth + resizeAdjust, tempHeight+menuBarHeight);
			window.moveTo(tempX, tempY);
			
			curtop += (menuBarHeight-statusBarHeight);
		}
	}
    
    //Set up the variables used for the camera tool.
    var x = curleft + 1; //Add the width of the camera tool.
    var y = curtop + 1;//Add the height of the camera tool.
    var w = "623";
    var h = "410";
    
    //Set up the camera data string.
    var cameraData = "["+winID+","+x+","+y+","+w+","+h+"]";
    
    //Get a reference to the camera tool.
    var sw = document.getElementById('cameraTool');	
    
    //Pass the camera data string to the camera tool.
    var success = sw.EvalScript(cameraData);
    
    //If the camera tool returns successfully, alert the user that something has happened.
    if (success) alert("A photo has been added to the clipboard.");
}

function setCompetitors(competitors)
{
    globalCompetitors = competitors;
}

function changeProfile(competitor, incomingEvent, incomingName)
{
    for (i = 0; i <= globalCompetitors.nodeInfo.length - 1; i++)
    {
        var competitorCell = document.getElementById(i);
        var text = '';
        var source = '';
        
        if (i == competitor)
        {
            text += '<div>';
                source = "images/" + incomingEvent.replace("ô","o").replace("é","e").replace("É","E").replace(":","").replace("’","").replace(/ /g,"") + "-" + incomingName + "_on.png";
                text += '<img src="' + source + '" height="75" alt="' + incomingName + '" title="' + incomingName + '" /><br /><font color="#000000">' + incomingName + '</font>';
            text += '</div>';
        }
        else
        {
            text += '<div>';
                source = incomingEvent.replace("ô","o").replace("é","e").replace(":","").replace("’","").replace(/ /g,"") + "-" + globalCompetitors.nodeInfo[i]["name"];
                text += '<a href="javascript:changeProfile(\'' + i + '\',\'' + incomingEvent + '\',\'' + globalCompetitors.nodeInfo[i]["name"] + '\');" onmouseover="swapImage(\'' + source + '\');" onmouseout="restoreImage(\'' + source + '\');"><img id="' + source + '" src="images/' + source + '_off.png" height="75" alt="' + globalCompetitors.nodeInfo[i]["name"] + '" title="' + globalCompetitors.nodeInfo[i]["name"] + '" /><br />' + globalCompetitors.nodeInfo[i]["name"] + '</a>';
            text += '</div>';
        }
        
        competitorCell.innerHTML = text;
    }
    
    var competitors = document.getElementById("competitors");
    
    competitors.innerHTML = '<iframe name="competitorProfiles" src="competitorProfiles.html?name=' + incomingName + '" height="344px" width="480px" frameborder="0" scrolling="auto"></iframe>';
}

function GetCookie(name) 
{
    var result = null;
    var myCookie = " " + document.cookie + ";";
    var searchName = " " + name + "=";
    var startOfCookie = myCookie.indexOf(searchName);
    var endOfCookie;
    
    if (startOfCookie != -1) 
    {
        startOfCookie += searchName.length;
        endOfCookie = myCookie.indexOf(";" , startOfCookie);
        result = unescape(myCookie.substring(startOfCookie, endOfCookie));
    }
    
    return result;
}

/* set the cookie value */
function SetCookieValue(name,value,expires,path,domain,secure) 
{
    var expString = ((expires == null) ? "" : ("; expires=" + expires.toGMTString())); 
    var pathString = ((path==null) ? "" : ("; path=" +path));
    var domainString = (( domain == null) ? "" : ("; domain="+domain));
    var secureString=((secure==true) ? "; secure" : "");
    
    document.cookie = name + "=" + escape(value) + expString+pathString+domainString+secureString;
}

function ClearCookie(name) 
{
    var ThreeDays = 3 * 24 * 60 * 60 + 1000;
    var expDate = new Date();

    expDate.setTime(expDate.getTime() - ThreeDays);
    document.cookie = name + "=ImOutOfHere; expires=" + expDate.toGMTString();
}

function updateVideoPage()
{
    try
    {
        parent.frames['videoPage'].location.href = "videos.html";
    }
    catch(e)
    {
    }
}
