var fitnessClubs = ['kingston','leicester','maidenhead','maidstone','solihullsouth','stevenage'];
var hadClubs = ['hull','dundee'];
var hafClubs = ['brighton','fulham','kensington','luton','portsolent','reading'];

$(document).ready(function() {
	$("#club_infobox").hide();
	$("#club_info_button").hide();
	$("div#hidden_msg").hide()
	if(typeof sIFR == "function") {
		sIFR.replaceElement("p.intro_blurb", named({sFlashSrc: "/static/fonts/din-medium-pound.swf", sColor: "#FFFFFF", sWmode: "transparent"}));
	}
	$("#logo_image").click(function(){
		window.location.href = '/home';
	});
	$("#dublin #logo_image").click(function(){
		window.location.href = 'http://www.davidlloyd.ie';
	});
	$("#dutch #logo_image").click(function(){
		window.location.href = 'http://www.davidlloyd.nl';
	});
});

function check_club() {
	var club = $("#sltClub").val();
	if(club == '') {
		$("#club_info_button").hide();
	}
	else {
		$("#club_info_button").show();
	}
}

function check_dutch_club_load(club,filename) {
	if (filename == 'motivatie-2') {
		$("#clubSide").attr('selectedIndex', 2);
		club = 'amsterdam_overtoom';
	}
	check_dutch_club(club,filename);
}

function check_dutch_club(club,filename) {
	if(club == 'amsterdam_overtoom') {
		$("span.price_price").html("39");
		$("#price").css("background","url(/static/promo/jan10/dutch/price_amsterdam.gif?v=2) no-repeat scroll left top");
		$(".header_img").css("background","url(/static/promo/jan10/dutch/header_amsterdam.jpg?v=4) no-repeat scroll left top");
	}
	else {
		$("span.price_price").html("29");
		$("#price").css("background","url(/static/promo/jan10/dutch/price.gif?v=2) no-repeat scroll left top");
		$(".header_img").css("background","url(/static/promo/jan10/dutch/header.jpg?v=3) no-repeat scroll left top");	
	}
	$("#clubSide").val(club);
	$("#sltClub").val(club);
	
	if(club == '') {
		$("#telephone").html('<span style="display: block; width: 50px;">&nbsp;</span>');
		if(typeof sIFR == "function") {
			sIFR.replaceElement("h2#telephone", named({sFlashSrc: "/static/fonts/din-bold.swf", sColor: "#FFFFFF", sCase: "upper", sWmode: "transparent"}));
		}
		$("#club_infobox").slideUp();
	} else {
		$.getJSON('/dutch-promotions/motivatie?_frameset=true&ajax=1&c=landing_newstart&m=get_club_infobox_dutch&ajax_args='+club, function(data){
			$("#club_infobox").slideUp(function() {
				var oldHeight = $("#black_callout").height();
				// bottom section
				$("#club_title").html(data.name).removeClass();
				$("#club_address").html(data.address);
				$("#club_facilities").html(data.facilities);
				$("#club_infobox").slideDown(function() {
					setMap(data.lat,data.long,club);
					$("h4#club_title").addClass("title_"+data.name);
					if(typeof sIFR == "function") {
						sIFR.replaceElement("h4.title_"+data.name, named({sFlashSrc: "/static/fonts/din-medium.swf", sColor: "#ffffff", sBgColor: "#b2995b", sWmode: "transparent"}));
					}
				});
				$("#sltClub").val(club);
				$("#clubSide").val(club);
				$("#telephone").html('CALL: '+data.tel);
				if(typeof sIFR == "function") {
					sIFR.replaceElement("h2#telephone", named({sFlashSrc: "/static/fonts/din-bold.swf", sColor: "#FFFFFF", sCase: "upper", sWmode: "transparent"}));
				}
			});
		});
	}
}

