$("#nav-bar li:not(.current) a img").hover(
	function() { $(this).attr("src", $(this).attr("src").split(".").join("-hover.")); },
	function() { $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
});
$("a img.ro").hover(
	function() { $(this).attr("src", $(this).attr("src").split(".").join("-hover.")); },
	function() { $(this).attr("src", $(this).attr("src").split("-hover.").join(".")); 
});
$(".get-tickets a img").hover(
	function() { $(this).attr("src", $(this).attr("src").split(".").join("-hover.")); },
	function() { $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
});
$("input.ro").hover(
	function() { $(this).attr("src", $(this).attr("src").split(".").join("-hover.")); },
	function() { $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
});

/*$("a#no-password").click(function() { $("#no-password-info").slideDown("fast"); return false; });*/
$("a#no-promo-code").click(function() { $("#no-promo-code-info").animate({height:"3em"}, {queue:false, duration:1000}); return false; });
$("a#seating-chart-link").click(function() { $("#seating-chart").slideToggle("slow"); return false; });
$("a#moto-tix").click(function() { $("#moto-show-description").slideToggle("fast"); return false; });
$("#get-tickets-btn a img").click(function() { return verifyForm(false); });
$("#buy-tickets-form").submit(function() { return verifyForm(true); });
$("a#rie-marketing-contract").click(function() { pageTracker._trackPageview("marketing-advertising.php/rie-marketing-contract"); });
$("a#rin-mindset").click(function() { pageTracker._trackPageview("marketing-advertising.php/rin-mindset"); });
$("a#rie-sponsors-brochure").click(function() { pageTracker._trackPageview("marketing-advertising.php/rie-sponsors-brochure"); });
$("a#rie-corporate-ice-breaker").click(function() { pageTracker._trackPageview("marketing-advertising.php/corporate-ice-breaker"); });
$("a#rie-fight-card-printing-instructions").click(function() { pageTracker._trackPageview("marketing-advertising.php/fight-card-printing-instructions"); });
$("a#rie-20090321-harrisonburg-fight-cards").click(function() { pageTracker._trackPageview("marketing-advertising.php/20090321-harrisonburg-fight-cards"); });
$("a#facebook-link").click(function() { pageTracker._trackPageview("index.php/facebook-link-click"); });
$("a#twitter-link").click(function() { pageTracker._trackPageview("index.php/twitter-link-click"); });
$("a#gtg-link").click(function() { pageTracker._trackPageview("index.php/gtg-link-click"); });
$("a#the-good-fight-link").click(function() { pageTracker._trackPageview("left-nav/the-good-fight-link-click"); });
$("a#philly-sports-forums-link").click(function() { pageTracker._trackPageview("left-nav/philly-sports-forums-link-click"); });
$("form[name='scan-tickets'] input[name='ticket-code']").keyup(function() {
	if ($(this).val().length == 6) {
		$("#ticket-results").html("Looking up ticket...");
		validateTicket();
	}
});
$("form[name='scan-tickets'] input[name='submit-btn']").click(function() {
	if ($("form[name='scan-tickets'] input[name='ticket-code']").val().length == 6) {
		$("#ticket-results").html("Looking up ticket...");
		validateTicket();
	}						   
});
$("select[name='techniques[]']").change(function() {
	var id = $(this).attr("id");
	id = id.split('-')[1];
	if ($("select#techniques-"+id+" :selected").val() == 1) {
		$("select#rounds-"+id).val("3");
		$("select#times-"+id).val("6");
	}
});
$("input[name='professional-fighter']").change(function() {
	if ($(this).val() == "Y") {
		$("#professional-fighter-info").show("fast");
	}
	else {
		$("#professional-fighter-info").hide("fast");
	}
});
function verifyForm(isTicketSalesForm) {
	var firstName = $("#buy-tickets-form input#first-name").val();
	var lastName = $("#buy-tickets-form input#last-name").val();
	var password = $("#buy-tickets-form input#promo-code").val();
	var msg1 = "Please enter the following information:\n";
	var msg1Error = false;
	
	if (isTicketSalesForm) {
	var quantity = $("#buy-tickets-form select#quantity").val();
	var section = $("#buy-tickets-form select#section").val();	
		if (quantity.length == 0 || quantity == 0) {
			msg1 += " - Quantity\n";
			msg1Error = true;
		}
		if (section.length == 0) {
			msg1 += " - Section\n";
			msg1Error = true;
		}
	}
	if (firstName.length == 0) {
		msg1 += " - First name\n";
		msg1Error = true;
	}
	if (lastName.length == 0) {
		msg1 += " - Last name\n";
		msg1Error = true;
	}
	if (password.length == 0) {
		msg1 += " - Promo code\n";
		msg1Error = true;
	}
	
	if (msg1Error) {
		alert(msg1);
		return false;
	}
	
	var msg2 = "Please correct the following information:\n";
	var msg2Error = false;
	if (!firstName.match("^[a-zA-Z\']+$")) {
		msg2 += " - First name is invalid\n";
		msg2Error = true;
	}
	if (!lastName.match("^[a-zA-Z\']+$")) {
		msg2 += " - Last name is invalid\n";
		msg2Error = true;
	}
	if (!password.match("^[rR]{1}[iI]{1}[eE]{1}[0-9]{1,3}[a-zA-Z]*$")) {
		msg2 += " - Promo code is invalid\n";
		msg2Error = true;
	}
	
	if (msg2Error) {
		alert(msg2);
		return false;
	}
	return true;
}
function validateTicket() {
	var ticket = $("form[name='scan-tickets'] input[name='ticket-code']").val();
	var eventID = $("form[name='scan-tickets'] select[name='event-id']").val();
	$("#ticket-results").load("/my-account/ticket-results.php", { ticket: ticket, eventID: eventID });
	$("form[name='scan-tickets'] input[name='ticket-code']").select();
}
/**
 * Loads the countdown to the next event
 */
 var targetDate = null;
