﻿/// <reference path="jquery-1.5.1-vsdoc.js" />

$(document).ready(function () {
	var images = $("#imageloader").text().split("|");
	$.each(images, function (i) {
		var img = $.trim(images[i]);
		if (img.length > 0) {
			var src = "/Content/Images/" + img;
			$("<img/>")
				.attr("href", src)
				.load(function () {
					$("#imageloader").append(this);
				});
		}
	});

	var hash = window.location.hash;
	if (hash == "#contact") {
		showContact();
	}
});




/* Sliding Tabs
-----------------------------------------------------------*/

// Remembers the current tab between clicks
var currentTab = null;

// Toggle a specified tab
function toggle(tab) {
	// If no tabs are selected, show the selected tab
	if (currentTab == null) {
		$("#slider").height(0).show();
		showTab(tab);
		currentTab = tab;
		// If the current tab has been clicked, hide it
	} else if (currentTab == tab) {
		hideTab(true);
		currentTab = null;
		// Switch between two tabs
	} else {
		removeClasses(currentTab);
		$("#slider > .body").css("visibility", "hidden");
		showTab(tab);
		currentTab = tab;
	}
}

// Common function to remove 'on' classes from tabs
function removeClasses(tab) {
	$("#tab-" + tab + "-left").removeClass("on");
	$("#tab-" + tab + "-body").removeClass("on");
	$("#tab-" + tab + "-right").removeClass("on");
}

// Show a specified tab
function showTab(tab) {
	// Mark tab as 'on'
	$("#tab-" + tab + "-left").addClass("on");
	$("#tab-" + tab + "-body").addClass("on");
	$("#tab-" + tab + "-right").addClass("on");

	// Animate slider and insert content
	$("#slider").animate({
		height: $("#body-" + tab).height()
	}, "normal", "swing", function () {
		$("#slider > .body").css("visibility", "visible").hide();
		$("#slider > #body-" + tab).fadeIn(function () {
			$("#slider").css("height", "auto");
		});
	});
}

// Hide a specified tab
function hideTab(slide) {
	var tab = currentTab;

	if (slide) {
		$("#slider").css("height", $("#slider").height());
		$("#slider > .body").hide();
		$("#slider").slideUp("normal", function () {
			removeClasses(tab);
		});
	} else {
		$("#slider").hide();
		removeClasses(tab);
	}
}

// Scroll to the top of the page and show the contact tab
function showContact() {
	$(window).scrollTop(240);
	hideTab("support");
	toggle("contact");
}




/* Contact Form
-----------------------------------------------------------*/

function contactBegin() {
	$("#body-contact-form").html("<p>Please wait...</p>");
}

function contactFailure() {
	$("#body-contact-form").html("<p>Sorry, there was a problem sending your query - please call us on 0845 8900980 instead.</p>");
}

function contactSuccess(data) {
	$("#body-contact-form").fadeOut(function () {
		$(this).html(data).fadeIn();
	});
}
