$(document).ready(function() {

	$("table.dates tr a.more").click(function() {
		$(this).parents("tr").next().find('td div').toggle();
		return false;
	});
	
    $('#video').flash(
        { src: 'inc/flash/player.swf',
          width: 600,
          height: 326,
          wmode: 'opaque',
          bgcolor: '#000000' },
        { version: 9 }
    );
	
    $('#video_perf').flash(
        { src: '/inc/flash/player - ie performance.swf',
          width: 600,
          height: 326,
          wmode: 'opaque',
          bgcolor: '#000000' },
        { version: 9 }
    );
    
    /*$('#miniplayer').flash(
        { src: '/inc/flash/mini/mini.swf',
          width: 371,
          height: 45,
          id: 'audioPlayer',
          name: 'audioPlayer',
          allowscriptaccess: 'always',
          swliveconnect: 'true' },
        { version: 8 }
    );*/
	
    $('#videoplayer').flash(
        { src: '/inc/flash/mini_player.swf', width: 350, height: 303 },
        { version: 8 },
        function(htmlOptions) {
            $this = $(this);
            htmlOptions.flashvars.file = $this.attr('rel');
            $this.html($.fn.flash.transform(htmlOptions));						
        }
    );

	$('#slidePhotos').innerfade({
		speed: 3000,
		timeout: 8000,
		type: 'sequence',
		containerheight: '231px'
	});
    
   $('#albumExplorer').jqm({trigger: 'a.albumExplorer', onHide: closeAlbumExplorer});
    
    $('a.albumExplorer').click(function() {    	
    	$('#video, #videoplayer').html('');
    	$('#audioPlayer').before('<div id="miniplayer"></div>').remove();
    		
    	if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox") {
    		$('#slidePhotos').css('display', 'none');
    	}
    		
		$('#albumplayer').flash(
			{ src: '/inc/flash/explorer/teatro.swf',
			  width: 759,
			  height: 380,
			  wmode: 'opaque',
			  bgcolor: '#ededed' },
			{ version: 8 }
		);
		    
    	return false;
    });
    
});

function thisMovie(movieName) {
	/*var isIE = navigator.appName.indexOf('Microsoft') != -1;
	return (isIE) ? window[movieName] : document[movieName];*/
	return document.getElementById(movieName);
}

function closeAlbumExplorer(hash) {
	hash.o.remove();
	hash.w.hide();
		
	$('#video').flash(
		{ src: 'inc/flash/player.swf',
		  width: 600,
		  height: 326,
		  wmode: 'opaque',
		  bgcolor: '#000000' },
		{ version: 8 }
	);
	
	if (jQuery.browser.msie && window.location.href.indexOf("/music") > 0)
		window.location = '/music/';
		
    if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox") {
   		$('#slidePhotos').css('display', 'block');
   	}
	
	$('#miniplayer').flash(
        { src: '/inc/flash/mini/mini.swf',
          width: 371,
          height: 45,
          id: 'audioPlayer',
          name: 'audioPlayer',
          allowscriptaccess: 'always',
          swliveconnect: 'true' },
        { version: 8 }
    );
	
	$('#videoplayer').flash(
		{ src: '/inc/flash/mini_player.swf', width: 350, height: 263 },
		{ version: 8 },
		function(htmlOptions) {
			$this = $(this);
			htmlOptions.flashvars.file = $this.attr('rel');
			$this.html($.fn.flash.transform(htmlOptions));						
		}
	);
	
	$('#albumplayer').html('');
}

jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
}
$.preloadImages('/inc/images/explorer-book.png', '/inc/images/explorer-preorder.png', '/inc/images/overlay-close.jpg');


/*
 * jqModal - Minimalist Modaling with jQuery
 *
 * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * $Version: 2007.08.17 +r11
 * 
 */
