// Function to monitor search box click off
// =================================================================================================
document.onclick=check;
function check(e){
	var target = (e && e.target) || (event && event.srcElement);
	var obj = document.getElementById('searchbox');
	var obj2 = document.getElementById('showsearchbox');
	var parent = checkParent(target);
	if(parent){obj.style.display='none'}
	if(target==obj2){
		obj.style.display='block';
		document.searchform.keyword.focus();
	}
}
function checkParent(t){
	while(t.parentNode){
		if(t==document.getElementById('searchbox')){
			return false
		}
		t=t.parentNode
	}
	return true
}

// Function to pop big picture window
// =================================================================================================
function popBigPic(fileName,show)
{
	var bigWindow = window.open('bigpic.asp?img='+fileName+'&show='+show,'bigPicWindow','width=520,height=520,titlebar=0,menubar=0,toolbar=0,location=0,scrollbars=0,status=0,dependent=1');
}


// Monitor for music player and music cookie...
// =================================================================================================
var musicWindow = null;
function checkMusic() {
	var x = readCookie("fcmusic");

	if (x == null || x == "play")
	{
		var url = "music.asp";
		musicWindow = open( '', 'musicWindow','width=100,height=25,titlebar=0,menubar=0,toolbar=0,location=0,scrollbars=0,status=0,dependent=1');
		if( !musicWindow || musicWindow.closed || !musicWindow.doSomething ) {
			musicWindow = window.open( url,'musicWindow','width=100,height=25,titlebar=0,menubar=0,toolbar=0,location=0,scrollbars=0,status=0,dependent=1');
		}
		createCookie('fcmusic','play',180);
	}
}

function doSomething() {
	 checkMusic();
	 musicWindow.doSomething();
}

// Function to start and stop music...
// =================================================================================================
function turnMusicOff()  {
	musicWindow.close();
	document.getElementById('musicbox').innerHTML = "<a href='' onclick='turnMusicOn(); return false;'>turn music on</a>";
	createCookie('fcmusic','stop',180);
}

function turnMusicOn()  {
	document.getElementById('musicbox').innerHTML = "<a href='' onclick='turnMusicOff(); return false;'>turn music off</a>";
	createCookie('fcmusic','play',180);
	checkMusic();
	return false;
}

// Function to show and hide search box...
// =================================================================================================
function showSearchBox()
{
	if (document.getElementById("searchbox").style.display != "block")
	{
		document.getElementById("searchbox").style.display = "block";
		document.searchform.keyword.focus();
		
	}
	else
	{
		document.getElementById("searchbox").style.display = "none";
	}
}

// Cookie Functions
// =================================================================================================
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);
}

