function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function preloadMenuImages()
{
  var menuImgs=["about-wmi.png","about-wmi_f2.png","buy-music.png","buy-music_f2.png","buy-tickets.png","buy-tickets_f2.png","donate.png","donate_f2.png","home.png","home_f2.png","join-wmi.png","join-wmi_f2.png","links.png","links_f2.png","press-media.png","press-media_f2.png","search.png","search_f2.png","staff-contact.png","staff-contact_f2.png","venues.png","venues_f2.png","wmi-concerts.png","wmi-concerts_f2.png","wmi-tours.png","wmi-tours_f2.png"];
  if(document.images)
  {
    document.menuImageArray = new Array();
    for(var i=0; i<menuImgs.length; i++)
    {
		var img = new Image;
		img.src = "images/menu/" + menuImgs[i];
		document.menuImageArray[i];
    }
  }
}



function switchImage(imgName, imgSrc) 
{
	if (imgSrc != "none" && imgSrc != null)
	{
		if(typeof(imgName)=="string") findObj(imgName).src = imgSrc;
		if(typeof(imgName)=="object") imgName.src = imgSrc;
	}
	
}

function myOver(obj)
{
	var src=obj.src.substring(obj.src.lastIndexOf("/"),obj.src.length);
	if(!obj.overSrc)
	{
		obj.oriSrc=obj.src;
		var srcArr=src.split(".");
		srcArr[0]+="_f2";
		obj.overSrc=obj.src.substring(0, obj.src.lastIndexOf("/")) + srcArr.join(".");
	}
	obj.src=obj.overSrc;
}

function myOut(obj)
{
	obj.src=obj.oriSrc;
}

function getLinks(obj)
{
//	var obj=findObj(objId);
	return obj.getElementsByTagName("a");
}

function getListItems(objId)
{
	var obj=findObj(objId);
	return obj.getElementsByTagName("li");
}

function replaceLinksWithImages()
{
	var aArr=getListItems("menu");
	document.menuImages=new Array();
	document.loadedImages=0;
	for(var i=0;i<aArr.length;i++)
	{
		var tag=aArr[i];
		var aTag=getLinks(tag)[0];
		var text=aTag.innerHTML;
		var theLink=aTag.href;
		var src;
		if(tag.className!="current")
		{
			src="images/menu/" + text.replace(/(\s)|(\/)/g, "-") + ".png";
			var img=new Image();
			img.onload=function()
			{
				document.loadedImages++
				if(document.loadedImages>=document.menuImages.length)
				{
					var menu=findObj("menu");
					menu.style.visibility="visible";
				}
			};
			img.src=src;
			document.menuImages.push(img);
			tag.innerHTML='<a href="'+theLink+'" target="' + aTag.target + '"><img src="'+src+'" onmouseover="myOver(this)" onmouseout="myOut(this)" alt="'+text+'" /></a>';
		}
		else
		{
			src="images/menu/" + text.replace(/(\s)|(\/)/g, "-") + "_f2.png";
			tag.innerHTML='<img src="'+src+'" alt="'+text+'" />';
		}
	}
}

function writeFlashHeader(src,xmlSrc)
{
	if(xmlSrc == null || xmlSrc == '') xmlSrc = 'xml/homeDisplayImages.xml';
   	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 12;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
   xmlSrc+="?"+randomstring;
   var flashHeader = new SWFObject(src, "flashHeader", "100%", "100%", "8", "#000000");//"#F3F9F3");
   flashHeader.addVariable("xmlSrc", xmlSrc);
   flashHeader.addParam("quality", "hight");
   flashHeader.addParam("wmode", "transparent");
   flashHeader.addParam("scalemode", "noscale");
   flashHeader.addParam("menu", "false");
   flashHeader.write("mainDisplay");
   var mainDisplay = findObj('mainDisplay');
   mainDisplay.style.visibility="visible";
}

function gotoHome()
{
	document.location.href="./";
}

function openVideoPlayer(id)
{
	var vp=window.open("videoPlayer.html?id="+id,"vp","width=320,height=288");
	vp.moveTo(((Screen.availWidth/2)-160),((Screen.availHeight/2)-144));
}

function playSong(src)
{
	var flashHeader=findObj('flashHeader');
	flashHeader.playExternalSound(src);
}

function writeMusicPlayer(id,src)
{
	document.writeln('<span id="'+id+'">testing here if this is going to be shown</span>&nbsp;');
  	var so = new SWFObject("media/musicPlayer.swf", id + "_mp", "50", "15", "8", "#F3F9F3");
  	so.addVariable("soundSrc", src);
  	so.write(id);
}