
document.observe('dom:loaded', function() {
		
	// youtube
	ytVideoApp.listVideos('search_all', 'SHIROCKmusic', 1);

	// home page popups
	$('ajax_bio').observe('click', showBio);
	$('ajax_equipment').observe('click', showEquipment);
	$('ajax_legal').observe('click', showLegal);
	$('ajax_media').observe('click', showMedia);
	$('ajax_radio').observe('click', showRadio);
	$('icons_eb').observe('click', showEB);
	$('icons_sr').observe('click', showSr);
	$('icons_ir').observe('click', showIr);
	$$('.ajax_email')[0].observe('click', showEmail);
	$$('.ajax_email')[1].observe('click', showEmail);
	$$('.ajax_contact')[0].observe('click', showContact);
	$$('.ajax_contact')[1].observe('click', showContact);

	// discography
	var track = document.getElementsByClassName('track');
	for (var i = 0; i < track.length; i++) {
		$(track[i].id).onclick = function () {
			getTrackPage(this.id);
		}
	}
	function getTrackPage(id) {
		var url = '/discography/lyrics.php';
		var rand   = Math.random(9999);
		var pars   = 'id=' + id + '&rand=' + rand;
		var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onLoading: showLoad, onComplete: showResponse} );
	}
	function showLoad () {
		$('lyrics').style.display = 'none';
		$('loading').style.display = 'block';
	}
	function showResponse (originalRequest) {
		var newData = originalRequest.responseText;
		$('loading').style.display = 'none';
		$('lyrics').style.display = 'block';		
		$('lyrics').innerHTML = newData;
	}

});

function showBio(event) {
	Event.stop(event);
	Lightview.show({ href: '/bio/',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showEquipment(event) {
	Event.stop(event);
	Lightview.show({ href: '/equipment/',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showLegal(event) {
	Event.stop(event);
	Lightview.show({ href: '/legal/',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showMedia(event) {
	Event.stop(event);
	Lightview.show({ href: '/media/',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showRadio(event) {
	Event.stop(event);
	Lightview.show({ href: '/radio/',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showEB(event) {
	Event.stop(event);
	Lightview.show({ href: '/popups/eb.php',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showSr(event) {
	Event.stop(event);
	Lightview.show({ href: '/popups/sr.php',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}
function showIr(event) {
	Event.stop(event);
	Lightview.show({ href: '/popups/ir.php',	rel: 'ajax', options: {	autosize: true,	topclose: true	} });
}

function showEmail(event) {
	Event.stop(event);
	Lightview.show({
		href: '/email/',
		rel: 'ajax',
		options: {
			autosize: true,
			topclose: true,
			ajax: {
				onComplete: function(){
				// once the request is complete we observe the form for a submit
				$('emma_signup').observe('submit', sendEmailForm);
				}
			}
		}
	});
}
function sendEmailForm(event){
	// we stop the default submit behaviour
	Event.stop(event);
	var oOptions = {
		method: "POST",
		parameters: Form.serialize("emma_signup"),
		asynchronous: true,
		onFailure: function (oXHR) {
			$('pop').update(oXHR.statusText);
		},
		onLoading: function (oXHR) {
			$('pop').update('Sending data ... <img src="/images/loading_indicator.gif" title="Loading..." alt="Loading..." border="0" />');
		},							
		onSuccess: function(oXHR) {
		   //$('pop_left').update(oXHR.responseText); // use either this or the line below
			Lightview.show({ href: '/email/index.php?r='+(oXHR.responseText), rel: 'ajax',	options: { autosize: true, topclose: true } });
		}				
	};
	var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "/email/process_form.php", oOptions);			 
}
function showContact(event) {
	Event.stop(event);
	Lightview.show({
		href: '/contact/',
		rel: 'ajax',
		options: {
			autosize: true,
			topclose: true,
			ajax: {
				onComplete: function(){
				// once the request is complete we observe the form for a submit
				$('contactForm').observe('submit', sendForm);
				}
			}
		}
	});
}
function sendForm(event){
	// we stop the default submit behaviour
	Event.stop(event);
	var oOptions = {
		method: "POST",
		parameters: Form.serialize("contactForm"),
		asynchronous: true,
		onFailure: function (oXHR) {
			$('pop_left').update(oXHR.statusText);
		},
		onLoading: function (oXHR) {
			$('pop_left').update('Sending data ... <img src="/images/loading_indicator.gif" title="Loading..." alt="Loading..." border="0" />');
		},							
		onSuccess: function(oXHR) {
		   //$('pop_left').update(oXHR.responseText); // use either this or the line below
			Lightview.show({ href: '/contact/index.php?r='+(oXHR.responseText), rel: 'ajax',	options: { autosize: true, topclose: true } });
		}				
	};
	var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "/contact/process_form.php", oOptions);			 
}