function openClubInfoBox(url,type,optionalClub) {
	if(optionalClub !== undefined) { 
		var club = optionalClub;
	}
	else {
		var club = $("#sltClub").val();					
	}
	if(club == '') return true;
	$.getJSON(url+'?_frameset=true&ajax=1&c=landing_newstart&m=get_club_infobox&ajax_args='+club, function(data){
		$("#club_infobox").slideUp(function() {
			var oldHeight = $("#black_callout").height();
			// do we need pricing ? - top section
			if(type == 'difference-hd' || type == 'newyou') {
				if(jQuery.inArray(club,fitnessClubs) > -1 || jQuery.inArray(club,hadClubs) > -1 ) {
					var color = type == 'difference-hd' ? '7cbd30' : 'c0272c';
					price = getClubPrice(club);
					$("div#only").html("").html("<h3 class='only'>From Only £"+price+"</h3><h3 class='permonth'>per month</h3>");
					if(typeof sIFR == "function") {
						sIFR.replaceElement("h3.only", named({sFlashSrc: "/static/fonts/din-bold-alt.swf", sColor: "#ffffff", sWmode: "transparent"}));
						sIFR.replaceElement("h3.permonth", named({sFlashSrc: "/static/fonts/din-bold-alt.swf", sColor: "#"+color, sWmode: "transparent"}));
					}
					$("#black_callout").css("height","auto");
					var newHeight = $("#black_callout").height();
					var diff = newHeight - oldHeight;
					$("#club_infobox .inner").css("margin-top",diff+"px");
					$("#photos_side").css("top",(5+diff)+"px");
				}
				else {
					$("div#only").html("");	
					$("#black_callout").css("height",oldHeight+"px");
					$("#club_infobox .inner").css("margin-top","0px");
					$("#photos_side").css("top","5px");
				}
			}
			// bottom section
			$("#club_title").html(data.name).removeClass();
			$("#club_address").html(data.address);
			$("#club_facilities").html(data.facilities);
			$("#club_infobox").slideDown(function() {
				setMap(data.lat,data.long,club);
				$("h4#club_title").addClass("title_"+data.name);
				if(typeof sIFR == "function") {
					sIFR.replaceElement("h4.title_"+data.name, named({sFlashSrc: "/static/fonts/din-medium.swf", sColor: "#ffffff", sBgColor: "#b2995b", sWmode: "transparent"}));
				}
			});
			$("#sltClub").val(club);
			$("#clubSide").val(club);
		});
	});
}

function closeInfoBox() {
	$("#club_infobox").slideUp();
}