function load_countdown()
{
	this.delay = 1000;
	this.counter = 0;
	this.timer = 0;
	
	// Set the target Date (July 17, 2009 8:00 PM)
	this.targetDate = new Date(2010, 6, 31, 19, 30, 0, 0);
	countdown_play();
}

function countdown_play()
{
	var currentDate = new Date();
	var millisPerDay = 86400000;
	var millisPerHour = 3600000;
	var millisPerMinute = 60000;
	var millisPerSecond = 1000;
	var currentTimeInMillis = Date.parse(currentDate.toString());
	var targetTimeInMillis = Date.parse(this.targetDate.toString());
	var diffInMillis = targetTimeInMillis - currentTimeInMillis;
	if (diffInMillis < 0) diffInMillis = 0;
	
	var daysLeft = Math.floor(diffInMillis / millisPerDay);
	diffInMillis = diffInMillis % millisPerDay;
	
	var hoursLeft = Math.floor(diffInMillis / millisPerHour);
	diffInMillis = diffInMillis % millisPerHour;
	
	var minutesLeft = Math.floor(diffInMillis / millisPerMinute);
	diffInMillis = diffInMillis % millisPerMinute;
	
	var secondsLeft = Math.floor(diffInMillis / millisPerSecond);
	diffInMillis = diffInMillis % millisPerSecond;
	
	var days_tens = Math.floor(daysLeft / 10);
	var days_ones = daysLeft % 10;
	var hours_tens = Math.floor(hoursLeft / 10);
	var hours_ones = hoursLeft % 10;
	var minutes_tens = Math.floor(minutesLeft / 10);
	var minutes_ones = minutesLeft % 10;
	var seconds_tens = Math.floor(secondsLeft / 10);
	var seconds_ones = secondsLeft % 10;
	
	jQuery("#days-tens").html(days_tens);
	jQuery("#days-ones").html(days_ones);
	jQuery("#hours-tens").html(hours_tens);
	jQuery("#hours-ones").html(hours_ones);
	jQuery("#mins-tens").html(minutes_tens);
	jQuery("#mins-ones").html(minutes_ones);
	jQuery("#secs-tens").html(seconds_tens);
	jQuery("#secs-ones").html(seconds_ones);

	clearTimeout(timer);
	this.timer = setTimeout('countdown_play()', this.delay);
}
$(document).ready(function() {
	load_countdown();
	$('div.video').hover(
		function() { $(this).css({border: '1px solid red', backgroundColor: '#333'}).children(".video-link").css("color","#ed1c24"); },
		function() { $(this).css({border: '1px solid #000', backgroundColor: '#000'}).children(".video-link").css("color","#fff"); });
	$('#video-link-0').click(function() {launchPopupVideo('0');});
	$('#video-link-0a').click(function() {launchPopupVideo('0');});
	$('#video-link-1').click(function() {launchPopupVideo('1');});
	$('#video-link-1a').click(function() {launchPopupVideo('1');});
	$('#video-link-2').click(function() {launchPopupVideo('2');});
	$('#video-link-2a').click(function() {launchPopupVideo('2');});
	$('#video-link-3').click(function() {launchPopupVideo('3');});
	$('#video-link-3a').click(function() {launchPopupVideo('3');});
	$('#video-link-4').click(function() {launchPopupVideo('4');});
	$('#video-link-4a').click(function() {launchPopupVideo('4');});
	$('#video-link-5').click(function() {launchPopupVideo('5');});
	$('#video-link-5a').click(function() {launchPopupVideo('5');});
	$('#video-link-6').click(function() {launchPopupVideo('6');});
	$('#video-link-6a').click(function() {launchPopupVideo('6');});
	$('#video-link-7').click(function() {launchPopupVideo('7');});
	$('#video-link-7a').click(function() {launchPopupVideo('7');});
	$('#video-link-8').click(function() {launchPopupVideo('8');});
	$('#video-link-8a').click(function() {launchPopupVideo('8');});
	$('#video-link-9').click(function() {launchPopupVideo('9');});
	$('#video-link-9a').click(function() {launchPopupVideo('9');});
	$('#video-link-f1').click(function() {launchPopupVideo('f1');});
	$('#video-link-f2').click(function() {launchPopupVideo('f2');});
	$('#video-link-f3').click(function() {launchPopupVideo('f3');});
	$('#video-link-f4').click(function() {launchPopupVideo('f4');});
	$('#video-link-f5').click(function() {launchPopupVideo('f5');});
	$('a.close-layer').click($.unblockUI);
});

