﻿var OurHotels = new function() {

    var me = this;

    this.ShowGeographyLevel3 = function(GeographyLevel3ID) {
        ff.Call("GetGeographyLevel3Hotels", function(s) { OurHotels.Display(s); }, GeographyLevel3ID);

        f.SetHTML('h2HotelHeader', 'Our Hotels in ' + f.GetObject('aG_' + GeographyLevel3ID).innerHTML);
        var oSelected = f.GetElementsByClassName('a', 'selected', 'divDestinations');
        if (oSelected.length > 0) { f.RemoveClass(oSelected[0], 'selected'); }
        f.SetClass('aG_' + GeographyLevel3ID, 'selected');

    }

    this.Display = function(sHTML) {
        f.SetHTML('divHotelContent', sHTML);
        me.SetDivLinks();
    }

    this.SetDivLinks = function() {

        var aLinks = f.GetObjectsByIDPrefix('a_', 'a', 'divHotelContent');
        var oDiv;
        for (var i = 0; i < aLinks.length; i++) {
            oDiv = f.GetObject('div_' + aLinks[i].id.split('_')[1]);
            f.AttachEvent(oDiv, 'click', function(o) { OurHotels.DivClick(f.GetObjectFromEvent(o)); });
        }
    }

    this.DivClick = function(oDiv) {
        while (oDiv.nodeName != 'DIV') {
            oDiv = oDiv.parentNode;
        }
        var aLink = f.GetObject('a_' + oDiv.id.split('_')[1]);
        window.location = aLink.href;
    }
}