document.observe('dom:loaded', function() {
	init_page();
});

var store_highlightstart = "#A4A4A4";
var store_highlightend = "#FFFFFF";
var ajaxreloadsite = 1;

butt1on = new Image();
butt1on.src = "/images/homep.gif";
butt2on = new Image();
butt2on.src = "/images/presskitp.gif";
butt3on = new Image();
butt3on.src = "/images/musicp.gif";
butt4on = new Image();
butt4on.src = "/images/mediap.gif";
butt5on = new Image();
butt5on.src = "/images/onlinelessonsp.gif";
butt6on = new Image();
butt6on.src = "/images/ordermusicp.gif";
butt7on = new Image();
butt7on.src = "/images/contactnickp.gif";

butt1off = new Image();
butt1off.src = "/images/home.gif";
butt2off = new Image();
butt2off.src = "/images/presskit.gif";
butt3off = new Image();
butt3off.src = "/images/music.gif";
butt4off = new Image();
butt4off.src = "/images/media.gif";
butt5off = new Image();
butt5off.src = "/images/onlinelessons.gif";
butt6off = new Image();
butt6off.src = "/images/ordermusic.gif";
butt7off = new Image();
butt7off.src = "/images/contactnick.gif";

function bbimg_act(imgName) {
	imgOn = eval(imgName + "on.src");
	document.images[imgName].src = imgOn;
}

function bbimg_inact(imgName) {
	imgOff = eval(imgName + "off.src");
	document.images[imgName].src = imgOff;
}

// Create the Divtag Handler
var divhandler = new handleDivTag(null); 

function handleDivTag(divtag) {
	var divtag;
	return divtag;
}

function handleResponse_nav () {   
	if(http.readyState == 4 && http.status == 200) { 


		// Text returned FROM the PHP script 
		var response = http.responseText; 
		if(response) { 
			try {
				document.getElementById(divhandler.divtag).innerHTML = response;
			}
			catch (e) {
				// IE fails unless we wrap the string in another element.
				document.getElementById(divhandler.divtag).innerHTML = '';
				var wrappingDiv = document.createElement('div');
				wrappingDiv.innerHTML = response;
				document.getElementById(divhandler.divtag).appendChild(wrappingDiv);
			}
			ajax_regex(response,divhandler.divtag);
			//	location.href = '#page_content';
		} 
	} 
}

function poll (ID) {
	if (document.getElementById(id)) {
		init_page(); 
		return;
	}
	else if (!document.getElementById(id))
	setTimeout("poll('"+ID+"')", 60);
}

function mediaplayer_js(songID) {
	if (songID) {		self.frames['mediaplayer'].location.href='nm_webkit/templates/mediaplayer.php?width=400&height=40&downloadbutton=1&medialoader=1&firstload=0&songID=' + songID;
}
}

/*
function ajax_regex (htmlcontent,divtag) {
	var swap_exp = /href(\s)*?=(\s)*?"([^"]+)"/im;
	var search_page = htmlcontent;
	var swap;
	var swap_check;
	var ajax_page;
	var swap_found = new Array();

	while (swap_check !== -1) {
		swap_check = search_page.search(swap_exp);
		if (swap_check == -1) {
			// exit loop if no more links found
			break;
		}
		swap = swap_exp.exec(search_page);
		if (swap[3].substring(0,7) !== "http://" && swap[3].substring(0,8) !== "https://" && swap[3].substring(0,11) !== "javascript:") {
			// delete leading slash from URL, if necessary
			if (swap[3].substring(0,1) == "/") {
				ajax_page = swap[3].substring(1);
			}
			else {
				ajax_page = swap[3];
			}
			if (ajax_page) {
				htmlcontent = htmlcontent.replace(swap[0], "href=\"javascript:ajax('" + ajax_page + "')\"");
			}
			// delete from search string
			search_page = search_page.replace(swap[0], "");
		}
		else {
			// external or AJAX link already processed, delete from search
			search_page = search_page.replace(swap[0], "");
		}
		document.getElementById(divtag).innerHTML = htmlcontent;
	}
}
*/

function init_page() {
	initAjaxLinks('button_bar');
	initAjaxLinks('pagecontent');
}



function checkrequired(which) {
	var pass=true;
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,8)=="required") {
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					pass=false;
					break;
				}
			}
		}
	}
	if (!pass) {
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		alert("There are missing fields in this form. Please make sure that all required fields are properly completed.");
		return false;
	}
	else
	return true;
}

function clearfield() {
	if (document.contact.requiredcontent.value == 'enter the content of your email message here') {
		document.contact.requiredcontent.value = '';
	}
}

function play_movie(song) {
	document.getElementById(song).innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="640" height="495"><param name="src" value="/' + song + '.mp4" /><param name="target" value="myself" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="plugin" value="quicktimeplugin" /><param name="type" value="video/quicktime" /><embed src="/' + song + '.mp4" width="640" height="495" controller="true" target = "myself" pluginspage="http://www.apple.com/quicktime/download/" autoplay="true" plugin="quicktimeplugin" type="video/quicktime"></embed></object>';
}