﻿// Initialise Shadowbox
if (typeof (Shadowbox) != "undefined") {
	Shadowbox.skin.markup = '<div id="sb-container"><div id="sb-overlay"></div><div id="sb-wrapper"><div id="sb-title"><div id="sb-title-inner"></div><a id="sb-nav-close" title="{close}" onclick="Shadowbox.close()">{close}</a></div><div id="sb-body"><div id="sb-body-inner"></div><div id="sb-loading"><a onclick="Shadowbox.close()">{cancel}</a></div></div><div id="sb-info"><div id="sb-info-inner"><div id="sb-counter"></div><div id="sb-nav"><a id="sb-nav-next" title="{next}" onclick="Shadowbox.next()"></a><a id="sb-nav-play" title="{play}" onclick="Shadowbox.play()"></a><a id="sb-nav-pause" title="{pause}" onclick="Shadowbox.pause()"></a><a id="sb-nav-previous" title="{previous}" onclick="Shadowbox.previous()"></a></div><div style="clear:both"></div></div></div></div></div>';
	Shadowbox.init({
		players: ["flv", "html", "iframe"],
		overlayOpacity: 0.7/*,
		onOpen: function(el) {
			$("#shadowbox #main_title").text('FSM ' + el.gallery);
		}*/
	});
}

// Other stuff
$(function() {
	var homeRotateSpeed = 6000;
	if ($(".p-home #content ul").length > 0) {
		var rand_no = Math.floor($(".p-home #content ul li").length * Math.random());
		$(".p-home #content").tabs({
			fx: { opacity: "toggle", duration: 1200 },
			selected: rand_no
		}).tabs("rotate", homeRotateSpeed);
	}

	// Thumbnail wall
	var wallThumbs = $(".thumbnail-wall a");
	wallThumbs.append('<span style="display:none;"></span>');
	wallThumbs.hover(function() {
		wallThumbs.stop(true);
		$(this).children("span").stop(true, true);
		$(this).fadeTo("normal", 1);
		if (jQuery.support.opacity) {
			$(this).children("span").fadeIn("normal");
		} else {
			$(this).children("span").show();
		}
		$(this).parent().siblings().children("a").fadeTo("normal", 0.4);
	}, function() {
		wallThumbs.stop(true);
		$(this).children("span").stop(true, true);
		if (jQuery.support.opacity) {
			$(this).children("span").fadeOut("normal");
		} else {
			$(this).children("span").hide();
		}
		wallThumbs.fadeTo("normal", 1);
	});

	// Contact overlay
	$("#container").append('<div id="contact-overlay" style="display:none;"><h1>Contact</h1><a id="contact-close">Close</a><div id="contact-content"></div></div>');
	var toggleContact = function() {
		if ($("#contact-content").children().length == 0) {
			$.get("/contact-us-overlay.aspx", function(data) {
				$("#contact-content").html(data);
			});
		}
		if ($("#n-contact-us").hasClass("active")) {
			$("#contact-overlay").slideUp("slow");
			$("#n-contact-us").removeClass("active");
			if ($(".p-home #content ul").length > 0) {
				$(".p-home #content").tabs("rotate", homeRotateSpeed);
			}
		} else {
			$("#contact-overlay").slideDown("slow");
			$("#n-contact-us").addClass("active");
			if ($(".p-home #content ul").length > 0) {
				$(".p-home #content").tabs("rotate", null);
			}
		}
		return false;
	}
	$("#contact-close,#n-contact-us a").click(toggleContact);

	// Navigation lozenge movement
	var navTimer = null;
	$("#nav li").hover(function() {
		clearTimeout(navTimer);
		$("#header").stop(true);
		var offset = $(this).offset();
		$("#header").animate({ marginTop: (offset.top - 59) + "px" }, "slow");
	}, function() {
		navTimer = setTimeout(function() {
			$("#header").stop(true);
			var offset = $("#nav li.active").offset();
			$("#header").animate({ marginTop: (offset.top - 59) + "px" }, "slow");
		}, 1000);
	});

	// Latest News
	if ($(".news-wrapper").length > 0) {
		$(".news-wrapper").jcarousel({
			vertical: true,
			scroll: 4,
			animation: 1000
		});
	}

	if (jQuery.fn.supersleight) {
		$("#header, .thumbnail-wall a").supersleight({ shim: '/images/x.gif' });
	}
});