﻿/// <reference path=/common/library/javascript/jquery/jquery-1.4.1-vsdoc.js />

var SLH = window.SLH ||
{};
SLH.Main = {};
SLH.Main = (function() {

	var emailValidator = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

	function init() {
		dropDownListEvent();
		mainImageSlideShow();
		//sifrReplace();
		contentTabs();
		registrationForm();
		forgottenPassword();
	}

	function dropDownListEvent() {
		$(".dropdown").change(function(e) {
			var selectedValue = $(this).val();
			$(this).next("input[type=hidden]").val(selectedValue);
		});
	}

	function mainImageSlideShow() {
		var slideshowEngine = new imageslideshowEngine();
		slideshowEngine.images = $(".main_image_container img").get();
		slideshowEngine.init(6000, 2000, mainImageSwitched);
	}

	function mainImageSwitched(i) {
		if ($(".caption_container .each").size() > 0) {
			$(".caption_container .each").fadeOut("slow", function() {
				setTimeout(function() { $(".caption_container .each").eq(i.to).fadeIn("slow"); }, 1000);
			});
		}
	}

	function sifrReplace() {
		$(".subtitle").sifr({
			font: "/common/template/flash/scala_sans_lf_caps.swf",
			build: 436,
			version: 3,
			height: 30,
			width: 600
		});
		$(".title").sifr({
			font: "/common/template/flash/scala_sans_lf_caps.swf",
			build: 436,
			version: 3,
			height: 30,
			width: 600
		});
	}

	function contentTabs() {
		$(".tabs_header_container a").click(function(e) {
			var sender = $(this);
			var currentIndex = $(".tabs_header_container a").index(sender);
			var target = $(".content_tabs").find(".each").eq(currentIndex);
			$(".content_tabs").find(".each").hide();
			$(target).show();

			$(".tabs_header_container").find(".item").removeClass("active");
			$(".tabs_header_container a").eq(currentIndex).parent().addClass("active");
			e.preventDefault();
		});
	}

	function registrationForm() {
		//Put the values from the hiddenfields back on postback (if the failed the validation)
		$(".dropdown").each(function(e) {
			var sender = $(this);
			var selectedValue = $(this).next("input[type=hidden]").val();
			$(sender).val(selectedValue);
		});
	}

	function forgottenPassword() {
		$(".forgotten_password_button").click(function(e) {
			var email = $(".forgotten_password_textbox").val();
			if (!emailValidator.test(email)) {
				e.preventDefault();
				return false;
			}
		});
	}

	function validateEmail(value) {
		if (!emailValidator.test(value)) {
			return false;
		}
		return true;
	}

	return {
		init: init
	};
})();
$(document).ready(SLH.Main.init);