function setMap(lat,long,club) {
	var zoom = 14;
	if(club == 'chigwell') zoom = 13;
	if(clubMap = new GMap2(document.getElementById('club_map'))) {
		clubMap.addOverlay(new GMarker(new GLatLng(lat,long)));
		clubMap.setCenter(new GLatLng(lat,long),zoom);
		clubMap.enableScrollWheelZoom();
	}			
}
function toggleClubButtonAndMessage(type,emailType,clubSelector) {
	var club = $("#"+clubSelector).val();
	var message = '';
	switch(type) {
		case 'difference':
			switch(emailType) {
				case 'eb':
				case 'em':
				case 'normal':
					if(jQuery.inArray(club,fitnessClubs) > -1)
						message = "The club you have selected does not offer racquets facilities or a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					else if(jQuery.inArray(club,hafClubs) > -1)
						message = "The club you have selected does not offer racquets facilities.";
					else if(jQuery.inArray(club,hadClubs) > -1)
						message = "The club you have selected does not offer a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					break;
			}
		break;
		case 'difference-hf':
			switch(emailType) {
				case 'eb':
				case 'em':
				case 'normal':
					if(jQuery.inArray(club,hafClubs) > -1)
						message = "";
					else if(jQuery.inArray(club,fitnessClubs) > -1)
						message = "The club you have selected does not offer racquets facilities or a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					else if(jQuery.inArray(club,hadClubs) > -1)
						 message = "The club you have selected does not offer a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					else 
						message = "The club you have selected also offers racquets facilities";
					break;
			}
		break;
		case 'newyou':
			switch(emailType) {
				case 'eb':
				case 'em':
				case 'normal':
					if(jQuery.inArray(club,fitnessClubs) > -1)
						message = "";
					else if(jQuery.inArray(club,hafClubs) > -1)
						 message = "The club you have selected is running a different promotion, please contact the club for details of memberships.";
					else if(jQuery.inArray(club,hadClubs) > -1)
						 message = "The club you have selected does not offer a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					else 
						message = "The club you have selected is running a different promotion, please contact the club for details of memberships";
					break;
			}
		break;
		case 'difference-hd':
			switch(emailType) {
				case 'eb':
				case 'em':
				case 'normal':
					if(jQuery.inArray(club,hadClubs) > -1)
						message = "The club you have selected does not offer a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					else if(jQuery.inArray(club,hafClubs) > -1)
						 message = "The club you have selected is running a different promotion, please contact the club for details of memberships.";
					else if(jQuery.inArray(club,fitnessClubs) > -1)
						 message = "The club you have selected does not offer racquets facilities or a three month membership, and offers membership from only £"+getClubPrice(club)+" per month.";
					else 
						message = "The club you have selected is running a different promotion, please contact the club for details of memberships";
					break;
			}
		break;
	}
	if(message.length > 0)
		showMessageHideButton(message,clubSelector);
	else
		hideMessageShowButton(clubSelector);
}

function hideMessageShowButton(clubSelector) {
	if(clubSelector == 'clubSide') {
		$("#club_info_button").hide();
	}
	else {
		$("#club_info_button").show();	
	}
	$("div#hidden_msg").html("").hide()
}

function showMessageHideButton(message,clubSelector) {
	if(clubSelector != 'clubSide') {
		$("#club_info_button").show();
	}
	else {
		$("#club_info_button").hide();	
	}
	if(message) {
		$("div#hidden_msg").html(message).show()
	}
}

function getClubPrice(club) {
	switch(club) {
		case 'kingston':
			var price = 48.50;
		break;
		case 'dundee':
			var price = 42;
		break;
		case 'hull':
			var price = 42;
		break;
		case 'leicester':
			var price = 46;
		break;
		case 'maidenhead':
			var price = 44.99;
		break;
		case 'maidstone':
			var price = 44.99;
		break;
		case 'stevenage':
			var price = 42;
		break;
		case 'solihullsouth':
			var price = 46;
		break;
	}		
	return price.toFixed(2);		
}

function changeFullClubPrice(club) {
	if(jQuery.inArray(club,fitnessClubs) > -1)
		var fullprice = 210;
	else
		var fullprice = 245;
	$("#allworth").html("").html("<h3 class='black_box'>ALL WORTH UP TO £"+fullprice+'</h3>');
	var content = $('#price_blurb .sIFR-alternate').html();
	var replaced = content.replace(/<span class="newprice">(.)+<\/span>/gi,'<span class="newprice">'+fullprice+'</span>');
	//console.log(replaced);
	$('#price_blurb').html("").html('<p class="intro_blurb">'+replaced+'</p>');
	if(typeof sIFR == "function") {
		sIFR.replaceElement("#allworth h3", named({sFlashSrc: "/static/fonts/din-medium-pound.swf", sColor: "#ffffff", sBgColor: "#b2995b", sWmode: "transparent"}));
		sIFR.replaceElement("#price_blurb p.intro_blurb", named({sFlashSrc: "/static/fonts/din-medium-pound.swf", sColor: "#ffffff", sWmode: "transparent"}));
		//sIFR.replaceElement("p.intro_blurb",              named({sFlashSrc: "/static/fonts/din-medium-pound.swf", sColor: "#FFFFFF", sWmode: "transparent"}));
	}
}


