function prepareGallery(){
	var gallery = document.getElementById("imageGallery");
	if(gallery){
		var links = gallery.getElementsByTagName("a");
		for( i=0; i<links.length; i++){
			links[i].onclick = function(){
				showpic(this,this.id);
				return false;
			}
		}
	}
}

function showpic(whichPic,id) {
	var source = whichPic.getAttribute("href");
	var placeholder = document.getElementById("placeholder");
	var old = placeholder.getAttribute("src",source); 
	placeholder.setAttribute("src",source);
	var text = whichPic.getAttribute("title");
	photo_nav(id,old);
}

function photo_nav(id,pic){
	var navigation = document.getElementById("imageGallery");
	var newID = $("span").attr("id");
	$("span.nonlink").replaceWith("<a id='"+newID+"' href='"+pic+"'>"+newID+"</a>");
	$("a").remove("#"+id);
	$("#"+id).replaceWith("<li id="+id+"><span class='nonlink' id='"+id+"''>"+id+"</span></li>");
	prepareGallery();
}

jQuery.preloadImages = function(){
  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function prepareTabs()
{
	var tabs = document.getElementById("tabs");
	var links = tabs.getElementsByTagName("a");
	for( i=0; i<links.length; i++)
	{
		links[i].onclick = function() 
		{
			var oldTab = $("span.nonlink").attr("title");
			var oldText = $("span.nonlink").text();
			var newTab = $("#"+this.id).attr("title");
			var newText = $("#"+this.id).text();
			showTab(this.id,oldTab,oldText,newTab,newText);
			toggleTabs(newTab,oldTab);
		}
	}
}


function setTab(val,type){
	if(val == 'Ghostly'){return false;} 
	if(val == 'Spectral'){
		id = 't2';
		if(type == 'artist'){
			newText = 'Spectral Artists';
		} else if(type == 'release'){
			newText = 'Spectral Sound (SPC)';
		}
	}
	if(val == 'GIDG'){
		id = 't3';
		if(type == 'release'){
			newText = 'Ghostly Digital (GIDG)';
		}
	}
	
 	var oldTab = $("span.nonlink").attr("title");
	var oldText = $("span.nonlink").text();
	var newTab = val;
 	showTab(id,oldTab,oldText,newTab,newText);
 	toggleTabs(newTab,oldTab);
}

function showTab(id,oldTab,oldText,newTab,newText){
		var navigation = document.getElementById("tabs");
		var newID = $("span.nonlink").attr("id");
		$("span.nonlink").replaceWith("<a id='"+newID+"' href='#"+oldTab+"' class='tab' title='"+oldTab+"'>"+oldText+"</a>");
		$("a#"+id).replaceWith("<span class='nonlink' id='"+id+"' title='"+newTab+"'>"+newText+"</span>");
		prepareTabs();
}

function toggleTabs(newTab,oldTab)
{
	$("."+oldTab).toggleClass("hide");
	switch (newTab){
		case "Ghostly":
			$("#gi").toggleClass("hide");
		break;
		case "Spectral":
			$("#spc").toggleClass("hide");
		break;
		case "GIDG":
			$("#gdg").toggleClass("hide");
		break;
	}
}

function show_more(val,type)
{
	$('.'+type).toggleClass('hide');
	var str = val.split('-');
	(str[0] == 'more') ? newType = 'less' : newType = 'more';
	$("#"+val).replaceWith("<a id=\""+newType+"-"+type+"\" class=\""+newType+"\" href=\"#\" onclick=\"show_more('"+newType+"-"+type+"','"+type+"'); return false;\">"+newType+"</a>");
}

function popitup(url) 
{
	newwindow=window.open(url,'name','height=325,width=510');
	if (window.focus) {newwindow.focus()}
	return false;
}

function submitForm(id){$("#"+id).submit();}
function closeWindow(){window.close();}
function to_old_win(url){opener.location.href = url;}//opener.opener = top; // or whatever, as long as opener.opener has a value;//closeWindow();}