/* count down variables */
//TargetDate = "06/05/2010 0:00 AM";
//TargetDates = ["06/05/2010 0:00 AM", "06/13/2010 0:00 AM", "06/27/2010 0:00 AM", "07/25/2010 0:00 AM", "08/07/2010 0:00 AM", "08/22/2010 0:00 AM"];
//TargetLinks = ["/races/crooked-lake-triathlon-5th-june/", 
//			   "/races/causeway-coast-triathlon-13th-june/", 
//			   "/races/waterways-ireland-fermanagh-lakeland-triathlon-27th-june/",
//			   "/races/top-of-the-mourne-triathlon-25th-july/",
//				"/races/mourne-triathlon-7th-august/", 
//				"/races/half-ireman-22nd-august/"];

// todo: setup script to show next date when required
//CountActive = true;
//CountStepper = -1;
//LeadingZero = true;
//DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
//DisplayFormat = "%%H%%H<span>:</span>%%M%%M";
//FinishMessage = "All done!";


/* no further editing required */
//if (typeof(TargetDate)=="undefined")
//	TargetDate = "06/05/2010 5:00 AM";
//if (typeof(DisplayFormat)=="undefined")
//	DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
//if (typeof(CountActive)=="undefined")
//	CountActive = true;
//if (typeof(FinishMessage)=="undefined")
//	FinishMessage = "";
//if (typeof(CountStepper)!="number")
//	CountStepper = -1;
//if (typeof(LeadingZero)=="undefined")
//	LeadingZero = true;

//CountStepper = Math.ceil(CountStepper);
//if (CountStepper == 0) {
//	CountActive = false;
//}
//var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;

//var dnow = new Date();
// check to see if there is a valid date to countdown to
//var dthen;
//for(dateInt=0;dateInt<TargetDates.length;dateInt++) {
//	dthen = new Date(TargetDates[dateInt]);
//	ddiff = new Date(dthen-dnow);
//	gsecs = Math.floor(ddiff.valueOf()/1000);
//	if (gsecs>0) {
//		break;
//	}
//}

//CountBack(gsecs);
	
// function calcage(secs, num1, num2) {
  // s = ((Math.floor(secs/num1))%num2).toString();
  // if (LeadingZero && s.length < 2)
    // s = "0" + s;
  // return "<strong>" + s + "</strong>";
// }

// function CountBack(secs) {
  // if (secs < 0) {
    // document.getElementById("race").innerHTML = FinishMessage;
    // return;
  // }
 // DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  // DisplayStr = /*DisplayStr*/DisplayFormat.replace(/%%H%%/g, calcage(secs,3600,100000));
  // DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  //DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

  // document.getElementById("race").innerHTML = DisplayStr;
  // document.getElementById("race").href = TargetLinks[dateInt];
  
  // if (CountActive)
    // setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
// }

$(document).ready(function() {
	
	$('ul.sf-menu').superfish();
	$('ul.sf-menu li:last-child').each(function() {
		$(this).addClass("last");
	});
	
	$('#banner').cycle({
		fx: 'fade',
		speed: 1500,
		timeout: 6000
	});

	function switchTextBlur() {
		if ($.trim($(this).val()) == '') {
			$(this).addClass('exampleText').val($(this).attr('title'));
		}
	}
	function switchTextFocus() {
		if ($(this).val() == $(this).attr('title')) {
			$(this).val('').removeClass('exampleText');
		}
	}
	// set behaviour on form fields
	$('form#talk_to_us input[type=text][title!=""]').each(function() {
		if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
		if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
	}).focus(switchTextFocus).blur(switchTextBlur);
	
	// remove default text on submit
	$('form#talk_to_us').submit(function() {
		$(this).find('input[type=text][title!=""]').each(function() {
			if ($(this).val() == $(this).attr('title')) $(this).val('');
		});
	});
	
});

jQuery.fn.exists = function(){return jQuery(this).length>0;}
