var menuitem = null;
var menudisp = null;

  function myappear(obj, div) {
  	tohide=null;
    //obj.style.visibility='visible';
	if(obj!= null) {
		Effect.Appear(obj, {duration: 0.5} );
	}
	if (menudisp != obj && menudisp!= null) {
		Effect.Fade(menudisp, {duration: 0.5} );
	   if(menuitem!=null) {
			menuitem.style.backgroundColor='#ccc';
			menuitem.style.height=20;
			menuitem.style.marginTop=4;
			if (Prototype.Browser.IE) {
			   menuitem.style.paddingTop=0;
			}
			
	    }
	}
	menudisp = obj;	
    if (obj!=div) {
    	menuitem = div;
    }
    if (obj != null) {
	    if (menuitem!=null) {
	    menuitem.style.background='#bbb';
	    menuitem.style.height=30;
	    menuitem.style.marginTop=-5;
	    if (Prototype.Browser.IE) {
	       menuitem.style.paddingTop=4;
	    }
	    }
    }
  }
  
var tohide = null;

  function mydisappear(obj) {
  	tohide = obj;
  		
    }

	function dodisappear() {
		if (tohide != null) {
			Effect.Fade(tohide, {duration: 0.5} );
		   	if(menuitem!=null) {
				menuitem.style.backgroundColor='#ccc';
				menuitem.style.height=20;
				menuitem.style.marginTop=4;
				if (Prototype.Browser.IE) {
				     menuitem.style.paddingTop=0;
				}
		    }
		    tohide = null;
		}
	}
	
	function stillhere() {
		tohide = null;
	}
	
setInterval("dodisappear()",500);

if (!Prototype.Browser.IE) {
	setTimeout("hideQuote()",10000);
}

var quotes = new Array();

function hideQuote() {
//	alert("boo");
	var quotediv = document.getElementById('quote');
	Effect.Fade(quotediv);
	setTimeout("showQuote()",2000);
}

function showQuote() {
	var quotediv = document.getElementById('quote');
	var num = Math.round(Math.random()*(quotes.length-1));
	quotediv.innerHTML = quotes[num];
	Effect.Appear(quotediv);
	setTimeout("hideQuote()",10000);	
}

function showError() {
	var errordiv = document.getElementById('error');
	Effect.SlideDown(errordiv);
	setTimeout("hideError()",5000);	
}

function hideError() {
	var errordiv = document.getElementById('error');
	Effect.SlideUp(errordiv);
}


//play music
var currenttrack;

function playSong(name,mylink) {
	if (document.getElementById(mylink) != currenttrack) {
		Sound.play('audio/'+name+'.mp3', {replace:true});
		if (currenttrack != null) {
			currenttrack.innerHTML="<img src='images/play.gif' border='0' width='20px'>";
		}
		currenttrack = document.getElementById(mylink);
		currenttrack.innerHTML="<img src='images/progress.gif' border='0' width='16px'>";
	} else {
		Sound.play('',{replace:true});
		currenttrack.innerHTML="<img src='images/play.gif' border='0' width='20px'>";
		currenttrack = null;
	}
}

function addMusical() {
	musnum++;
	if (Prototype.Browser.IE) {
		var newPerf = "<hr><p><b>"+musnum+") Musical</b><br /><input type='text' class='required' id='performance"+musnum+"' name='performance[]' /></p>";
		newPerf+="<p><b>Date</b><br /><small>Format: dd/mm/yyyy</small><br /><input type='text' class='short required validate-date-au' id='date"+musnum+"' name='perfDate[]'  /></p>";
		newPerf+="<p><b>Approx. Audience Size</b></br ><input type='text' class='short required validate-digits' id='asize"+musnum+"' name='asize[]' /></p>"
		newPerf+="<p><b>Will recordings be made?</b><br /><input type='radio' checked name='recordings' style='width:50px;'/>Yes<input type='radio' name='recordings[]' style='width:50px;' />No</p>";
		document.getElementById('performancelist').innerHTML+=newPerf;	
		var newdiv= document.createTextNode(newPerf);
	//	alert(document.getElementById('performancelist').childNodes[1].nodeName);
	} else {
		var newdiv = document.getElementById('performancelist').childNodes[1].cloneNode(true);
		newdiv.setAttribute('id','mus'+musnum);
		newdiv.setAttribute('style','display:none');
		newdiv.setAttribute('class','row');
		newdiv.firstChild.childNodes[0].firstChild.nodeValue = musnum+') Musical';
		var newlink = document.createElement('div');
		newlink.setAttribute('style','float:right');
		newlink.innerHTML = "<a href='javascript:removeMusical("+musnum+")'>[remove]</a>";
		newdiv.firstChild.childNodes[0].appendChild(newlink);
		newdiv.firstChild.childNodes[2].setAttribute('id','performance'+musnum);
		newdiv.firstChild.childNodes[2].value = '';
		newdiv.childNodes[1].childNodes[2].setAttribute('id','date'+musnum);
		newdiv.childNodes[1].childNodes[2].value = '';
		newdiv.childNodes[2].childNodes[2].setAttribute('id','asize'+musnum);
		newdiv.childNodes[2].childNodes[2].value = '';
		newdiv.childNodes[3].childNodes[2].setAttribute('name','recordings['+musnum+'][]');
		newdiv.childNodes[3].childNodes[4].setAttribute('name','recordings['+musnum+'][]');
		newdiv.childNodes[3].childNodes[2].setAttribute('checked',true);
//	alert(newdiv.firstChild.childNodes[2].nodeName);
	document.getElementById('performancelist').appendChild(newdiv);
	}
	Effect.BlindDown('mus'+musnum);
	valid = new Validation('licenceform',{immediate:true,focusOnError:false});
}

function removeMusical(sender) {
//	alert(sender);
	Effect.BlindUp('mus'+sender);
	var musicals = document.getElementById('performancelist');
	var remove = document.getElementById('mus'+sender);
//	alert(remove);
//	musicals.removeChild(remove);
}

function showvenue() {
	Effect.BlindUp('venueshow');
	Effect.BlindDown('venue');	
}

function hidevenue() {
	Effect.BlindUp('venue');
	Effect.BlindDown('venueshow');	    
}
