function hover(box) {
	document.getElementById('box'+box).className = 'menuHover';
}
function hoverOut(box) {
	document.getElementById('box'+box).className = 'menuOption';
}
function pagehover(box) {
	document.getElementById('page'+box).className = 'textLinkHvr';
}
function pagehoverOut(box) {
	document.getElementById('page'+box).className = 'textLink';
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
function enter() {
	var check = alert("You entered an incorrect username / password.");
}
function myAlert(message) {
	alert(message);
}

var http = getHTTPObject();
function getHTTPObject(){
  var xmlHttp=null;
  try{ xmlHttp=new XMLHttpRequest(); }
  catch(err){
    try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(err){
    }
  } return xmlHttp;
}

function Search(){
  var searchWords = document.getElementById('searchBar').value;
  var url="ajax_search.php?searchWords="+searchWords;
  var myRandom=parseInt(Math.random()*99999999);
  http.abort();
  http.open("GET", url+'&rand='+myRandom, true);
  http.onreadystatechange=ajaxReceive;
  http.send(null);
  http.close;
}

function ajaxReceive(){
  if(http.readyState==4){
	  var returncode = http.responseText;
      document.getElementById('contacts').innerHTML = returncode;
  }
}
function add_note() {
	$(document).ready(function(){

	  $("#Addnote").animate({opacity: "0.1", width: "807"}, "slow")
	  .animate({opacity: "1", height: "140"}, "slow")
	  return false;

});
};
function shrink_note() {
	$(document).ready(function(){

	  $("#Addnote").animate({opacity: "1", height: "30"}, "slow")
	  .animate({opacity: "1", width: "120"}, "slow")
	  return false;

});
};
function scrollDown() {
	for (i=0;i<window.screen.availHeight;i+=10) {window.scroll(0,i); }
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
 
function showPlayer(id){  
  arsmusic = window.open ('test_pop.php?id='+id, 'arsmusic', config='height=383, width=497, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}
 
function gopage(id){
  if(!readCookie('arsmusicpopup')){
    showPlayer(id);
  } else {
	  var oldWin = window.open("test_pop.php?id="+id,"arsmusic");
	  oldWin.focus();
  }

}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function slideShow(speed) {
	//append a LI item to the UL list for displaying caption
	$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.slideshow li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.slideshow li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
	$('#slideshow-caption p').html($('ul.slideshow a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#slideshow-caption').css({opacity: 0.8, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	//pause the slideshow on mouse over
	//$('ul.slideshow').hover(
		//function () {
			//clearInterval(timer);	
		//}, 	
		//function () {
			//timer = setInterval('gallery()',speed);			
		//}
	//);
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	

	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	$('#slideshow-caption').slideToggle(300, function () { 
		$('#slideshow-caption h3').html(title); 
		$('#slideshow-caption p').html(desc); 
		$('#slideshow-caption').slideToggle(500); 
	});		

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}
