// JavaScript Document
// Copyright 2008 by Bruen Media Group
// 970-593-6300
// www.bruen.com
// Written By Justin Bruen

window.onload = loadFunc;// Things that happen after "Onload"
var movieName = "assistant";// This is taken from the hard coded flash <object> ID or <embed> NAME
var divName = "assistantDIV";//associates assistant div container id with a variable that will 
var newMoviePath="makeHome.flv";//Default video
var flashCapable="false";// This will change to true if Flash checks in via flashActive() javascript callback
var action_param = gup( 'action' );// Find value of querry string name and assign to variable using gup function - used to ForcePlay video
var flashTimeout;//used to see if Flash is enabled after page loads for specified time.

function bruen_writeswf() {
document.write('<div id="assistantDIV">');
document.write('<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" WIDTH="400" HEIGHT="300" ID="assistant">');
document.write('<PARAM NAME="MOVIE" VALUE="media/assistant.swf" />');
document.write('<PARAM NAME="PLAY" VALUE="true" />');
document.write('<PARAM NAME="LOOP" VALUE="false" />');
document.write('<PARAM NAME="QUALITY" VALUE="high" />');
document.write('<PARAM NAME="SCALE" VALUE="SHOWALL" />');
document.write('<PARAM NAME="ALLOWSCRIPTACCES" VALUE="ALWAYS" />');
document.write('<PARAM NAME="FLASHVARS" VALUE="" />');
document.write('<PARAM NAME="WMODE" VALUE="transparent" />');
document.write('<EMBED SRC="media/assistant.swf" WIDTH="400" HEIGHT="300" LOOP="false" PLAY="true" QUALITY="high" SCALE="SHOWALL" swLiveConnect="true" allowScriptAccess="always" wmode="transparent" FlashVars="" NAME="assistant" PLUGINSPAGE="http://www.macromedia.com/go/flashplayer/">');
document.write('</EMBED>');
document.write('</OBJECT>');
document.write('</div>');
}

function flashActive() {//This function is triggered by Flash External Interface call and lets javascript know that flash is available
	flashCapable="true";
	clearTimeout(flashTimeout);
	cookieCheck();
	//createCookie('playintro','skip',30);
}

// parse the querry string and find the value of a specific name=value pair
// This most elegant function was copied from http://www.netlobo.com/url_query_string_javascript.html
// Wish I understood it better! Very handy!
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function SendStartDataToFlashMovie()
{
var flashMovie=getFlashMovieObject(movieName);
flashMovie.SetVariable("moviePath",newMoviePath);
flashMovie.SetVariable("playMovie",1);
}

function SendStopDataToFlashMovie()
{
var flashMovie=getFlashMovieObject(movieName);
flashMovie.SetVariable("playMovie",0);
}

function toggleDivOn(){
checkFlash();
if (flashCapable == "true"){
	SendStartDataToFlashMovie();
	document.poppedLayer = eval('document.getElementById(divName)');
	document.poppedLayer.style.left = "0px";
	}
}

function toggleDivOff(){
SendStopDataToFlashMovie();
document.poppedLayer = eval('document.getElementById(divName)');
document.poppedLayer.style.left = "-399px";
}

function dealHunter()
{
newMoviePath="dealHunter.flv";	
toggleDivOn();
}

function expertGuides()
{
newMoviePath="expertGuides.flv";
toggleDivOn();
}

function groups()
{
newMoviePath="groups.flv";
toggleDivOn();
}

function joinDirectory()
{
newMoviePath="joinDirectory.flv";
toggleDivOn();
}

function makeHome()
{
newMoviePath="makeHome.flv";
toggleDivOn();
}

function newsAlerts()
{
newMoviePath="newsAlerts.flv";
toggleDivOn();
}

function todayIn()
{
newMoviePath="todayIn.flv";
toggleDivOn();
}

function lunchDinner()
{
newMoviePath="lunchDinner.flv";
toggleDivOn();
}

function createCookie(name,value,days) {
if (days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

function cookieCheck(){
var x = readCookie('playintro');
if (action_param){
	newMoviePath=action_param +".flv";
	toggleDivOn();
	}
	else
	{
	if (x) 
		{
		}
		else
		{
		//makeHome();
		}
	}
}

function loadFunc(){
flashTimeout = setTimeout ("introCheck()",5000);//Check to see if flash is available for force plays and notify user if No Flash
}

function introCheck(){
if (action_param){checkFlash();}
}

function checkFlash(){
if(flashCapable=="false"){
	if (confirm('Content on this page requires Macromedia Flash Player 8 or later. Your browser plug-ins may need to be turned on or your Flash plug-in updated. Do you want to download it now?'))
    {window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";}
	}
}
