



//How deep is the website's base directory?
var baselevel = 2;

//How many characters are in the base url?
var baselevelchars = 50;

//Find the depth of the current page
function countInstances(string) {
  	var substrings = string.split("/");
  	var string_output = substrings.length - 3 - baselevel;
	var index_level = '';
	for (l = 0; l < string_output; l += 1)
	{
		index_level = index_level + '../';	
	}
	return index_level;
}

if (document.images)
{
  preload_image_object = new Image();
  // set image url
  image_url = new Array();
  image_url[0] = countInstances(location.href) + "/images/ui/resource-hover.gif";
  image_url[1] = countInstances(location.href) + "/images/ui/tabs-hover-bg.gif";
  image_url[2] = countInstances(location.href) + "/images/ui/sort-by-hover.gif";
  image_url[3] = countInstances(location.href) + "/images/ui/results-hover.gif";
  image_url[4] = countInstances(location.href) + "/images/ui/song-hover.gif";
   var i = 0;
   for(i=0; i<=3; i++) 
     preload_image_object.src = image_url[i];
}


//Include external Javascript files
function includeJavaScript(jsFile, index_level) {
  document.write('<script type="text/javascript" src="'
    + countInstances(location.href) + 'global/javascript/' + jsFile + '"></script>'); 
}

//Text To Image Replacement Array
//Syntax: node value | image name | width | height

replaceImages = new Array(
  );

function replacedom() {
  	if(document.getElementsByTagName && document.createElement){
		index_level = countInstances(location.href);
   	for (l=1;l<=replaceImages.length;l++){
     		targetElements = document.getElementsByTagName("*");
   		chunks=replaceImages[l-1].split(' | ');
   		for(f=0;f<targetElements.length;f++){
   			if(targetElements[f].firstChild) {
   				if(targetElements[f].firstChild.nodeValue==chunks[0]){
   	        		newimg = document.createElement('img');			
   	        		newimg.setAttribute('alt',chunks[0]);		
   					newimg.setAttribute('width',chunks[2]);		
   					newimg.setAttribute('height',chunks[3]);
   	        		newimg.setAttribute('src',index_level + 'images/ui/' + chunks[1]);
   					imgcover = document.createElement('img');
   					imgcover.setAttribute('alt',chunks[0]);		
   					imgcover.setAttribute('width',chunks[2]);		
   					imgcover.setAttribute('height',chunks[3]);
   					imgcover.setAttribute('style',
   											'position : relative; ' +
   											'top : 0px; ' +
   											'left : -' + chunks[2] + 'px; ');
   					imgcover.setAttribute('src',index_level + 'images/ui/blank.gif');
   					targetElements[f].replaceChild(newimg,targetElements[f].firstChild);
   					targetElements[f].appendChild(imgcover);
   					}
			    }
	      	}
		}
    }
}



function initialize() {
	replacedom();
	 	if(location.href.length > baselevelchars) {
	}
}



function albums_sort(direction) {
	if(direction == "asc") {
	document.getElementById('albums-sort-by').innerHTML="<dl><dt>Sort by:</dt><dd><a href=\"javascript:albums_date_sort('desc')\">Release Date&nbsp;<img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-down-greyed.gif\"></a></dd><dd><a href=\"javascript:albums_sort('desc')\">Album Title <img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-down.gif\"></a></dd></dl>";
	document.getElementById('albums-sort-asc').style.display='none';
	document.getElementById('albums-sort-desc').style.display='block';
	document.getElementById('albums-date-asc').style.display='none';
	document.getElementById('albums-date-desc').style.display='none';
	 } else {
		document.getElementById('albums-sort-by').innerHTML="<dl><dt>Sort by:</dt><dd><a href=\"javascript:albums_date_sort('desc')\">Release Date&nbsp;<img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-down-greyed.gif\"></a></dd><dd><a href=\"javascript:albums_sort('asc')\">Album Title <img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-up.gif\"></a></dd></dl>";
		document.getElementById('albums-sort-desc').style.display='none';
		document.getElementById('albums-sort-asc').style.display='block';
		document.getElementById('albums-date-asc').style.display='none';
		document.getElementById('albums-date-desc').style.display='none';
	}
}



function albums_date_sort(direction) {
	if(direction == "asc") {
	document.getElementById('albums-sort-by').innerHTML="<dl><dt>Sort by:</dt><dd><a href=\"javascript:albums_date_sort('desc')\">Release Date&nbsp;<img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-up.gif\"></a></dd><dd><a href=\"javascript:albums_sort('desc')\">Album Title <img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-down-greyed.gif\"></a></dd></dl>";
	document.getElementById('albums-sort-asc').style.display='none';
	document.getElementById('albums-sort-desc').style.display='none';
	document.getElementById('albums-date-asc').style.display='block';
	document.getElementById('albums-date-desc').style.display='none';
	 } else {
		document.getElementById('albums-sort-by').innerHTML="<dl><dt>Sort by:</dt><dd><a href=\"javascript:albums_date_sort('asc')\">Release Date&nbsp;<img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-down.gif\"></a></dd><dd><a href=\"javascript:albums_sort('asc')\">Album Title <img src=\"http://www.newattitude.org/sovereigngracemusic/images/ui/sort-down-greyed.gif\"></a></dd></dl>";
		document.getElementById('albums-sort-desc').style.display='none';
		document.getElementById('albums-sort-asc').style.display='none';
		document.getElementById('albums-date-asc').style.display='none';
		document.getElementById('albums-date-desc').style.display='block';
	}
}




