//window.onload = initPage;


function initPage()
{
    initPops();
    doTableColoring();
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (var i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



/** note this puts roll over on image, not href **/
function initPops()
{
    //if we don't support getElementById then exit
	if (!document.getElementById) return
	
    //grab all img pop divs
    var img_divs = getElementsByClass("imginline",document,'div');

	var s = '';
	
	var div_ref = null;
	var cap_ref = null
	var a_ref   = null;
	var i_ref   = null;
	
    //loop over images
	for (var i = 0; i < img_divs.length; i++)
	{
		//s += imgdivs[i].className + "\n";
		
	    //point to reference
	    div_ref = img_divs[i];
	    
	    //grab href link
	    a_ref = div_ref.getElementsByTagName("a");
	    i_ref = div_ref.getElementsByTagName("img");
	    
	    if (!a_ref || !i_ref) return;
	    
	    
	    s = 'pop.html?i=' + a_ref[0].href + '&a=' +  i_ref[0].getAttribute('alt');
	    //a_ref[0].href = "#";
	    a_ref[0].setAttribute('hsrc', s);
	    a_ref[0].setAttribute('title', i_ref[0].getAttribute('alt'));	    
	    
		//on mouseover grab hsrc
		
		if(div_ref.className.match('horiz-image_s3'))
		{
			a_ref[0].onclick = function()
			{
				pop_hori_s3(this); return false;
			}
		}
		else if(div_ref.className.match('horiz-image'))
		{
			a_ref[0].onclick = function()
			{
				pop_hori(this); return false;
				//window.open(this.href, 'horiz', 'width=337,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
			}
		}
		else if(div_ref.className.match('vert-image_s3'))
		{
			a_ref[0].onclick = function()
			{
				pop_vert_s3(this); return false;
			}
		}
		else 
		{
			a_ref[0].onclick = function()
			{
				pop_vert(this); return false;
				//window.open(this.href, 'horiz', 'width=337,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
			}		
		}

            
	    //s += i_ref[0].getAttribute('alt') + "\n";
	}
	
}


function pop_vert(a_href)
{
	//alert("woogoo");
	var htmlLink = a_href.getAttribute('hsrc')
	//window.open(htmlLink, 'target="image_v"', 'width=337,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
	window.open(htmlLink, 'image_v', 'width=337,height=400,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
}

function pop_hori(a_href)
{
	//alert("woogoo");
	var htmlLink = a_href.getAttribute('hsrc')
	window.open(htmlLink, 'image_h', 'width=421,height=316,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
}



function pop_vert_s3(a_href)
{
	var htmlLink = a_href.getAttribute('hsrc')
	window.open(htmlLink, 'image_v', 'width=322,height=410,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
}

function pop_hori_s3(a_href)
{
	var htmlLink = a_href.getAttribute('hsrc')
	window.open(htmlLink, 'image_h', 'width=405,height=278,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1'); return false;
}



function doTableColoring()
{

	if (!document.getElementsByTagName) return;
	
	var tables = getElementsByClass("music-table",document,'table');
	
	for (var i=0; i < tables.length; i++) 
	{
		var thisTable = tables[i]
		stripe(thisTable);
	}
		
}
var stripe = function(table) {
	
		var tbodies = table.getElementsByTagName("tbody");
		 
		for (var h = 0; h < tbodies.length; h++) {
			var even = true;
			
			var trs = tbodies[h].getElementsByTagName("tr");
			
			for (var i = 0; i < trs.length; i++) {
				/**trs[i].onmouseover=function(){
					this.className += " ruled"; return false
				}
				trs[i].onmouseout=function(){
					this.className = this.className.replace("ruled", ""); return false
				}**/
				if(trs[i].className.match('tr_head'))
				{
					//skip it
					even = false;
				}
				else
				{
	
					if(trs[i].className == "t-sub-sec") {even = true;} 
					else {
					if(even)
						trs[i].className += " even";
					
					even = !even;
					}
				}
			}
		}

}




/** NOTHING OF INTEREST BEYOND HERE **/


function init() {
       // quit if this function has already been called
       if (arguments.callee.done) return;

       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;

       // create the "page loaded" message
       //var text = document.createTextNode("Page loaded!");
       //var message = document.getElementById("message");
       //message.appendChild(text);
       initPage();
   };

   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, null);
   }

   /* for Internet Explorer */
   /*@cc_on @*/
   /*@if (@_win32)
   /* document.write("<script defer src=ie_onload.js><"+"/script>"); */
   /*@end @*/

   /* for other browsers */
   window.onload = init;