function launchPopupVideo(videoID) {
	$.blockUI({ message: $('div#popup-video-' + videoID), css: { 
                top:  ($(window).height() - 400) /2 + 'px', 
                left: ($(window).width() - 640) /2 + 'px', 
                width: '640px',
				backgroundColor: '#666'
            } 
   }); 
}

function initPopupVideo(video) {
	YAHOO.namespace("example.container");
	if (!YAHOO.example.container.wait) {
		// Initialize the temporary Panel to display while waiting for external content to load
		YAHOO.example.container.wait = 
		new YAHOO.widget.Panel("wait",  
			{ width:"640px", 
			  height:"360px",
			  fixedcenter:true, 
			  close:true, 
			  draggable:false, 
			  zindex:400,
			  modal:true,
			  visible:false,
			  iframe:true
			} 
		);
	
		YAHOO.example.container.wait.setHeader("");
		YAHOO.example.container.wait.setBody('<div id="popup-flvplayer"><font size="1" color="#FFFFFF"><a href="http://www.macromedia.com/go/getflashplayer"><font size="1" color="#FFFFFF">Get the Flash Player</font></a> to see this player.</font></div>');
		YAHOO.example.container.wait.render(document.body);
		var s1 = new SWFObject("/assets/flash/player-licensed.swf","mediaplayer","640","360","7");
		s1.addParam("allowfullscreen","true");
		s1.addParam('allowscriptaccess','always');
		s1.addParam("wmode","opaque");
		s1.addVariable("width","640");
		s1.addVariable("height","360");
		s1.addParam('flashvars','autostart=true&provider=video&file=http://hwcdn.net/b3c8n4b8/cds/FightPromos/'+video+'&width=640&height=360');
		s1.write("popup-flvplayer");
	}

	// Show the Panel
	YAHOO.example.container.wait.hideEvent.subscribe(closePopup, null, null);
	YAHOO.example.container.wait.show();
}

var player = null;

function playerReady(thePlayer) {
	player = jQuery('#' + thePlayer.id)[0];
	player.addModelListener("STATE","handleStateChange"); 
}
function handleStateChange(obj) {
	if (obj.oldstate == "BUFFERING" && obj.newstate == "IDLE") {
		player.sendEvent("PLAY","true");
	}
	else if (obj.oldstate == "PLAYING" && obj.newstate == "COMPLETED") {
		YAHOO.example.container.wait.hide();
	}
}

function closePopup() {
	player.sendEvent('STOP');
	jQuery("#popup-flvplayer").remove();
	YAHOO.example.container.wait.destroy();
}