﻿var sW = 0, sH = 0, iL = 0, iT = 0, iW = 0, iH = 0, wW = 0, wH = 0;
var gp = "gallery";

function rb() {        
    if (sW / sH < wW / wH) {
        iW = wW;
        iH = iW * sH / sW;
        iL = 0;
        iT = -Math.floor((iH - wH) / 2);
    } else {
        iH = wH;
        iW = iH * sW / sH;
        iT = 0;
        iL = -Math.floor((iW - wW) / 2);
    }

    $("#BG").css({ "width": wW + "px", "height": wH + "px" });
    $("#BG img").css({ "width": iW + "px", "height": iH + "px", "left": iL + "px", "top": iT + "px" });

}

function rc() {
    wW = $(window).width();
    wH = $(window).height();

    $("#Right").css({ "min-height": (Math.max(wH, $("#Left").height()) - 40) + "px" });
    $("#Copyright").css("top", ($("#Right").height() - ($("#PhoneNumber").height() + 20 + $("#RightContent").height() + 30)) + "px");
}

function sgi(f) {
	//$(".gallery-image .mask").hide();
	$("#GalleryImage").attr("src", "/Ti.ashx?p=" + gp + "%5c" + f + "&w=528");
    //$("#RightContent").html("<div class=\"gallery-image\"><img class=\"image\" src=\"/Ti.ashx?p=gallery%5c" + f + "&amp;w=" + ($("#RightContent").width() - 2) + "\" alt=\"image\" /><img class=\"mask\" src=\"/i/gallery-mask.png\" alt=\"\" /></div>");
}


$(function () {

	var p = window.location.href;
	if (p.indexOf(".com/") > -1) p = p.substr(p.indexOf(".com/") + 4);
	else if (p.indexOf(".uk/") > -1) p = p.substr(p.indexOf(".uk/") + 3);
	else if (p.indexOf(".biz/") > -1) p = p.substr(p.indexOf(".biz/") + 4);
	if (p.charAt(p.length - 1) != "/") p = p + "/";
	if (/^\/([a-zA-Z\-]+\/)?$/.test(p)) {
		var jqActiveLinkImg = $("#Navigation a[href='" + p + "'] img");
		jqActiveLinkImg.addClass("active").attr("src", jqActiveLinkImg.attr("src").replace("-inactive.png", ".png"));
	}


	$("#Left a img").enableIE6Transparency();
	//$("#Left a.main:gt(0) img").css("opacity", 0.6).mouseover(function () { $(this).css("opacity", 1); }).mouseout(function () { $(this).css("opacity", 0.6); });
	$("#Left a.main:gt(0) img:not(.active)").mouseover(function () { $(this).attr("src", $(this).attr("src").replace("-inactive.png", ".png")); }).mouseout(function () { $(this).attr("src", $(this).attr("src").replace(".png", "-inactive.png")); });
	$("#Copyright").css("opacity", 0.6);

	$(window).resize(function () { rc(); });

	rc();

	$("h3").css("opacity", 0.6);

	$(".menu").mouseover(function () { $(this).addClass("focus"); }).mouseout(function () { $(this).removeClass("focus"); }).click(function () { $.navigate($(this).find("a").attr("href")); });

	if ($("#GalleryThumbnails").length > 0) $("#GalleryThumbnails img:eq(0)").click();
	$("#GalleryImage").load(function () { $(".gallery-image .mask").show(); });

	$("#BG img[longdesc*='.']").load(function () {
		sW = $("#BG img").width();
		sH = $("#BG img").height();
		rb();
		$(window).resize(function () { rb(); });
	}).attr("src", "/i/backgrounds/".concat($("#BG img").attr("longdesc")));

	setTimeout(function () { $("#Copyright").css("top", ($("#Right").height() - ($("#PhoneNumber").height() + 20 + $("#RightContent").height() + 30)) + "px"); }, 50);
});
