function changeClass(obj) {
	$(window.top.document).find("li").removeClass("selected");
	$(window.top.document).find("#"+obj).addClass("selected");
}

function getvar( 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 setViewer(hash,maintitle,title){
	var blah = hash.split(".");
	changeClass(blah[0]);
	var v = window.top.document.getElementById("viewer");

	//v.src=hash;
	v.contentWindow.location.replace(hash);
	
//	var newurl = location.href.replace(/^(.*)#.+/,"$1#"+hash);
	//alert(newurl);

//var nu = location.href.replace(/.*/,"http:/www.google.com");

	//location.replace(newurl);
	if (window.defaultPage != hash)
		location.hash=hash;
	//alert(hash);
	
	window.currentURL = location.href;
	//window.currentURL = newurl;

	if (maintitle!==undefined)
	{	
		if (title!==undefined && title!="" && title!=" ")
			document.title = maintitle + " -- " + title;
		else
			document.title = maintitle;
	}
}

function startup(){

	// Fix alpha PNG
	//$(document).ready(function () {
    	//$('img#dropshadow').supersleight();
	//});
	
	// Set the viewer based on the #
	if (location.hash != ""){
		var q = location.hash.substring(1);
		setViewer(q);
	}
	else if (window.defaultPage)
	{	//alert("default: ["+window.defaultPage+"]");
		setViewer(window.defaultPage,window.defaultTitle,window.defaultSubtitle);
	}
	else
	{	//alert("no default: "+location.href);
		//return;
	}
	
	window.currentURL = location.href;
	urlInterval = setInterval(checkURL, 500);
}

function showAll(){
	$("li").fadeIn("100");
	$("#categorySelector td").removeClass("selected");
	var eugh = "#categorySelector .AllSelector";
	$(eugh).addClass("selected");
}

function hideAllBut(theClass){
	scrollTo(document.getElementById('slider'),0);
	$("#menuitems li").fadeOut("10");
	$("#menuitems li."+theClass).animate({foo: 1}, 400).fadeIn("10");
	
	$("#categorySelector td").removeClass("selected");
	var eugh = "#categorySelector ."+theClass+"Selector";
	$(eugh).addClass("selected");
}

function checkURL(){
	if (window.currentURL != location.href){
		window.currentURL = location.href;
		//alert("check!");
		
		var hash = '';
		if (location.hash != "")
			hash = location.hash.substring(1);
		else
			hash = window.defaultPage;
		
		setViewer(hash);
	}
}
