$(document).ready(function() {


fixGreyBox();

if($('#twitter_update_list li').length > 0){
	$('#twitter_update_list').show();
	$('#twitter_update_list a').each(function(){
		$(this).attr('target', '_blank')
	});

}else{
	$('#twitterFallBack').show();
}


var pageHolderHeight = '850px';
var windowHeight = $(window).height();


if(windowHeight > 850){
	$('#gatewayFormShadow').height(windowHeight);
}else{
	$('#gatewayFormShadow').height(pageHolderHeight);
}


var pageHolderWidth = '1150px';
var windowWidth = $(window).width();

$(window).resize(function() {
	var newWindowWidth = $(window).width();
	if(newWindowWidth > 1150){
	$('#gatewayFormShadow').width(newWindowWidth);
	}
	
	var newWindowHeight = $(window).height();
	if(newWindowHeight > 850){
	$('#gatewayFormShadow').height(newWindowHeight);
	}
	
});

if(windowWidth > 1150){
	$('#gatewayFormShadow').width(windowWidth);
}else{
	$('#gatewayFormShadow').width(pageHolderWidth);
}



	$("#gateway_index fieldset input#day").focus(function() {
		var value = $(this).val();
		if(value == "DD") {
			$(this).val("");
		}
	});
	
	$("#gateway_index fieldset input#day.french").focus(function() {
		var value = $(this).val();
		if(value == "JJ") {
			$(this).val("");
		}
	});
	
	$("#gateway_index fieldset input#day.french").blur(function() {
		var value = $(this).val();
		if(value == "") {
			$(this).val("JJ");
		}
	});
	
	$("#gateway_index fieldset input#day").blur(function() {
		var value = $(this).val();
		if(value == "") {
			$(this).val("DD");
		}
	});
	
	$("#gateway_index fieldset input#month").focus(function() {
		var value = $(this).val();
		if(value == "MM") {
			$(this).val("");
		}
	});
	
	$("#gateway_index fieldset input#month").blur(function() {
		var value = $(this).val();
		if(value == "") {
			$(this).val("MM");
		}
	});
	
	$("#gateway_index fieldset input#year").focus(function() {
		var value = $(this).val();
		if(value == "YYYY") {
			$(this).val("");
		}
	});
	
	$("#gateway_index fieldset input#year.french").focus(function() {
		var value = $(this).val();
		if(value == "AAAA") {
			$(this).val("");
		}
	});
	
	$("#gateway_index fieldset input#year.french").blur(function() {
		var value = $(this).val();
		if(value == "") {
			$(this).val("AAAA");
		}
	});
	
	$("#gateway_index fieldset input#year").blur(function() {
		var value = $(this).val();
		if(value == "") {
			$(this).val("YYYY");
		}
	});
	
	$("#gateway_index #province").toggle(function(event) {
		event.preventDefault();
		  $("#gateway_index #dropdown").animate({
			top: "-125px",
			height: "481px"
		  }, 500 );
		$(this).css("background-position", "0 -65px");
	}, function(event) {
		event.preventDefault();
		  $("#gateway_index #dropdown").animate({
			top: "+125px",
			height: "0px"
		  }, 500 );
		$(this).css("background-position", "0 0");
	});
	
	
	$("#gateway_index #dropdown_hidden").val("alb");
	
	$("#gateway_index #dropdown li a").click(function(event) {
		event.preventDefault();
		$("#gateway_index #province").click();
		
		$("#gateway_index #dropdown").animate({
			top: "+125px",
			height: "0px"
		}, 500 );
		
		var selectedProv = $(this).attr("id");
		var selectedText = $(this).text();
		$("#gateway_index #dropdown_hidden").val(selectedProv);
		$("#gateway_index #province").text(selectedProv.toUpperCase());
	});

	
	$("#gateway_index #submit_hidden").hide();
	$("#gateway_index #dropdown_hidden").hide();
	
	$("#gateway_index #submit").click(function(event) {
		event.preventDefault();
		$("#gateway_index form").submit();
	});
	
	$("#gateway_index #submit_french").click(function(event) {
		event.preventDefault();
		$("#gateway_index form").submit();
	});
	
	$("#home_index #homemenu #bestbeer").css("background-position", "0 0px");
	$("#home_index #homemenu #bestbeer_french").css("background-position", "0 -57px");
	
	$("#home_index #homemenu a").hover(function(event) {
		event.preventDefault();
		var height = $(this).height();
		$("#home_index #homemenu a").css("background-position", "0 0");
		$(this).css("background-position", "0 -" + height + "px");
		var position = $(this).position();
		$("#home_index #probably #probablylink, #home_index #probably #probablylink_french").stop().animate({top: position.top + "px", left: 0}, 500, function(){});
		$("#home_index #probably #probablylink, #home_index #probably #probablylink_french").attr("href", $(this).attr("href"));
	});
	
	$("#tab").click(function(event) {
		event.preventDefault();
		if($("#slider").hasClass("closed")) {
			$("#slider").stop().animate({left: 0}, 600, function(){});
			$("#slider").removeClass("closed").addClass("open");
			$(this).removeClass("closed").addClass("open");
		} else {
			$("#slider").stop().animate({left: -1030}, 600, function(){});
			$("#slider").removeClass("open").addClass("closed");
			$(this).removeClass("open").addClass("closed");
		}
	});
	
	$("#contact_index #submitHidden").hide();
	
	$("#contact_index #submit, #contact_index #submit_french").click(function(event) {
		event.preventDefault();
		$("#contact_index #contactform").submit();
	});

	$('#torontofc_button_t').mouseover(function() {
		if(!($('#torontofc_button').is(':animated'))){
			$('#torontofc_button').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#torontofc_button').fadeOut('fast');
	});	
	
	$('#sponsorships_button_t').mouseover(function() {
		if(!($('#sponsorships_button').is(':animated'))){
			$('#sponsorships_button').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#sponsorships_button').fadeOut('fast');
	});
	
	
	
	$('#tfc_siteButton_t').mouseover(function() {
		if(!($('#tfc_siteButton').is(':animated'))){
			$('#tfc_siteButton').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#tfc_siteButton').fadeOut('fast');
	});	
	
	$('#tfc_proxButton_t').mouseover(function() {
		if(!($('#tfc_proxButton').is(':animated'))){
			$('#tfc_proxButton').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#tfc_proxButton').fadeOut('fast');
	});

	$('#b_baradd_req_t').mouseover(function() {
		if(!($('#b_baradd_req').is(':animated'))){
			$('#b_baradd_req').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#b_baradd_req').fadeOut('fast');
	});	
	
	$('#b_mapgo_en_t').mouseover(function() {
		if(!($('#b_mapgo_en').is(':animated'))){
			$('#b_mapgo_en').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#b_mapgo_en').fadeOut('fast');
	});	
	
	$('#contactSubmit_t').mouseover(function() {
		if(!($('#contactSubmit').is(':animated'))){
			$('#contactSubmit').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#contactSubmit').fadeOut('fast');
	});	
	
	
	$('#site_sports_t').mouseover(function() {
		if(!($('#site_sports').is(':animated'))){
			$('#site_sports').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#site_sports').fadeOut('fast');
	});	
	
	$('#site_about_t').mouseover(function() {
		if(!($('#site_about').is(':animated'))){
			$('#site_about').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#site_about').fadeOut('fast');
	});	
	
	$('#site_buy_t').mouseover(function() {
		if(!($('#site_buy').is(':animated'))){
			$('#site_buy').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#site_buy').fadeOut('fast');
	});
	
	$('#torontofc_button_french_t').mouseover(function() {
		if(!($('#torontofc_button_french').is(':animated'))){
			$('#torontofc_button_french').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#torontofc_button_french').fadeOut('fast');
	});	
	
	$('#sponsorships_button_french_t').mouseover(function() {
		if(!($('#sponsorships_button_french').is(':animated'))){
			$('#sponsorships_button_french').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#sponsorships_button_french').fadeOut('fast');
	});
	
	$('#torontofc_button_french_t').mouseover(function() {
		if(!($('#torontofc_button_french').is(':animated'))){
			$('#torontofc_button_french').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#torontofc_button_french').fadeOut('fast');
	});	
	
	$('#tfc_proxbutton_french_t').mouseover(function() {
		if(!($('#tfc_proxbutton_french').is(':animated'))){
			$('#tfc_proxbutton_french').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#tfc_proxbutton_french').fadeOut('fast');
	});
	
	$('#tfc_siteButton_french_t').mouseover(function() {
		if(!($('#tfc_siteButton_french').is(':animated'))){
			$('#tfc_siteButton_french').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#tfc_siteButton_french').fadeOut('fast');
	});
	
	$('#b_mapgo_fr_t').mouseover(function() {
		if(!($('#b_mapgo_fr').is(':animated'))){
			$('#b_mapgo_fr').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#b_mapgo_fr').fadeOut('fast');
	});
	
	$('#contactSubmit_fr_t').mouseover(function() {
		if(!($('#contactSubmit_fr').is(':animated'))){
			$('#contactSubmit_fr').fadeIn('fast');
		}
	}).mouseout(function(){
			$('#contactSubmit_fr').fadeOut('fast');
	});

	
});

$('#facebookiFrame').ready(function(){

});


	// Utility functions
function  fixGreyBox() {
    // find all the greyBox and correct their html
    $(".greybox").before('<div class="greyboxOutside"><div class="topright"></div><div class="top"></div></div>');
    $(".greybox").after('<div class="greyboxOutside"><div class="bottomright"></div><div class="bottom"></div></div>');
}




function pd(event) {
    event.preventDefault();
}
function trim (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