function artists_sort(direction) {
	if(direction == "asc") {
		document.getElementById('artists-sort-by').innerHTML="<dl><dt>Sort by:</dt><dd><a href=\"javascript:artists_sort('desc');\">Name <img src=\"http://www.sovereigngracemusic.org/images/ui/sort-down.gif\"></a></dd></dl>";
		document.getElementById('artists-sort-desc').style.display='none';
		document.getElementById('artists-sort-asc').style.display='block';
	} else {
		document.getElementById('artists-sort-by').innerHTML="<dl><dt>Sort by:</dt><dd><a href=\"javascript:artists_sort('asc');\">Name <img src=\"http://www.sovereigngracemusic.org/images/ui/sort-up.gif\"></a></dd></dl>";		
		document.getElementById('artists-sort-asc').style.display='none';
		document.getElementById('artists-sort-desc').style.display='block';
	}
}


function change_song(songcount, newsong){
	for (i=1;i<=songcount;i++) {
	document.getElementById('song_'+i).className="empty";
	}
	document.getElementById('song_' + newsong).className="selected";
}


function popVideo(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=370');");
}





function OffWindowH()
{
	
 var OffWindowH=0;

 

 window.scrollTo(0,10000000);

 

 if(typeof self.pageYOffset!='undefined')

 OffWindowH=self.pageYOffset;

 else if(document.compatMode && document.compatMode != 'BackCompat')

OffWindowH=document.documentElement.scrollTop;

 else if(document.body && typeof(document.body.scrollTop)!='undefined')

OffWindowH=document.body.scrollTop;


 window.scrollTo(0,0);

 

 return OffWindowH;

}

 

function WindowHeight()

{

  var WindowHeight = 0;

  if( typeof( window.innerWidth ) == 'number' )

  WindowHeight = window.innerHeight;

  else if (document.documentElement &&  document.documentElement.clientHeight)

  WindowHeight = document.documentElement.clientHeight;

  else if(document.body && document.body.clientHeight)

  WindowHeight = document.body.clientHeight;

 

  return WindowHeight;

}

 

function pHeight()

{

  var pHeight = OffWindowH() + WindowHeight();

  return pHeight;

}

 

function favBg()

{

  var favBg = document.getElementById('favBg');

  favBg.style.height = pHeight() + 'px';
  favBg.style.display = "block";

}


function closeVideo() {
	document.getElementById("favArea").innerHTML = "";
	document.getElementById("favArea").style.display = "none";
	document.getElementById("audioFrame").style.display = "block";
	document.getElementById('favBg').style.display = "none";
}
 

var cdiv = "blank";

function posFrame() {
  if (cdiv == "blank") { cdiv = window.setInterval("posFrame()", 50); }
 var Element = document.getElementById("favArea");
 objh = parseFloat(Element.style.height)/2;
 objw = parseFloat(Element.style.width)/2;
 Element.style.top = Math.floor(Math.round((document.documentElement.offsetHeight/2)+document.documentElement.scrollTop)-objh)+'px';
 Element.style.left = Math.floor(Math.round((document.documentElement.offsetWidth/2)+document.documentElement.scrollLeft)-objw)+'px';
}

function popFrame(title, source, poster, ref ) {
posFrame();	
if (source.search(/vimeo/i) > 0) {
document.getElementById("audioFrame").style.display="none";
document.getElementById('favArea').style.display = "block";
document.getElementById('favArea').style.width = "640px";
document.getElementById('favArea').style.height = "510px";
newsource = source.replace("http://vimeo.com/", "")
posFrame();
document.getElementById("favArea").innerHTML = "<object width=\"640\" height=\"480\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=" + newsource + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=" + newsource + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"640\" height=\"480\"></embed></object><a href=\"javascript:closeVideo();\" style=\"float : left; font-family : arial; font-size : 11px; color : #fff; margin-top : 14px; padding-left : 2px;\">Close</a>";
} else {
document.getElementById("audioFrame").style.display="none";
document.getElementById('favArea').style.display = "block";
posFrame();
document.getElementById("favArea").innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"360\" height=\"290\" id=\"sgm_video\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"allowFullScreen\" value=\"false\" /><param name=\"FlashVars\" value=\"titlevar=" + title + "&videosource=http://sgm.edgeboss.net/download/sgm/musicvideo/" + source + "&poster=" + poster + "\" /><param name=\"movie\" value=\"http://www.sovereigngracemusic.org/flash/sgm_video.swf\" /><param name=\"menu\" value=\"false\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" />	<embed src=\"http://www.sovereigngracemusic.org/flash/sgm_video.swf\" menu=\"false\" quality=\"high\" bgcolor=\"#ffffff\" width=\"360\" height=\"290\" FlashVars=\"titlevar=" + title + "&videosource=http://sgm.edgeboss.net/download/sgm/musicvideo/" + source + "&poster=" + poster + "\" name=\"sgm_video\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object><a href=\"javascript:closeVideo();\" style=\"float : left; font-family : arial; font-size : 11px; color : #fff; margin-top : 14px; padding-left : 2px;\">Close</a><a  style=\"float : right; font-family : arial; font-size : 11px; color : #fff; margin-top : 14px; padding-left : 2px;\" href=\"http://www.sovereigngracemusic.org/send-video/?title="  + title + "&source=" + source + "&poster=" + poster + "&ref=" + ref + "\">"+ source + "Send to a friend</a>";
}
}