// JavaScript Document

var minHeight = 0;
var currentHash = "";
var oldHash = "";
var movieID = "";

function writeFlash (src, width, height, id, flashVars, isTransparent)
{
	movieID = id;
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '" id="' + id + '">');
	document.write('<param name="movie" value="' + src + '"/>');
	document.write('<param name="quality" value="high"/>');
	if (isTransparent == true)
	{
		document.write('<param name="wmode" value="transparent"/>');
	}
	document.write('<param name="FlashVars" value="' + flashVars + '"/>');
	document.write('<param name = "allowScriptAccess" value = "always" />');
	document.write('<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" name="' + id + '" FlashVars="' +  flashVars + '" ');
	if (isTransparent == true)
	{
		document.write('wmode="transparent"');
	}
	document.write('></embed>');
	document.write('</object>');
}

function changePage(theHeight, theHash, theTitle)
{
	setHeight(theHeight);
	setHash(theHash);
	setTitle(theTitle);
	scrollToPos(0);
}

function getHeight() 
{
	var theHeight = 0;
	if (typeof(window.innerWidth) == 'number' )
	{
    	// Non-IE
    	theHeight = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		// IE 6+ in 'standards compliant mode'
		theHeight = document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientHeight)
	{
		// IE 4 compatible
		theHeight = document.body.clientHeight;
	}
	return theHeight;
}

function setHeight(theHeight)
{
	//alert(theHeight);
	minHeight = theHeight;
	var windowHeight = getHeight();

	if (theHeight < windowHeight)
	{
		document.getElementById("flashContainer").style.height = windowHeight + "px";
	}
	else
	{
		document.getElementById("flashContainer").style.height = theHeight + "px";
	}
	
	window.scrollBy(0, 1);
	window.scrollBy(0, -1);
	
	/*
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
		var ffversion=new Number(RegExp.$1);
		if (ffversion < 3)
		{
			window.scrollBy(0, 1);
			window.scrollBy(0, -1);
		}
	}
	*/
}

function setTitle(theTitle)
{
	if (theTitle != "" && theTitle != undefined && theTitle != null && theTitle != "null")
	{
		document.title = "Blacklight New Media - " + theTitle;
	}
	else
	{
		document.title = "Blacklight New Media";
	}
}

function getHash()
{
	var theHash = "";
	theHash = window.location.hash;
	return theHash;
}

function setHash(theHash)
{
	//if (!(theHash == "home/" && oldHash == ""))
	if (theHash != "home/")
	{
		document.getElementById("anchor").innerHTML = "<p name='/" + theHash + "' id='/" + theHash + "'> </p>";
		window.location.hash = "#/" + theHash;
		currentHash = "#/" + theHash;
		oldHash = currentHash;
	}
	else if (oldHash != "")
	{
		document.getElementById("anchor").innerHTML = "<p name='/' id='/'> </p>";
		window.location.hash = "#/";
		currentHash = "#/";
		oldHash = currentHash;
	}
}

function checkHash()
{
	if (navigator.appName.indexOf("Microsoft") != -1) 
	{
	 // alert('window.location.hash = ' + window.location.hash + '; oldHash = ' + oldHash);
	 // alert('document.getElementById("anchor").innerHTML' + document.getElementById("anchor").innerHTML);
	}
	
	if (window.location.hash != oldHash)
	{
		//alert('hash change');
		//alert("current hash = " + window.location.hash + "; oldHash = " + oldHash);
		//window.location.reload();
		onHashChange();
	}
}

function onHashChange() 
{
    thisMovie(movieID).onHashChange(window.location.hash);
}

function thisMovie(movieName) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
	{
		// IE
        return window[movieName];
    }
    else 
	{
		// Not IE
        return document[movieName];
    }
}

function windowOrDocument()
{
	if (navigator.appName.indexOf("Microsoft") != -1) 
	{
        return window;
    }
    else 
	{
        return document;
    }
}

function resize()
{
	//alert("resize called");
	setHeight(minHeight);
}

function scrollToPos(yPos)
{
	window.scrollTo(0, yPos);
}

setInterval("checkHash()", 100);
