﻿// JAVASCRIPT FUNCTIONS: ////////////////////////



// JQUERY FUNCTIONS: ////////////////////////
$(document).ready(function() {
    
    screenSizer();    
    
     jQuery.preloadImages = function() {
         for (var i = 0; i < arguments.length; i++) {
             jQuery("<img>").attr("src", arguments[i]);
         }
     }
    
    $("#showEditables").click(function() {
        $(".editableDisplay, .editableDisplay p").animate({ backgroundColor: "yellow" }, 100)
        .animate({ backgroundColor: "#222222" }, 1400);

        setTimeout(function() {
            $(".editableDisplay, .editableDisplay p").css("background-color", "Transparent");
        }, 1550);
    });

    $("#showEditablesImages").click(function() {
        $(".editableDisplay img, .editableDisplay a.pagenav").css({ "border": "1px solid yellow" });
        setTimeout(function() {
            $(".editableDisplay img, .editableDisplay a.pagenav").css("border", "none");
        }, 1500);
    });

    //Hotel search:
    $("#LinkHotelSearch").click(function() {
        $(this).toggleClass("HotelSearch_on");
        $("#PanelHotels").slideToggle(500);
    });

    //Clear search field on click
    $("#search > input:not(.themeBG)").click(function() {

    });

    // Clear textbox on click:
    $(".subscribe_txt").focus(function() {
        if ($(this).val() == "Name" || $(this).val() == "E-mail address") { $(this).val("") }
    });

    $.preloadImages(["/Images/bg_bookbistro.gif", "/Images/bg_twist.jpg", "/Images/bg_bookbistro.jpg", "/Images/bg_bookrbistro.gif", "/Images/bg_bookroom.gif",
                    "/Images/bg_bookroom.jpg", "/Images/bg_careers.gif", "/Images/bg_careers.jpg", "/Images/bg_ecole.gif", "/Images/bg_ecole.jpg",
                   "/Images/bg_home.gif", "/Images/bg_home.jpg", "/Images/bg_home_new.gif", "/Images/bg_home_new.jpg", "/Images/bg_home_valentine.jpg",
                    "/Images/bg_hotels.gif", "/Images/bg_hotels.jpg", "/Images/bg_imagelibrary.gif", "/Images/bg_imagelibrary_top.gif", "/Images/bg_twist.gif"]);

    // Homecoming open and shuts:
    $(".showDate_text").hide();
    $(".showDate").click(function() {
        $(".showDate_text").slideUp();
        $(".showDate").removeClass("showDate_on");
        $("#" + this.id).parent().next("div").slideToggle();
        $("#" + this.id).addClass("showDate_on");
    });

    $("#awards li div").hide();
    $(".awardstable").parent().hide();

    $("#awards li").click(function() {
        $("#awards li").removeClass("on");
        $("#awards li div").slideUp(400);

        $("#" + this.id + " div").slideDown(400);
        $("#" + this.id).addClass("on");
    });
    $(".showtable").click(function() {
        $(".awardstable").parent().slideUp(400);
        $("#" + this.id).next("div").slideDown(400);
    });

});


function screenSizer() {
    var heightWindow = $(window).height();
    var heightDocument = $(document).height();
    var heightFooter = $("#Footer").height();
    var heightWrap = $(".Wrap").height()

    if (heightWindow >= heightDocument) {
        heightFooter += (heightWindow - heightWrap);
        $("#Footer").height(heightFooter);
    }
}



/*
JSTarget function by Roger Johansson, www.456bereastreet.com
*/
var JSTarget = {
    init: function(att, val, warning) {
        if (document.getElementById && document.createElement && document.appendChild) {
            var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
            var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
            var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
            var arrLinks = document.getElementsByTagName('a');
            var oLink;
            var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
            for (var i = 0; i < arrLinks.length; i++) {
                oLink = arrLinks[i];
                if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
                    oLink.onclick = JSTarget.openWin;
                }
            }
            oWarning = null;
        }
    },
    openWin: function(e) {
        var event = (!e) ? window.event : e;
        if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
        else {
            var oWin = window.open(this.getAttribute('href'), '_blank');
            if (oWin) {
                if (oWin.focus) oWin.focus();
                return false;
            }
            oWin = null;
            return true;
        }
    },
    /*
    addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
    */
    addEvent: function(obj, type, fn) {
        if (obj.addEventListener)
            obj.addEventListener(type, fn, false);
        else if (obj.attachEvent) {
            obj["e" + type + fn] = fn;
            obj[type + fn] = function() { obj["e" + type + fn](window.event); }
            obj.attachEvent("on" + type, obj[type + fn]);
        }
    }
};
JSTarget.addEvent(window, 'load', function() { JSTarget.init("rel", "external"); });

function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}