(function($) {
$.fn.jqm=function(o){
var _o = {
zIndex: 3000,
overlay: 95,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: false,
target: false,
modal: false,
toTop: false,
onShow: false,
onHide: false,
onLoad: false
};
return this.each(function(){if(this._jqm)return; s++; this._jqm=s;
H[s]={c:$.extend(_o, o),a:false,w:$(this).addClass('jqmID'+s),s:s};
if(_o.trigger)$(this).jqmAddTrigger(_o.trigger);
});};

$.fn.jqmAddClose=function(e){hs(this,e,'jqmHide'); return this;};
$.fn.jqmAddTrigger=function(e){hs(this,e,'jqmShow'); return this;};
$.fn.jqmShow=function(t){window.scrollTo(0,0);return this.each(function(){if(!H[this._jqm].a)$.jqm.open(this._jqm,t)});};
$.fn.jqmHide=function(t){return this.each(function(){if(H[this._jqm].a)$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(/^\d+$/.test(h.w.css('z-index')))?h.w.css('z-index'):c.zIndex,o=$('<div></div>').css({height:'100%',width:'100%',position:'absolute',left:0,top:0,'z-index':z-1});if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox") { } else {o.css('opacity', c.overlay/100);} o.fadeIn('2000', function() {h.w.show();});h.t=t;h.a=true;h.w.css('z-index',z);
 if(c.modal) {if(!A[0])F('bind');A.push(s);o.css('cursor','wait');}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=false;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):false;
 // fix for ff mac - flash and background opacity cause problems, use alpha png instead
 if (BrowserDetect.OS == "Mac" && BrowserDetect.browser == "Firefox") { $('.jqmOverlay').css({backgroundColor:'transparent',backgroundImage:'url(/inc/images/overlay-background.png)',backgroundRepeat:'repeat'}); }
 if(ie6){$('body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}} else { $(".jqmOverlay").css('height', $("html").height()); }

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 //(c.onShow)?c.onShow(h):h.w.show();e(h);return false;
 (c.onShow)?c.onShow(h):e(h);return false;
},
close:function(s){var h=H[s];h.a=false;
 if(A[0]){A.pop();if(!A[0])F('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return false;
}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(e){}},
F=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,e,y){var s=[];w.each(function(){s.push(this._jqm)});
 $(e).each(function(){if(this[y])$.extend(this[y],s);else{this[y]=s;$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return false;});}});};
})(jQuery);

//######################## MAIN FORM VALIDATION FUNCTION ######################
function validateRegistration() {

	var msg = '';

	if (document.frmComp.slctTitle.selectedIndex == 0){
		msg+="\nTitle";
	}		

	if (document.frmComp.txtFirstName.value == "") {
		msg+="\nFirst Name";
	} 

	if (document.frmComp.txtSurname.value == "") {
		msg+="\nLast Name";
	}	

	if (document.frmComp.slctSex.selectedIndex == 0){
		msg+="\nGender";
	}

	if (document.frmComp.txtAddress1.value  == "") {
		msg+="\nAddress Line 1";
	}		

	if (document.frmComp.txtTown.value == "") {
		msg+="\nTown";
	}			

	if (document.frmComp.txtPostcode1.value == "" && document.frmComp.txtPostcode1.disabled == false) {
		msg+="\nPostcode Part 1";
	}

	if (document.frmComp.txtPostcode3.value == "" && document.frmComp.txtPostcode3.disabled == false) {
		msg+="\nPostcode Part 2";
	}		

	if (document.frmComp.slctMonth.selectedIndex == 0 || document.frmComp.slctDay.selectedIndex == 0 || document.frmComp.slctYear.selectedIndex == 0){
		msg+="\nDate of Birth";
	}	

	if (document.frmComp.slctCountry.value == 0) {
		msg+="\nCountry";
	}								

	if (document.frmComp.txtEmail.value == "") {
		msg+="\nEmail Address";
	}

	if (document.frmComp.txtEmail2.value == "") {
		msg+="\nConfirm Email";
	}
	
	if ( document.frmComp.txtEmail.value != document.frmComp.txtEmail2.value ) {
		msg+="\nEmail addresses do not match.";
	}
	
	if (!document.frmComp.agree.checked) {
		msg+='\nYou must agree to the Privacy Policy and/or Terms and Conditions.';
	}
	
	if (msg != "") {
		alert("Please complete the following field(s)\n" + msg);
		return false;
	}
	
	if (!isEmail(document.frmComp.txtEmail.value)) {
		alert("Please enter a valid email address");
		return false;	
	}
	
	if (!isDOB(document.frmComp.slctDay[document.frmComp.slctDay.selectedIndex].value,
			document.frmComp.slctMonth[document.frmComp.slctMonth.selectedIndex].value,
			document.frmComp.slctYear[document.frmComp.slctYear.selectedIndex].value)) {
		return false;	
	}
		
	if (document.frmComp.txtMobile.value != ""){
		if (!isMobile(frmComp.txtMobile.value)){
			alert("Please enter a valid mobile number.");
			return false;
		}
	}
}

//###################################
function isMobile( str ) {
	var r1 = new RegExp("[a-z]|[A-Z]");
	return (!r1.test(str));
}

//#############################
function checkCountry() {
	if (document.all){
		if(frmComp.slctCountry.value == "GBR"){
			frmComp.txtzipcode.value = "";
			frmComp.txtzipcode.disabled = true;
			frmComp.txtPostcode1.disabled = false;
			frmComp.txtPostcode3.disabled = false;
		} else {
			frmComp.txtPostcode1.value = "";
			frmComp.txtPostcode3.value = "";
			frmComp.txtzipcode.disabled = false;
			frmComp.txtPostcode1.disabled = true;
			frmComp.txtPostcode3.disabled = true;
		}
	}	
}

function isDOB(dd,mm,yyyy) {
	
	monthdays = new Array(12);
	monthdays[0]=31;
	monthdays[1]=28;
	monthdays[2]=31;
	monthdays[3]=30;
	monthdays[4]=31;
	monthdays[5]=30;
	monthdays[6]=31;
	monthdays[7]=31;
	monthdays[8]=30;
	monthdays[9]=31;
	monthdays[10]=30;
	monthdays[11]=31;
	
	todayDate=new Date();
	thisyear=todayDate.getFullYear();

	if (isNaN(dd) || isNaN(mm) || isNaN(yyyy)) {
		alert('Please ensure you have entered numbers for the Date of Birth');
		return false;
	}

	if (((yyyy % 4 == 0) && !(yyyy % 100 == 0)) ||(yyyy % 400 == 0)) monthdays[1]++;
	
	if ((yyyy < 1900) || (yyyy >= (thisyear+1900))) {
		alert('Please check the year for the Date of Birth');
		return false;
	}
	
	if ((mm > 12) || (mm < 1)) {
		alert('Please check the month for the Date of Birth');
		return false;
	}
	
	if ((dd > monthdays[mm - 1]) || (dd < 1)) {
		alert('Please check the day for the Date of Birth');
		return false;
	}
	
	var testYear = parseInt(yyyy)+14;
	if( testYear > thisyear ) {
		alert( "Sorry, you must be 14 or over to register.");
		return false;
	}
	
	if( testYear == thisyear ) {
		var testMonth = parseInt(todayDate.getMonth()) + 1;
		
		if( testMonth < parseInt(mm) ) {
			alert( "Sorry, you must be 14 or over to register." );
			return false;
		}
		
		if( testMonth == parseInt(mm) ) {
			var testDay = parseInt(todayDate.getDate());
			
			if( testDay < parseInt(dd) ) {
				alert( "Sorry, you must be 14 or over to register." );
				return false;
			}	
		}
	}
	
	return true;

}

//#################################
function isEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

function doGender() {
	f = document.forms[0];
	
	if( (f.slctTitle.selectedIndex == 1) || (f.slctTitle.selectedIndex == 5) ) {
		f.slctSex.selectedIndex = 1;
	} else {
		f.slctSex.selectedIndex = 2;
	}
}