﻿var last = "lrg1";
$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent);
$(document).ready(function() {
    if ($.browser.msie6) {
        $("#nav").css("position", "absolute");
    } else {
        $("#nav").css("position", "fixed").css("top", "auto");
    }
    $(window).scroll(function() {
        fixNav();
    });
    $(window).resize(function() {
        fixNav();
    });
    $(".tour").click(function() {
        showTour(this);
        return false;
    });
    fixNav();
    $("#thumbs a").click(function() {
        var lid = this.href.split("/");
        var iid = lid[lid.length - 1].replace(".jpg", "");
        if (iid !== last) {
            if ($("#" + iid).length) {
                //                window.console.log("test");
                $("#largeimg img:not(#loader)").css("z-index", "1");
                $("#" + iid).hide().css("z-index", "10").fadeIn(function() {
                    $("#largeimg img:not(#largeimg img#" + iid + ", #largeimg img#loader)").hide();
                });
            } else {
                var t = setTimeout("$('#loader').show();", 250);
                $nimg = $("<img/>").hide().attr("src", this.href).attr("id", iid).appendTo("#largeimg");
                $nimg.load(function() {
                    clearTimeout(t);
                    $('#loader').hide();
                    $("#largeimg img:not(#loader)").css("z-index", "1");
                    $nimg.css("z-index", "10").fadeIn(function() {
                        $("#largeimg img:not(#largeimg img#" + iid + ", #largeimg img#loader)").hide();
                    });
                });
            }
            last = iid;
        }
        return false;
    });

    $(".appointments").click(function() {
        popUp(this);
        return false;
    });
        $(".showpanel").click(function() {
            $(this).toggleClass("showpanel-show");
            //$("#nav").animate({ top: "+=" + $("#" + this.id + "-pnl").height() + "px" });

            //alert(fixNav());
            if (!fixNav()) {
                $("#nav").css("position", "relative").css("top", "0");
                $("#" + this.id + "-pnl").slideToggle(function() {
                    if ($.browser.msie6) {
                        $("#nav").css("position", "absolute");
                    } else {
                        $("#nav").css("position", "fixed").css("top", "auto");
                    }
                    fixNav();
                });
            } else {
                $("#" + this.id + "-pnl").slideToggle(function() {
                    fixNav();
                });
            }
        });
if ($(".home").length){
	
	popUp2("pdf/18thanniv.pdf")
}
});
function fixNav() {
    var docked = false;
    var scrolloffset = (($("#wrapper").height()) - 14) - $(window).height();
    // $("#debug").html("wrapper: " + $("#wrapper").height() + "<br />window: " + $(window).height()  + "<br />offset: " + scrolloffset + "<br />Top: " + $(this).scrollTop());
    if ($(window).scrollTop() >= scrolloffset) {
        if ($.browser.msie6) {
            $("#nav").css("top", ($("#wrapper").height() - 37) + "px");
        } else {
            $("#nav").css("bottom", ($(this).scrollTop() - scrolloffset) + "px");
        }
    } else {
        if ($.browser.msie6) {
            $("#nav").css("top", ($(window).height() + $(this).scrollTop()) - 23 + "px");
        } else {
            $("#nav").css("bottom", "0px");
        }
        docked = true;
    }
    return docked;
}

function popUp(link) {
    var left = (screen.width / 2) - 430;
    var top = (screen.height / 2) - 290;
    window.open(link.href, "booking", "scrollbars = 1, location = 0, width = 860, height = 580, left = " + left + ", top = " + top);
}

function popUp2(promo) {
    var left = (screen.width / 2) - 430;
    var top = (screen.height / 2) - 290;
    window.open(promo, "booking", "scrollbars = 1, location = 0, width = 510, height = 710, left = " + left + ", top = " + top);
}


function showTour(link) {
    var left = (screen.width / 2) - 375;
    var top = (screen.height / 2) - 275;
    window.open(link.href, link.id, "scrollbars = 0, location = 0, width = 500, height = 400, left = " + left + ", top = " + top);
}

