var outRigPage;
jQuery(document).ready(function () {
    //jQuery(document).domain = "outrigger.com";

    function OutRigger() {
        var iNavMgr = new internalNavManager();
        var currencyPopupConfig = {
            url: '/layouts/Outrigger/Reservations/CurrencyConverter.aspx',
            width: '385',
            height: '340'
        };

        //	signup config
        var signupPopupConfig = {
            width: 420,
            height: 385,
            scrolling: '1'
        };
        //	+HELP
        var helpPopupConfig = {
            width: '610',
            height: '650',
            scrolling: '1'
        };
        var printPopupConfig = {
            width: '800',
            height: '700'
        };
        var propertyDetailsPopupConfig = {
            width: '729',
            height: '700'
        };
        var dpConfig = {
            numberOfMonths: 2,
            changeMonth: true,
            closeText: 'Close',
            showOtherMonths: true,
            minDate: 0,
            maxDate: "+1y"
        };

        var smallDialogWidth = 415;
        var mediumDialogWidth = 560;
        var largeDialogWidth = 729;
        var photoDialogWidth = 464;
        var maxDialogHeight = 500;
        var dialogHeight = 500;
        var dialogCloseText = 'Close';
        var inavParamName = 'inav';
        var iNavLinks = {};
        this.initPage = function () {

            /*	--------- 		INIT Calls	---------	 */

            if (typeof (jsonLinkByHref) != "undefined") {
                this.initOmnitureLinks();
            }

            //Apply pngfix to .ashx files if IE6
            var ua = navigator.userAgent;
            var ie = /MSIE/.test(ua) && ua.replace(/.*?MSIE (.).*/, "$1");
            if (ie && ie == 6) {
                jQuery('img[src$=".ashx?png=1"]').each(function () {
                    var cls = jQuery(this).attr('class');
                    if (cls.length) cls += ' ';
                    cls += 'pngfix';
                    jQuery(this).attr('class', cls);
                });
            }

            //	Head navigation
            this.initHeadNav();

            this.initGlobal();

            //	Booking Widget
            if (jQuery('.con-book').length) {
                this.initBookingWidget();
            }

            //	List Property
            if (jQuery('.con-list-property').length) {
                this.initPropertyList();
            }

            //	Select Room
            if (jQuery('.con-select-room').length) {
                this.initRoomList();
            }

            // Compare Properties
            //if (jQuery('.con-comparison-properties-details').length) {
            //    this.initCompareProperties(); 
            //}

            //	Currency Converter
            if (jQuery('.con-currency-converter').length) {
                this.initCurrencyConverter();
            }

            //	Guest information forms
            if (jQuery('.con-guest-info').length || jQuery('.con-review-reservation').length
                || jQuery('.con-confirmation').length) {
                this.initGuestForms();
            }

            // Photo Gallery
            if (jQuery('.property-detail-picture-nav').length) {
                this.initPhotoGallery();
            }

            //	Property detail page PROP-DETAIL
            if (jQuery('.con-prop-detail').length) {
                this.initPropDetail();
                this.initPropertyList();
            }

            // Destination Landing Page
            if (jQuery('.con-dest-land').length) {
                this.initDestDetail();
                this.initDestSpecials();
                this.initWhereToStay();
            }

            // Specials Landing Page
            if (jQuery('.con-spec-land').length) {
                this.initSpecials();
            }

            // Event Landing Page
            if (jQuery('.filter-dest-fld').length && jQuery('.filter-prop-fld').length) {
                this.initArticleFilter();
            }

            //Explore Category Articles
            if (jQuery('.blog-list-header').length) {
                this.initCategoryArticles();
            }

            //Older Posts Rail Widget
            if (jQuery('.old-posts-content').length) {
                this.initOldPostWidget();
            }

            //Press Release Landing
            if (jQuery('.con-press-release-land').length) {
                this.initPressReleaseLanding();
            }

            //Press Release Sign Up
            if (jQuery('.con-press-release-sign-up').length) {
                this.initPressRelease();
            }

            //Country and State Dropdown Lists
            if (jQuery('.con-country-state-lists').length) {
                this.initCountryStateLists();
            }
            // help
            if (jQuery('.con-help').length) {
                this.initCurrencyConverter();
                //  Remove left pipe from last nav item
                jQuery('.con-help .prop-nav ul li:last').css('background-image', 'none');
            }
            if (jQuery('.prop-nav ul').length) {
                iNavMgr.init('.prop-nav ul', '.mod-nav-3', '.menu-nav ul', inavParamName, '.con-selected-tab');
                // Make background blue
                jQuery('body').css('background-color', '#c6e0ea');
            }
            if (jQuery('.mod-guest-info.profile').length) {
                //  Country - state in edit profile
                jQuery('.js-country-fld').change(function () { updateStateOpt(jQuery('.js-country-fld'), jQuery('.js-state-fld')); });
            }
            /*  After Delete profile dialog */
            if (jQuery('.js-dialog-after-delete').length) {
                handleAfterDeleteDialog();
            }
            /* Video Content Tile */
            if (jQuery('.mod-video-tile').length) {
                this.initVideoContentTiles();
            }
            /* Image rotators */
            if (jQuery('.no-flash').length) {
                jQuery('.no-flash').each(function () {
                    jQuery(this).click(function (e) {
                        e.preventDefault();
                        window.open("http://get.adobe.com/flashplayer/");
                    });
                });
            }
            /* Links to another tab within same tabbed content page */
            if (jQuery('.js-internal-tab-link').length) {
                jQuery('.js-internal-tab-link').click(function () {
                    jQuery('li a[href=' + jQuery(this).attr("href") + ']').trigger('click');
                });
            }
            /* Request a meeting form */
            if (jQuery('.con-location-ddl').length) {
                this.initRequestMeeting();
            }
            /*  Hide any user message on submit */
            if (jQuery('.js-hide-onsubmit').length) {
                jQuery('.btn-submit').click(function () { jQuery('.js-hide-onsubmit').hide(); });
            }
            /* Print Share Toolbar */
            if (jQuery('.js-print-params').length && jQuery('.print-ico').length) {
                //Append any additional print querystring params to print button href
                var href = jQuery('.print-ico').attr('href');
                jQuery('.print-ico').attr('href', href + jQuery('.js-print-params').html());
            }
            /*TA points*/
            if (jQuery('.ta-hdr-reward-points').length && jQuery('input[id$=\'hdnTravelAgentRewardPoints\']').length) {
                jQuery('.ta-hdr-reward-points').html(jQuery('input[id$=\'hdnTravelAgentRewardPoints\']').val());
            }
            /*TA login poller*/
//            if (jQuery('.con-ta-login').length) {
//                this.initLoginPoller();
//            }

        };
        //	Main menu behavior
        var menuExpand = function () {
            jQuery("a.nav-level-0-link:first, ul:first", jQuery(this)).addClass('js-hover');
            ie7MenuFix(this);
        };
        var menuCollapse = function () {
            jQuery("a.nav-level-0-link:first, ul:first", jQuery(this)).removeClass('js-hover');
        };
        //	Main menu Hover Intent configuration
        //        var menuHIConfig = {
        //            over: menuExpand, // function = onMouseOver callback (REQUIRED)
        //            timeout: 0, // number = milliseconds delay before onMouseOut    
        //            out: menuCollapse // function = onMouseOut callback (REQUIRED)    
        //        };
        /*
        * openCurrencyConverter(p)
        *
        * p {string} Parameters to append to the popup URL
        *
        * Displays new window, popup style
        */
        var openCurrencyConverter = function (p) {
            window.open(currencyPopupConfig.url + "?" + p, "currencyConverter", "height=" + currencyPopupConfig.height + ",width=" + currencyPopupConfig.width);
        }
        //	update Events List in property detail page using ajax
        var updateEvents = function () {
            var eventDate = jQuery('.mod-events .event-date-fld').datepicker("getDate");
            eventDate.setHours(0);
            eventDate.setMinutes(0);
            eventDate.setSeconds(0);
            eventDate.setMilliseconds(0);
            var newHTML = "";

            // Retreive JSON events
            var jsonObject = null;
            if (typeof (jsonEvents) == "undefined") {
                var eventMissingMsg = typeof (noEventsMsg) != "undefined" ? noEventsMsg : "";
                newHTML += '<tr><td class="event-time">&nbsp;</td><td>' + eventMissingMsg + '</td></tr>';
            }
            else {
                jsonObject = jsonEvents;

                for (var i = 0; i < jsonObject.length; i++) {
                    var startValues = jsonObject[i].StartDate.split('/');
                    var startDate = new Date();
                    startDate.setFullYear(startValues[2], startValues[0] - 1, startValues[1]);
                    startDate.setHours(0);
                    startDate.setMinutes(0);
                    startDate.setSeconds(0);
                    startDate.setMilliseconds(0);

                    var endValues = jsonObject[i].EndDate.split('/');
                    var endDate = new Date();
                    endDate.setFullYear(endValues[2], endValues[0] - 1, endValues[1]);
                    endDate.setHours(0);
                    endDate.setMinutes(0);
                    endDate.setSeconds(0);
                    endDate.setMilliseconds(0);

                    //Only show events that are valid for the selected date
                    if (startDate <= eventDate && endDate >= eventDate) {
                        newHTML += '<tr><td class="event-time">' + jsonObject[i].Time + '</td><td><a href="' + jsonObject[i].Url + '">' + jsonObject[i].Title + '</a><br />' + jsonObject[i].Location + '</td></tr>';
                    }
                }
                if (newHTML.length === 0) {
                    var eventMissingMsg = typeof (noEventsMsg) != "undefined" ? noEventsMsg : "";
                    newHTML += '<tr><td class="event-time">&nbsp;</td><td>' + eventMissingMsg + '</td></tr>';
                }
            }

            table = jQuery('.mod-events .table-contents table').html(newHTML);
            jQuery('.mod-events .table-contents table tr:last td').css('border-bottom', 'none');
        }
        /*
        * function updateStateOpt
        * @param field1 {object} select box that changed
        * @param field1 {object} select box to be populated
        * 		Read options from configuration object, populate level 2
        * 		select box        
        */
        var updateStateOpt = function ($field1, $field2) {
            //	Retrieve default text
            var stateProvDefaultText = (jQuery('option', $field2).length >= 1) ? jQuery('option:first', $field2).text() : "...";

            // Retreive JSON country and state data
            if (typeof (jsonCountries) === "undefined") {
                return;
            }
            var listItems = '<option value="0">' + stateProvDefaultText + '</option>';
            $field2.html("");

            if (jsonCountries[$field1.val()] !== undefined) {
                var stateObj = jsonCountries[$field1.val()].states;
                if (stateObj) {
                    for (var i = 0; i < stateObj.length; i++) {
                        listItems += "<option value='" + stateObj[i].code + "'>" + stateObj[i].name + "</option>";
                    }
                }
            }
            $field2.html(listItems);
        }

        /*
        METHODS 		 					***********************************
        */

        /*
        onShareClose()
        Clear validators and form fields from share itinerary dialog when closing it
        */
        var onShareClose = function () {
            jQuery('input[type=text], textarea', jQuery('.js-dialog-share-email')).val('');
            jQuery('.glb-validation-summary', jQuery('.js-dialog-share-email')).hide();
            jQuery('.validator-inline-msg', jQuery('.js-dialog-share-email')).hide();
        };
        this.initOmnitureLinks = function () {
            jQuery.each(jsonLinkByHref, function (i, v) {
                if (jQuery('a[href$="' + v.Key + '"]').length) {
                    jQuery('a[href$="' + v.Key + '"]').live("click", function () { eval(v.Value); });
                }
            });
            jQuery.each(jsonLinkByClass, function (i, v) {
                if (jQuery('.' + v.Key) != undefined) {
                    jQuery('.' + v.Key).live("click", function () { eval(v.Value); });
                }
            });
        }
        this.initDetailPhotoGallery = function () {
            updateDetailPhotoGallery(0);
            updateDetailVideoGallery(0);
            initFullscreenVideoDialog('.js-dialog-video');

            jQuery('.nextPhoto').click(function (e) {
                e.preventDefault();
                updateDetailPhotoDialog(jQuery(this).attr('value'));
            });

            jQuery('.previousPhoto').click(function (e) {
                e.preventDefault();
                updateDetailPhotoDialog(jQuery(this).attr('value'));
            });

            jQuery('.con-remote-video img').each(function () {
                var $iframeContainer = jQuery(this).parent().parent().parent().siblings('.con-remote-video-div');
                var $iframe = $iframeContainer.find('iframe');
                var dialogRemoteVideo = $iframeContainer.dialog({
                    bgiframe: true,
                    autoOpen: false,
                    modal: true,
                    dialogClass: 'VTour',
                    position: 'center',
                    closeText: dialogCloseText,
                    width: Number($iframe.attr('width')),
                    height: Number($iframe.attr('height')),
                    open: function (event, ui) {
                        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                            jQuery('select').css('visibility', 'hidden');
                        }
                    },
                    close: function (ev, ui) { $iframe.attr('src', ''); jQuery('select').css('visibility', 'visible'); }
                });

                jQuery(this).click(function (e) {
                    e.preventDefault();
                    $iframe.attr('src', jQuery(this).attr('value'));
                    dialogRemoteVideo.dialog('open');
                });
            });

        };
        var updateDetailPhotoGallery = function (currentIndex) {

            var prop;
            if (jQuery('.nextPhoto', jQuery('.js-dialog-photo')).attr('rel') !== undefined) {
                prop = jQuery('.nextPhoto', jQuery('.js-dialog-photo')).attr('rel');
            }

            // Retreive JSON imgages;
            if (prop !== undefined && jsonImages[prop] !== undefined) {
                jsonObject = jsonImages[prop];
            }
            else {
                jsonObject = jsonImages;
            }

            var numItemsPerPage = 12;

            //Add results stats
            var remainingImgs = jsonObject.length - currentIndex;
            var numImgsOnPage = (Number(remainingImgs) < numItemsPerPage) ? remainingImgs : numItemsPerPage;
            var photoNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastPhotoInPage = (jsonObject.length > 0) ? Number(numImgsOnPage) + photoNumber - 1 : 0;
            //jQuery('.con-photo-gallery-results').html(photoNumber + ' - ' + lastPhotoInPage + ' of ' + jsonObject.length + ' results');

            updatePagingLinks(jsonObject.length, currentIndex, lastPhotoInPage, updateDetailPhotoGallery, numItemsPerPage, ".con-photo-gallery");

            //Add Images
            var newHTML = "";
            for (var i = 0; i < numImgsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                newHTML += '<a href="javascript:void();"><img class="photo-detail" src="' + jsonObject[index].Src + '" title="' + jsonObject[index].Alt + '" alt="' + jsonObject[index].Desc + '" value="' + index + '" width="150" height="102" /></a>';
            }
            jQuery('.photo-thumb-grid').html(newHTML);

            //Add click handler to new images
            jQuery('.photo-thumb-grid img').click(function () {

                updateDetailPhotoDialog(jQuery(this).attr('value'), prop, jQuery('.' + prop + "-context"));
                var dialogPhoto = jQuery('.js-dialog-photo').dialog({
                    bgiframe: true,
                    modal: true,
                    closeText: dialogCloseText,
                    width: photoDialogWidth,
                    open: function (event, ui) {
                        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                            jQuery('select').css('visibility', 'hidden');
                        }
                    },
                    close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
                });
            });
        };
        var updateDetailVideoGallery = function (currentIndex) {

            // Retreive JSON imgages
            var jsonObject = null;
            if (typeof (jsonVideos) == "undefined") { return; }
            jsonObject = jsonVideos;
            var numItemsPerPage = 12;

            //Add results stats
            var remainingImgs = jsonObject.length - currentIndex;
            var numImgsOnPage = (Number(remainingImgs) < numItemsPerPage) ? remainingImgs : numItemsPerPage;
            var photoNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastPhotoInPage = (jsonObject.length > 0) ? Number(numImgsOnPage) + photoNumber - 1 : 0;
            //jQuery('.con-video-gallery-results').html(photoNumber + ' - ' + lastPhotoInPage + ' of ' + jsonObject.length + ' results');

            updatePagingLinks(jsonObject.length, currentIndex, lastPhotoInPage, updateDetailVideoGallery, numItemsPerPage, ".con-video-gallery");

            //Add Images
            var newHTML = "";
            for (var i = 0; i < numImgsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                newHTML += '<a href="#"><img src="' + jsonObject[index].Thumbnail + '" title="' + jsonObject[index].Alt + '" name="' + jsonObject[index].Title + ',' + jsonObject[index].Runtime + '" alt="' + jsonObject[index].Alt + '" value="' + index + '" video="' + jsonObject[index].Src + '" width="150" height="102" /></a>';
            }
            jQuery('.video-thumb-grid').html(newHTML);

            //Add click handler to new images
            jQuery('.video-thumb-grid img').click(function () {
                if (jQuery('.js-dialog-video').length) {
                    showFullScreenVideoDialog(jQuery(this).attr('video'), jQuery(this).attr('src'), jQuery(this).attr('alt'), "fullscreenVideo", '.js-dialog-video', true);
                }
            });
        };
        this.showImageRotatorFullScreenVideo = function (videoPath, imagePath, title, embedSwfElementName, dialogContentElementClass) {
            showFullScreenVideoDialog(videoPath, imagePath, title, embedSwfElementName, dialogContentElementClass, false);
        };
        var showFullScreenVideoDialog = function (videoPath, imagePath, title, embedSwfElementName, dialogContentElementClass, showTime) {

            if (title == null || String(title).length == 0) {
                title = " ";
            }

            var sShowTime = "false";
            if (showTime == true) {
                sShowTime = "true";
            }

            var params = {};
            params.menu = "false";
            params.scale = "noscale";
            params.bgcolor = "#ffffff";
            params.wmode = "transparent";

            var attributes = {};
            attributes.align = "middle";

            var flashvars = {};
            flashvars.filePath = videoPath;
            flashvars.posterPath = imagePath;
            flashvars.autoPlay = 'true';
            flashvars.fullScreen = 'false';
            flashvars.time = sShowTime;
            flashvars.title = title;

            var dialogPhoto = jQuery(dialogContentElementClass).dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                closeText: dialogCloseText,
                width: 'auto',
                height: 'auto',
                position: 'center',
                resizable: true,
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery(this).dialog('destroy'); jQuery('select').css('visibility', 'visible'); }
            });

            swfobject.embedSWF("/swfs/OutriggerVideoPlayer.swf", embedSwfElementName, "928", "522", "10.0.0", "/swfs/expressInstall.swf", flashvars, params, attributes);

            dialogPhoto.parent().css('text-align', 'right'); //Fix close button alignment in IE7
            dialogPhoto.dialog('open');
        };
        var initFullscreenVideoDialog = function (embedSwfElementName) {
            var params = {};
            params.menu = "false";
            params.scale = "noscale";
            params.bgcolor = "#ffffff";
            params.wmode = "transparent";

            var attributes = {};
            attributes.align = "middle";

            var playerFlashvars = {};
            playerFlashvars.filePath = '';
            playerFlashvars.posterPath = '';
            playerFlashvars.autoPlay = 'true';
            playerFlashvars.fullScreen = 'false';
            playerFlashvars.time = false;
            playerFlashvars.title = '';
            swfobject.embedSWF("/swfs/OutriggerVideoPlayer.swf", "fullscreenFlashDiv", "928", "522", "10.0.0", "/swfs/expressInstall.swf", playerFlashvars, params, attributes);
        };
        var updatePagingLinks = function (numItems, currentIndex, lastItemInPage, pagingUpdateResultsFunction, numItemsPerPage, parentClass) {

            if (parentClass.length == 0) {
                parentClass = ".mod-article-list";
            }

            //Add paging links, if we haven't already
            var pages = Math.ceil(numItems / numItemsPerPage);
            if (jQuery(parentClass).find('.con-gallery-page-link').length == 0 && pages > 1) {

                //Numbered Page Links
                var pagesHTML = "";
                for (var j = 0; j < pages; j++) {
                    var aClass = (j == 0) ? 'con-gallery-page-link active' : 'con-gallery-page-link';
                    pagesHTML += '<a class="' + aClass + '" href="#" value="' + Number(j * numItemsPerPage) + '">' + Number(j + 1) + '</a> ';
                }
                jQuery(parentClass).find('.datepicker-month-arrow-right').before(pagesHTML);

                jQuery(parentClass).find('.con-gallery-page-link').click(function (e) {
                    e.preventDefault();
                    jQuery(parentClass).find('.con-gallery-page-link').attr('class', 'con-gallery-page-link');
                    jQuery(this).attr('class', 'con-gallery-page-link active');
                    pagingUpdateResultsFunction(jQuery(this).attr('value'));
                    //	scroll up to the top of the list (and just a little beyond)
                    jQuery(window).scrollTop(jQuery(parentClass).offset().top - 20);
                });

                //Previous Page Arrow Click Handler
                jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-left').click(function (e) {
                    e.preventDefault();
                    var newIndex = Number(jQuery(this).attr('value'));
                    var counter = 0;
                    jQuery(parentClass).find('.thumb-page-nav').children('.con-gallery-page-link').each(function () {
                        var aClass = (newIndex == counter * numItemsPerPage) ? 'con-gallery-page-link active' : 'con-gallery-page-link';
                        jQuery(this).attr('class', aClass);
                        counter++;
                    });
                    pagingUpdateResultsFunction(jQuery(this).attr('value'));
                    //	scroll up to the top of the list (and just a little beyond)
                    jQuery(window).scrollTop(jQuery(parentClass).offset().top - 20);
                });

                //Next Page Arrow Click Handler
                jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-right').click(function (e) {
                    e.preventDefault();
                    var newIndex = Number(jQuery(this).attr('value'));
                    var counter = 0;
                    jQuery(parentClass).find('.thumb-page-nav').children('.con-gallery-page-link').each(function () {
                        var aClass = (newIndex == counter * numItemsPerPage) ? 'con-gallery-page-link active' : 'con-gallery-page-link';
                        jQuery(this).attr('class', aClass);
                        counter++;
                    });
                    pagingUpdateResultsFunction(jQuery(this).attr('value'));
                    //	scroll up to the top of the list (and just a little beyond)
                    jQuery(window).scrollTop(jQuery(parentClass).offset().top - 20);
                });
            }

            //Set values for previous and next page arrows
            var prevPageIndex = currentIndex - numItemsPerPage;
            if (prevPageIndex < 0) {
                prevPageIndex = numItems - (numItems - ((pages - 1) * numItemsPerPage));
            }

            var nextPageIndex = (lastItemInPage + 1 > numItems) ? 0 : lastItemInPage;
            jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-left').attr('value', prevPageIndex);
            jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-right').attr('value', nextPageIndex);

            if (numItems == 0 || pages == 1) {
                jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-left').hide()
                jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-right').hide();
            }
            else {
                jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-left').show()
                jQuery(parentClass).find('.thumb-page-nav').children('.datepicker-month-arrow-right').show();
            }

            //Set values of any fields that track the currently visible indicies
            var currentItemNumber = (numItems > 0) ? Number(currentIndex) + 1 : 0;
            jQuery(parentClass).find('.page-nav-first-index').html(currentItemNumber);
            jQuery(parentClass).find('.page-nav-last-index').html(lastItemInPage);
            jQuery(parentClass).find('.page-nav-total-results').html(numItems);
        };
        /*
        *   updateDetailPhotoDialog (index, prop, $context)
        *   @param index {integer}  Current position within images array
        *   @param prop {string}    Optional. Property code ("OEH", etc)
        *   @param $context {jQuery Object} Optional. DOM element that contains the gallery (default: '.js-dialog-photo')        
        */
        var updateDetailPhotoDialog = function (index, prop, $context) {

            // Retreive JSON imgages
            var jsonObject = null;
            if (typeof (jsonImages) == "undefined") { return; }
            if (prop !== undefined && jsonImages[prop] !== undefined) {
                jsonObject = jsonImages[prop];
            }
            else {
                jsonObject = jsonImages;
            }
            if ($context === undefined) {
                $context = jQuery('.js-dialog-photo');
            }

            if (jsonObject[index] === undefined) { return; }
            var title = jsonObject[index].Title;
            if (title == null || title == '') { title = '&nbsp;'; }
            var desc = jsonObject[index].Desc;
            if (desc == null || desc == '') { desc = '&nbsp;'; }
            var src = jsonObject[index].Src;
            jQuery('.js-img-title', $context).html(title);
            jQuery('.js-img-text', $context).html(desc);
            jQuery('.js-img-large', $context).attr('src', src);

            var photoNumber = Number(index) + 1;
            //var photoStats = 'Photo ' + photoNumber + ' of ' + jsonObject.length;
            jQuery('.con-photo-number', $context).html(photoNumber);
            jQuery('.con-photo-total', $context).html(jsonObject.length);

            var nextIndex = (Number(index) == jsonObject.length - 1) ? 0 : Number(index) + 1;
            jQuery('.nextPhoto', $context).attr('value', nextIndex);

            var prevIndex = (Number(index) == 0) ? jsonObject.length - 1 : Number(index) - 1;
            jQuery('.previousPhoto', $context).attr('value', prevIndex);
        };
        /*
        *	Property Detail Init
        */
        this.initPropDetail = function () {

            //	Events list
            jQuery('.mod-events .table-contents table tr:last td').css('border-bottom', 'none');
            jQuery('.mod-events .event-date-fld')
				.datepicker(dpConfig)
				.datepicker("setDate", new Date())
				.change(function () {
				    updateEvents();
				});
            jQuery('.mod-events .datepicker-ico img').click(function () {
                jQuery('.mod-events .event-date-fld').datepicker('show');
            });
            jQuery('.mod-events .datepicker-month-arrow-right').click(function () {
                var newDate = jQuery('.mod-events .event-date-fld').datepicker("getDate");
                jQuery('.mod-events .event-date-fld').datepicker("setDate", new Date(newDate.setDate(newDate.getDate() + 1)));
                updateEvents();
            });
            jQuery('.mod-events .datepicker-month-arrow-left').click(function () {
                var newDate = jQuery('.mod-events .event-date-fld').datepicker("getDate");
                jQuery('.mod-events .event-date-fld').datepicker("setDate", new Date(newDate.setDate(newDate.getDate() - 1)));
                updateEvents();
            });
            updateEvents();
            this.initDetailPhotoGallery();

            //	Room and Amenities
            jQuery('.mod-views-desc h3').click(function (e) {
                e.preventDefault();
                jQuery(this).next('.con-view-type').toggle();
            });

        };
        /*
        *	Destination Detail Init
        */
        this.initDestDetail = function () {

            //	Events list
            /*jQuery('.mod-events .table-contents table tr:last td').css('border-bottom', 'none');
            jQuery('.mod-events .event-date-fld')
            .datepicker(dpConfig)
            .datepicker("setDate", new Date())
            .change(function() {
            updateEvents();
            });
            jQuery('.mod-events .datepicker-ico img').click(function() {
            jQuery('.mod-events .event-date-fld').datepicker('show');
            });
            jQuery('.mod-events .datepicker-month-arrow-right').click(function() {
            var newDate = jQuery('.mod-events .event-date-fld').datepicker("getDate");
            jQuery('.mod-events .event-date-fld').datepicker("setDate", new Date(newDate.setDate(newDate.getDate() + 1)));
            updateEvents();
            });
            jQuery('.mod-events .datepicker-month-arrow-left').click(function() {
            var newDate = jQuery('.mod-events .event-date-fld').datepicker("getDate");
            jQuery('.mod-events .event-date-fld').datepicker("setDate", new Date(newDate.setDate(newDate.getDate() - 1)));
            updateEvents();
            });
            updateEvents();*/
            jQuery('.mod-article-list ul li:last').addClass('last');
        };

        /*
        *	Article Filter Init
        */
        this.initArticleFilter = function () {
            addFilterDateHandlers();
            addFilterDestinationPropertyHandlers();
        };
        var addFilterDestinationPropertyHandlers = function () {

            var _jsonDestProp = null;
            // Retreive JSON destination and property data
            if (typeof (jsonDestination) != "undefined") {
                _jsonDestProp = jsonDestination;
            }
            var destDropdown = jQuery('.filter-dest-fld');
            var propDropdown = jQuery('.filter-prop-fld');
            var propertyDefaultText = jQuery(":selected", propDropdown).text();
            //  Saved combo state from post
            var selectedPropCode = (jQuery('.js-selected-property-val') !== undefined) ? jQuery('.js-selected-property-val').val() : "";
            var selectedIndex = -1;

            /*
            * function updateSelOpt
            * @param field1 {object} select box that changed
            * @param field1 {object} select box to be populated
            * 		Read options from configuration object, populate level 2
            * 		select box
            *  2010-06-01 Updated to support All condos with value=0 and d a hidden input with properties IDs
            */
            var updateSelOpt = function ($field1, $field2) {
                var createOptionElement = function (value, label) {
                    return "<option value='" + value + "'>" + label + "</option>";
                }
                $field2.html("");

                //Populate properties list
                var propObj = undefined;
                for (var i = 0; i < _jsonDestProp.length; i++) {
                    if (_jsonDestProp[i].Code == $field1.val()) {
                        propObj = _jsonDestProp[i].Properties;
                    }
                }
                if (_jsonDestProp[$field1.val()] !== undefined) {
                    propObj = _jsonDestProp[$field1.val()].Properties;
                }
                if (propObj) {
                    var listItems = '<option value="0">' + jQuery('.label-all-props').val() + '</option>';
                    for (var i = 0; i < propObj.length; i++) {
                        if (propObj[i].Name != "") {
                            listItems += createOptionElement(propObj[i].Code, propObj[i].Name);
                            if (selectedPropCode && selectedPropCode == propObj[i].Code) selectedIndex = i;
                        }
                    }

                } else {
                    listItems = '<option value="0">' + propertyDefaultText + '</option>';
                }
                $field2.html(listItems);
                //If we had prepopulate data, set selected index of properites list
                if (selectedIndex > -1) {
                    $field2.get(0).selectedIndex = selectedIndex + 1;
                }
            }
            updateSelOpt(destDropdown, propDropdown);
            propDropdown.get(0).selectedValue = jQuery('.js-selected-property-val');
            destDropdown.change(function () { updateSelOpt(destDropdown, propDropdown); });
            jQuery('.js-property').hide();
            propDropdown.change(function () {
                jQuery('.js-property').hide();
                var code = propDropdown.val();
                jQuery(".js-property-code-" + code).show();
            });

        };

        var addFilterDateHandlers = function () {
            jQuery('.mod-article-filter .datepicker-ico img').click(function (e) {
                e.preventDefault();
                //jQuery('.mod-article-filter .js-date-from').datepicker('show');
                _currentCheckControl.datepicker('show');
            });

        };

        /* 
        * Explore Category Articles Init
        */
        this.initCategoryArticles = function () {
            updateCategoryArticles(0);
        };
        var updateCategoryArticles = function (currentIndex) {

            var jsonObject = null;
            if (typeof (jsonCategoryArticles) == "undefined") { return; }
            jsonObject = jsonCategoryArticles;

            var numItemsPerPage = 8;

            var remainingItems = jsonObject.length - currentIndex;
            var numItemsOnPage = (Number(remainingItems) < numItemsPerPage) ? remainingItems : numItemsPerPage;
            var itemNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastItemInPage = (jsonObject.length > 0) ? Number(numItemsOnPage) + itemNumber - 1 : 0;

            updatePagingLinks(jsonObject.length, currentIndex, lastItemInPage, updateCategoryArticles, numItemsPerPage, "");

            var newHTML = "";
            for (var i = 0; i < numItemsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                newHTML += '<li><a href="' + jsonObject[index].Url + '"><img src="' + jsonObject[index].Img + '" alt="' + jsonObject[index].Title + '" class="left" /></a>';
                newHTML += '<div class="right"><h3>' + jsonObject[index].Title + '</h3><p class="byline"><strong>' + jsonObject[index].Author + '</strong> at ' + jsonObject[index].Date + '</p>';
                newHTML += '<p>' + jsonObject[index].Body + '</p><a href="' + jsonObject[index].Url + '">Read More</a>';
                newHTML += '</div>	<!--	/right	--></li>';
            }

            jQuery('.category-articles-grid').html(newHTML);
        };

        /* 
        * Old Blog Posts Widget Init
        */
        this.initOldPostWidget = function () {
            if (typeof (oldPostStartingIndex) == "undefined") { updateOldPostWidget(0); }
            else { updateOldPostWidget(oldPostStartingIndex); }

        };
        var updateOldPostWidget = function (currentIndex) {

            var jsonObject = null;
            if (typeof (jsonOldPosts) == "undefined") { return; }
            jsonObject = jsonOldPosts;

            var numItemsPerPage = 1;
            if (typeof (oldPostCount) != "undefined")
                numItemsPerPage = oldPostCount;

            currentIndex = currentIndex < 0 ? 0 : currentIndex;

            var remainingItems = jsonObject.length - currentIndex;
            var numItemsOnPage = (Number(remainingItems) < numItemsPerPage) ? remainingItems : numItemsPerPage;
            var itemNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastItemInPage = (jsonObject.length > 0) ? Number(numItemsOnPage) + itemNumber - 1 : 0;

            var newHTML = "";
            for (var i = 0; i < numItemsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                newHTML += '<li><a href="' + jsonObject[index].Url + '&index=' + index + '"> ' + jsonObject[index].Label + '</a>';
            }
            var oldContent = jQuery('.old-posts-content');
            jQuery('.old-post-list', oldContent).html(newHTML);
            if (currentIndex > 0) {
                jQuery('.old-post-previous', oldContent).show().click(function (e) {
                    updateOldPostWidget(currentIndex - numItemsPerPage);
                });
            } else {
                jQuery('.old-post-previous', oldContent).hide()
            }
            if (lastItemInPage < jsonObject.length) {
                jQuery('.old-post-next', oldContent).show().click(function (e) {
                    updateOldPostWidget(lastItemInPage);
                });
            } else {
                jQuery('.old-post-next', oldContent).hide()
            }
        };
        /*
        * Destination Specials Init
        */
        this.initDestSpecials = function () {
            updateDestSpecials(0);
        };
        var updateDestSpecials = function (currentIndex) {

            var jsonObject = null;
            if (typeof (jsonSpecials) == "undefined") { return; }
            jsonObject = jsonSpecials;

            var numItemsPerPage = 8;

            var remainingItems = jsonObject.length - currentIndex;
            var numItemsOnPage = (Number(remainingItems) < numItemsPerPage) ? remainingItems : numItemsPerPage;
            var itemNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastItemInPage = (jsonObject.length > 0) ? Number(numItemsOnPage) + itemNumber - 1 : 0;

            updatePagingLinks(jsonObject.length, currentIndex, lastItemInPage, updateDestSpecials, numItemsPerPage, ".dest-specials-list");

            var newHTML = "";
            for (var i = 0; i < numItemsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                //newHTML += '<li><a href="' + jsonObject[index].Url + '"><img src="' + jsonObject[index].Img + '" alt="' + jsonObject[index].NavigationName + '" class="left" /></a>';
                newHTML += '<li><div ><h3><a href="' + jsonObject[index].Url + '">' + jsonObject[index].NavigationName + '</a></h3>';
                if (jsonObject[index].PromotionAudience != "") {
                    newHTML += '<p class="byline">' + jsonObject[index].PromotionAudience + '</p>';
                }
                newHTML += '<p>' + jsonObject[index].Body + '</p><a href="' + jsonObject[index].Url + '">Read More</a>';
                newHTML += '</div>	<!--	/right	--></li>';
            }

            jQuery('.specials-grid').html(newHTML);
        };
        /* 
        * Where To Stay Init
        */
        this.initWhereToStay = function () {
            updateWhereToStay(0);
        };
        var updateWhereToStay = function (currentIndex) {

            var jsonObject = null;
            if (typeof (jsonWhereToStay) == "undefined") { return; }
            jsonObject = jsonWhereToStay;

            //per OUT-3041 commenting out paging logic 03/21/2011, leaving code for now pending final approval
            //var numItemsPerPage = 8;

            //var remainingItems = jsonObject.length - currentIndex;
            //var numItemsOnPage = (Number(remainingItems) < numItemsPerPage) ? remainingItems : numItemsPerPage;
            //var itemNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            //var lastItemInPage = (jsonObject.length > 0) ? Number(numItemsOnPage) + itemNumber - 1 : 0;

            //updatePagingLinks(jsonObject.length, currentIndex, lastItemInPage, updateWhereToStay, numItemsPerPage, ".where-to-stay-list");

            var newHTML = "";
            var lastDestination = "";
            //for (var i = 0; i < numItemsOnPage; i++) {
            for (var i = 0; i < jsonObject.length; i++) {
                var index = Number(currentIndex) + Number(i);
                if (lastDestination != jsonObject[index].Destination) {
                    newHTML += '<h3>' + jsonObject[index].Destination + '</h3>';
                }
                newHTML += '<ul><li><a href="' + jsonObject[index].Url + '"><img src="' + jsonObject[index].Img + '" alt="' + jsonObject[index].Title + '" class="left" /></a>';
                newHTML += '<div class="right"><h3><a href="' + jsonObject[index].Url + '">' + jsonObject[index].Title + '</a></h3>';
                newHTML += '<p>' + jsonObject[index].Body + '</p><a href="' + jsonObject[index].Url + '">Read More</a>';
                newHTML += '</div>	<!--	/right	--></li></ul>';
                lastDestination = jsonObject[index].Destination;
            }

            jQuery('.where-to-stay-grid').html(newHTML);
        };

        /* 
        * Where To Stay Init
        */
        this.initSpecials = function () {
            this.initCalendars();
            //if (!jQuery('.mod-article-filter .js-date-from').val().length) {
            if (jQuery('.mod-article-filter .js-date-from').val() == undefined) {
                jQuery('.mod-article-filter .js-date-from').datepicker("setDate", new Date());
            }
            //if (!jQuery('.mod-article-filter .js-date-to').val().length) {
            if (jQuery('.mod-article-filter .js-date-to').val() == undefined) {
                jQuery('.mod-article-filter .js-date-to').datepicker("setDate", '+' + 3);
            }
            updateSpecials(0);
        };
        /*
        initCalendars()
        Initialize set of 2 datepickers (from and to dates)
        */
        this.initCalendars = function () {
            var $fromDate = jQuery('.js-date-from')
				.datepicker(dpConfig);

            var $toDate = jQuery('.js-date-to')
				.datepicker(dpConfig);

            $fromDate.change(function () {
                validateCalendarDates($fromDate, $toDate, this);
            });
            $toDate.change(function () {
                validateCalendarDates($fromDate, $toDate, this);
            });
        };
        var updateSpecials = function (currentIndex) {

            var jsonObject = null;
            if (typeof (jsonSpecials) == "undefined") { return; }
            jsonObject = jsonSpecials;

            var numItemsPerPage = 50;

            var remainingItems = jsonObject.length - currentIndex;
            var numItemsOnPage = (Number(remainingItems) < numItemsPerPage) ? remainingItems : numItemsPerPage;
            var itemNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastItemInPage = (jsonObject.length > 0) ? Number(numItemsOnPage) + itemNumber - 1 : 0;

            updatePagingLinks(jsonObject.length, currentIndex, lastItemInPage, updateSpecials, numItemsPerPage, "");

            var newHTML = "";
            for (var i = 0; i < numItemsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                //newHTML += '<li><a href="' + jsonObject[index].Url + '"><img src="' + jsonObject[index].Img + '" alt="' + jsonObject[index].NavigationName + '" class="left" /></a>';
                newHTML += '<li><div><h3><a ';
                if (jsonObject[index].IsExternal) newHTML += 'target="_blank" ';
                newHTML += 'href="' + jsonObject[index].Url + '">' + jsonObject[index].NavigationName + '</a></h3>';
                if (jsonObject[index].PromotionAudience != "") {
                    newHTML += '<p class="byline">' + jsonObject[index].PromotionAudience + '</p>';
                }
                newHTML += '<p>' + jsonObject[index].Body + '</p><a href="' + jsonObject[index].Url + '">Read More</a>';
                newHTML += '</div>	<!--	/right	--></li>';
            }

            jQuery('.specials-grid').html(newHTML);

        };
        /*
        * validateCalendarDates
        * @param {object} fromElement - element containing start date
        * @param {object} toElement - element containing end date
        * @param {object} changedElement - element that recieved the change
        * @param {object} changedElement - element that recieved the change
        * 
        * UPDATE (mariano)
        * now it is setting the date of the invalid one to the SAME as the other instead
        * of the previous/next day to allow using this init for filters like in
        * Specials or Events pages
        *
        * Executes upon change on date inputs
        * If end date is previous or equal to start date sets the one that didn't change
        * to one day after or before the new one to make dates consistent
        */
        var validateCalendarDates = function (startElement, endElement, changedElement) {
            if (jQuery(startElement).val() != "" && jQuery(endElement).val() != "") {
                var start_date = new Date(jQuery(startElement).val());
                var end_date = new Date(jQuery(endElement).val());
                //	Determine who changed
                if (jQuery(changedElement).attr("name") == jQuery(startElement).attr("name")) {
                    //	start date changed
                    //	Compare dates
                    if (end_date <= start_date) {
                        var newDate = jQuery(startElement).datepicker("getDate");
                        jQuery(endElement).datepicker("setDate", new Date(newDate.setDate(newDate.getDate())));
                    }
                }
                else {
                    if (end_date <= start_date) {
                        //	end date changed
                        var newDate = jQuery(endElement).datepicker("getDate");
                        jQuery(startElement).datepicker("setDate", new Date(newDate.setDate(newDate.getDate())));
                    }
                }
            }
        };

        /*
        * handleSameBillingCheckbox()
        *
        * Handles hiding and showing of billing information in guest info
        */
        var handleSameBillingCheckbox = function () {
            var fields = jQuery('.frm-seperate-billing');
            if (jQuery('.same-billing-checkbox').attr('checked')) {
                fields.hide();
            } else {
                fields.show();
            }
        }

        /*
        * handleSameAsAgentCheckbox()
        *
        * Handles hiding and showing of guest information in guest info
        */
        var handleSameAsAgentCheckbox = function () {
            var fields = jQuery('.frm-separate-info');
            if (jQuery('.same-as-agent-checkbox').attr('checked')) {
                fields.hide();
            } else {
                fields.show();
            }
        }

        /*
        *	Guest Info forms init        
        */
        this.initGuestForms = function () {

            handleSameBillingCheckbox();
            handleSameAsAgentCheckbox();

            //	Dialog more Rate info overlay config
            var dialogRateInfo = jQuery('.js-dialog-more-rate-info').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                closeText: dialogCloseText,
                width: smallDialogWidth,
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
            });
            jQuery('.js-dialog-more-rate-info-opener').click(function (e) {
                e.preventDefault();
                dialogRateInfo.dialog('open');
            });

            //	Share  itinerary overlay config
            var shareTitle = jQuery('.js-dialog-share-email').attr('title');
            var dialogShareEmail = jQuery('.js-dialog-share-email').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                title: shareTitle,
                closeText: dialogCloseText,
                close: onShareClose,
                width: mediumDialogWidth,
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                    jQuery('.js-dialog-share-email').parent().appendTo(jQuery('form:first'));
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }

            });


            //	Cost discalimer overlay
            var costTitle = jQuery('.js-dialog-cost-disclaimer').attr('title');
            var dialogCostDisclaimer = jQuery('.js-dialog-cost-disclaimer').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                title: costTitle,
                closeText: dialogCloseText,
                width: smallDialogWidth,
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
            });
            //	Credit card policy overlay config
            var cardTitle = jQuery('.js-dialog-card-disclaimer').attr('title');
            var dialogCardDisclaimer = jQuery('.js-dialog-card-disclaimer').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                title: cardTitle,
                closeText: dialogCloseText,
                width: smallDialogWidth,
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
            });
            //	end of Credit card policy overlay config
            jQuery('fieldset:not(:last)', jQuery('.guest-info .glb-frm')).addClass('border-bottom');

            if (jQuery('.frm-guest-info .date-fld').length) {
                jQuery('.frm-guest-info .date-fld').datepicker(dpConfig);
            }
            jQuery('.js-dialog-share-email-opener').click(function (e) {
                e.preventDefault();
                dialogShareEmail.dialog('open');
            });


            if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                alert("test");
                $(".ui-dialog").css("top", $(window).scrollTop() + "px");
                $(window).scroll(function () {
                    $(".ui-dialog").css("top", $(window).scrollTop() + "px");
                });
            }


            jQuery('.js-dialog-cost-disclaimer-opener').click(function (e) {
                e.preventDefault();
                dialogCostDisclaimer.dialog('open');
            });

            //	Credit card policy overlay trigger config
            jQuery('.js-dialog-card-disclaimer-opener').click(function (e) {
                e.preventDefault();
                dialogCardDisclaimer.dialog('open');
            });
            //	end of Credit card policy overlay trigger config

            jQuery('.same-billing-checkbox').click(function () {
                handleSameBillingCheckbox();
            });

            jQuery('.same-as-agent-checkbox').click(function () {
                handleSameAsAgentCheckbox();
            });

            //	Property details overlay
            var dialogDetails = jQuery('.js-dialog-details').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                closeText: 'Close', //fixme
                width: 729, //	FIXME
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }

            });
            jQuery('.js-dialog-details-opener').click(function (e) {
                e.preventDefault();
                dialogDetails.dialog('open');
            });

        };
        /*	MOD bkwgt	*/
        this.initBookingWidget = function () {
            jQuery('.special-rates-link').click(function (e) {
                e.preventDefault();
                //	Toggle js-expanded class (when expanded, the class changes the "+" sign for a "-")
                jQuery(this).toggleClass('js-expanded');
                if (jQuery('.special-rates').css('display') !== 'block') {
                    //	Display special rates options
                    jQuery('.special-rates').fadeIn('fast', function () {
                        removeElFilterIE7(this);
                    });
                }
                else {
                    jQuery('.special-rates').hide();
                }
            });
            jQuery('.btn-done').click(function (e) {
                //  Hide special rates options
                e.preventDefault();
                jQuery('.special-rates').hide();
                jQuery('.special-rates-link').toggleClass('js-expanded');
            });
        };

        this.initHeadNav = function () {
            /* Add mouse events to the direct <li> children of nav-primary - to add the hover classes */
            //jQuery('.nav-wrapper li').hoverIntent(menuHIConfig);
            jQuery('.nav-wrapper li').hover(menuExpand, menuCollapse);
            jQuery('li:first', jQuery(".nav-level-1")).addClass("js-first");

            /* mega menu edit */

            jQuery('.nav-level-1').mouseenter(function () {
                jQuery(this).prev().addClass("nav-level-0-link-hover");
            }).mouseleave(function () {
                jQuery(this).prev().removeClass("nav-level-0-link-hover");
            });

            jQuery('.nav-options-subheader').next('.nav-options-item').addClass('nav-options-item-first');
            jQuery('.nav-options-01 .nav-options-subheader:first').addClass('nav-options-subheader-first');
            jQuery('.nav-options-02 .nav-options-subheader:first').addClass('nav-options-subheader-first');
            jQuery('.nav-options-03 .nav-options-subheader:first').addClass('nav-options-subheader-first');
            jQuery('.nav-options-04 .nav-options-subheader:first').addClass('nav-options-subheader-first');

            if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                jQuery(".nav-wrapper li.nav-level-0-item:first").mouseover(function () {
                    jQuery(".con-book select").css("visibility", "hidden");
                }).mouseout(function () {
                    jQuery(".con-book select").css("visibility", "visible");
                });
                /*
                jQuery("#nav-level-1-01 .nav-options").mouseover(function () {
                jQuery(".con-book select").css("visibility", "hidden");
                }).mouseout(function () {
                jQuery(".con-book select").css("visibility", "visible");
                });
                */
                //jQuery('select').css('visibility', 'hidden');
            } else {
            };


            /* jQuery('ul .nav-level-1 li').mouseover(function() {
            jQuery(this).toggleClass('.navmenu_liBackgroundHover');
            });*/
            //	Language dropdown	-----------------
            jQuery('.con-language').hover(function () {
                jQuery(this).addClass('js-hover');
            }, function () {
                jQuery(this).removeClass('js-hover');
            });
        };
        /*	MOD list-property	*/
        this.initPropertyList = function () {
            jQuery('.view-details-link').each(function () {
                jQuery('span:last', jQuery(this)).hide(); //	Hide "close" legend.
            });
            jQuery('.mod-view-details-tab .tab-content').hide();
            jQuery('.view-details-link').click(function (e) {
                e.preventDefault();
                //  get context by building selector string from clicked A's class
                var context = jQuery("." + jQuery('span:first', jQuery(this)).attr("class") + "-context");
                //	Toggle content visibility:
                jQuery('.mod-view-details-tab .tab-content', context).toggle();
                //	Toggle tab's bkgr:
                jQuery('.view-details-link', context).toggleClass('js-expanded');
                //	Toggle View / Close legends:
                jQuery('.view-details-link span:first', context).toggle();
                jQuery('.view-details-link span:last', context).toggle();
            });

        }
        /*	MOD select-room	*/
        this.initRoomList = function () {
            jQuery('.mod-list-rooms .room-head-wrp').hide();
            //jQuery('.room-head').next().addClass('js-first');
            jQuery('.room-head:not(.js-expanded)').next().addClass('js-first');
            jQuery('.room-head h2').click(function (e) {
                e.preventDefault();
                var context = jQuery(jQuery(this).parent());
                context.toggleClass('js-expanded');
                //	Toggle content visibility:
                jQuery('.room-head-wrp', context).toggle();
                //	manage next-to-head rate's specific styles
                jQuery('.room-head.js-expanded').next().removeClass('js-first');
                jQuery('.room-head:not(.js-expanded)').next().addClass('js-first');
            });
            jQuery('.room-rate h3').click(function (e) {
                e.preventDefault();
                var context = jQuery(jQuery(this).parent());
                //	Toggle content visibility:
                context.toggleClass('js-expanded');
            });
            //	Total Cost overlay
            jQuery('.room-rate').each(function () {
                var thisTitle = jQuery('.js-dialog-cost', jQuery(this)).attr('title');
                var dialog = jQuery('.js-dialog-cost', jQuery(this))
					.dialog({
					    bgiframe: true,
					    autoOpen: false,
					    modal: true,
					    title: thisTitle,
					    closeText: 'Close', //fixme
					    width: 415, //	FIXME
					    open: function (event, ui) {
					        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
					            jQuery('select').css('visibility', 'hidden');
					        }
					    },
					    close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
					});
                jQuery('.js-dialog-cost-opener', jQuery(this)).click(function (e) {
                    e.preventDefault();
                    dialog.dialog('open');
                });
            });

            //	Property details overlay			
            var dialogDetails = jQuery('.js-dialog-details').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                closeText: 'Close', //fixme
                width: 729, //	FIXME
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
            });

            jQuery('.js-dialog-details-opener').click(function (e) {
                e.preventDefault();
                dialogDetails.dialog('open');
            });

            jQuery("input[name='show']:radio").change(function () {
                if (jQuery("input[name='show']:radio:checked").val() == "all") {
                    jQuery('.room-rate').show();
                } else {
                    jQuery('.room-rate').hide();
                    jQuery('.js-first').show();
                }
                jQuery(this).blur();
            });
        } //	initRoomList()

        /* Compare Properties */
//        this.initCompareProperties = function () {
//            var dTitle = jQuery('#cancel-policy-1').attr('title');
//            var dialogCardDisclaimer1 = jQuery('#cancel-policy-1').dialog({
//                bgiframe: true,
//                autoOpen: false,
//                modal: true,
//                title: dTitle,
//                closeText: dialogCloseText,
//                width: smallDialogWidth
//            });
//            var dialogCardDisclaimer2 = jQuery('#cancel-policy-2').dialog({
//                bgiframe: true,
//                autoOpen: false,
//                modal: true,
//                title: dTitle,
//                closeText: dialogCloseText,
//                width: smallDialogWidth
//            });
//            var dialogCardDisclaimer3 = jQuery('#cancel-policy-3').dialog({
//                bgiframe: true,
//                autoOpen: false,
//                modal: true,
//                title: dTitle,
//                closeText: dialogCloseText,
//                width: smallDialogWidth
//            });
//            jQuery('#cancel-policy-link-1').click(function (e) {
//                e.preventDefault();
//                dialogCardDisclaimer1.dialog('open');
//            });
//            jQuery('#cancel-policy-link-2').click(function (e) {
//                e.preventDefault();
//                dialogCardDisclaimer2.dialog('open');
//            });
//            jQuery('#cancel-policy-link-3').click(function (e) {
//                e.preventDefault();
//                dialogCardDisclaimer3.dialog('open');
//            });
//        }
        /*	Currency Converter init method	*/
        this.initCurrencyConverter = function () {
            jQuery('.js-popup-close').click(function (e) {
                e.preventDefault();
                window.close();
            });
        }

        /*
        * openPrint()
        *
        * Displays printable document in new window, popup style
        * @param url to open
        */
        var openPrint = function (url) {
            window.open(url, "Print", "height=" + printPopupConfig.height + ",width=" + printPopupConfig.width + ",scrollbars=yes,resizable=yes");
        }
        /*
        * openHelp(url)
        *
        * Displays help in new window, popup style
        */
        var openHelp = function (url) {
            window.open(url, "Help", "height=" + helpPopupConfig.height + ",width=" + helpPopupConfig.width + ",scrollbars=" + helpPopupConfig.scrolling + ",resizable=no");
        }
        /*
        * openPropertyDetails()
        *
        * Displays propety details in new window, popup style
        * @param url to open
        */
        var openPropertyDetails = function (url) {
            window.open(url, "Details", "height=" + propertyDetailsPopupConfig.height + ",width=" + propertyDetailsPopupConfig.width + ",scrollbars=yes,resizable=yes");
        }

        /* Photo Gallery init method */
        this.initPhotoGallery = function () {
            //  Load 1st photo in each gallery (for booking flow pages)
            jQuery('.property-detail-picture-nav').each(function () {
                //	If there is a nextPhoto link with a rel attr that holds a prop code, then load first picture
                if (jQuery('.nextPhoto', jQuery(this)).attr('rel') !== undefined) {
                    var prop = jQuery('.nextPhoto', jQuery(this)).attr('rel');
                    if (prop != "") {
                        updateDetailPhotoDialog(0, prop, jQuery('.' + prop + "-context"));
                    }
                }
            });
            jQuery('.nextPhoto, .previousPhoto').click(function (e) {
                e.preventDefault();
                //  the rel attr holds property code to reference images object
                //  the value holds the current index in the gallery
                updateDetailPhotoDialog(jQuery(this).attr('value'), jQuery(this).attr('rel'), jQuery('.' + jQuery(this).attr('rel') + "-context"));
            });

        }
        /* 
        * initPressRelease
        */
        this.initPressRelease = function () {
            if (jQuery('.con-all-news-types').length > 0) {
                jQuery('.con-all-news-types').click(function () {
                    if (jQuery('.con-all-news-types').attr('checked')) {
                        jQuery('.news-type').attr('checked', 'checked');
                    } else {
                        jQuery('.news-type').attr('checked', '');
                    }
                });
            }
        }
        /*
        * initPressReleaseLanding
        */
        this.initPressReleaseLanding = function () {
            jQuery('.releases-per-page-list').change(function () {
                jQuery('.con-gallery-page-link').hide();
                jQuery('.con-gallery-page-link').attr('class', '');
                updatePressReleases(0);
            });

            updatePressReleases(0);
        }
        var updatePressReleases = function (currentIndex) {

            var jsonObject = null;
            if (typeof (JSONPressReleases) == "undefined") { return; }
            jsonObject = JSONPressReleases;

            var numItemsPerPage = jQuery(":selected", '.releases-per-page-list').val();

            var remainingItems = jsonObject.length - currentIndex;
            var numItemsOnPage = (Number(remainingItems) < numItemsPerPage) ? remainingItems : numItemsPerPage;
            var itemNumber = (jsonObject.length > 0) ? Number(Number(currentIndex) + 1) : 0;
            var lastItemInPage = (jsonObject.length > 0) ? Number(numItemsOnPage) + itemNumber - 1 : 0;

            updatePagingLinks(jsonObject.length, currentIndex, lastItemInPage, updatePressReleases, numItemsPerPage, "");

            var newHTML = "";
            for (var i = 0; i < numItemsOnPage; i++) {
                var index = Number(currentIndex) + Number(i);
                newHTML += '<li>' + jsonObject[index].Date + ' <a href="' + jsonObject[index].Url + '">' + jsonObject[index].Title + '</a></li>';
            }

            jQuery('.press-releases-grid').html(newHTML);
            if (jsonObject.length == 0) {
                jQuery('.press-releases-grid').hide();
            }
            else {
                jQuery('.press-releases-grid').show();
            }
        };

        /*
        * initCountryStateLists
        */
        this.initCountryStateLists = function () {

            // Retreive JSON countries
            var jsonObject = null;
            if (typeof (JSONCountries) != "undefined") {

                jsonObject = JSONCountries;
                var listItems = '<option value="">Select</option>';
                for (var i = 0; i < jsonObject.length; i++) {

                    listItems += '<option value="' + jsonObject[i].Value + '">' + jsonObject[i].Name + '</option>';
                }

                jQuery('.con-country-ddl').html(listItems);

                jQuery('.con-country-ddl').change(function () {
                    handleUpdateStatesList(jQuery(this), jQuery(this).closest('.con-country-state-lists').find('.con-state-ddl'), true);
                    handleUpdateZipRequired(jQuery(this), jQuery(this).closest('.con-country-state-lists').siblings('.con-zip-postal').first());
                });

                jQuery('.con-country-ddl').each(function (index) {

                    jQuery(this).children('option').each(function (index) {
                        var selectedValue = jQuery(this).parent().siblings('.con-country-value').val();

                        if (selectedValue != "undefined" && String(selectedValue).length > 0) {

                            if (jQuery(this).val() == selectedValue) {
                                jQuery(this).parent().get(0).selectedIndex = index;
                                handleUpdateStatesList(jQuery(this).parent(), jQuery(this).parent().closest('.con-country-state-lists').find('.con-state-ddl'), false);
                                handleUpdateZipRequired(jQuery(this).parent(), jQuery(this).parent().closest('.con-country-state-lists').siblings('.con-zip-postal').first());
                            }
                        }
                    });
                });

                jQuery('.con-state-ddl').each(function (index) {

                    jQuery(this).children('option').each(function (index) {
                        var selectedValue = jQuery(this).parent().siblings('.con-state-value').val();
                        if (selectedValue != "undefined" && String(selectedValue).length > 0) {
                            if (jQuery(this).val() == selectedValue) {
                                jQuery(this).parent().get(0).selectedIndex = index;
                            }
                        }
                    });
                });
            }
        }
        var handleUpdateZipRequired = function ($field1, $field2) {
            var jsonObject = null;

            if (typeof (JSONCountries) != "undefined" && $field1 != "undefined" && $field2 != "undefined") {
                jsonObject = JSONCountries;
                for (var i = 0; i < jsonObject.length; i++) {
                    if (jsonObject[i].Value == $field1.val()) {
                        //	If there are no zip, field2 is not required
                        if (!jsonObject[i].ZipRequired) {
                            //	2nd level list empty (no states for this country)
                            $field2.children('.frm-item').removeClass('frm-required');
                        }
                        else {
                            $field2.children('.frm-item').addClass('frm-required');
                        }
                    }
                }
            }
        }
        var handleUpdateStatesList = function ($field1, $field2, onChange) {

            var defaultItem = '<option value="">Select</option>';
            $field2.html(defaultItem);
            if (onChange) {
                $field2.siblings('.con-state-value').val("");
                $field2.siblings('.con-num-states-value').val("");
            }
            var selectedIndex = -1;

            if ($field1.siblings('.con-country-value') != "undefined") {
                $field1.siblings('.con-country-value').val($field1.val());
            }

            $field2.change(function () {
                if (jQuery(this).siblings('.con-state-value') != "undefined") {
                    jQuery(this).siblings('.con-state-value').val(jQuery(this).val());
                }
            });
            $field2.blur(function () {
                if (jQuery(this).siblings('.con-state-value') != "undefined") {
                    jQuery(this).siblings('.con-state-value').val(jQuery(this).val());
                }
            });

            var jsonObject = null;
            if (typeof (JSONCountries) != "undefined" && $field1 != "undefined" && $field2 != "undefined") {
                jsonObject = JSONCountries;

                for (var i = 0; i < jsonObject.length; i++) {
                    if (jsonObject[i].Value == $field1.val()) {
                        //var listItems = '<option value="">Select</option>';
                        var listItems = defaultItem;
                        $field2.siblings('.con-num-states-value').val(jsonObject[i].States.length);
                        for (var j = 0; j < jsonObject[i].States.length; j++) {
                            listItems += '<option value="' + jsonObject[i].States[j].Value + '">' + jsonObject[i].States[j].Name + '</option>';
                        }
                        //	If there are no states, field2 is not required
                        if (listItems == defaultItem) {
                            //	2nd level list empty (no states for this country)
                            $field2.closest('.frm-item').removeClass('frm-required');
                            $field2.closest('.frm-item').hide(); //added to allow form items to hide/show depending on country selection - GH(AG) OUT-2824
                            jQuery('.province-region').show(); //added to allow form items to hide/show depending on country selection - GH(AG) OUT-2824
                        }
                        else {
                            $field2.closest('.frm-item').addClass('frm-required');
                            $field2.closest('.frm-item').show(); //added to allow form items to hide/show depending on country selection - GH(AG) OUT-2824
                            jQuery('.province-region').hide(); //added to allow form items to hide/show depending on country selection - GH(AG) OUT-2824
                        }
                        $field2.html(listItems);
                    }
                }
            }
        }
        /* Video content tiles */
        this.initVideoContentTiles = function () {
            jQuery('.mod-video-tile').each(function (index) {
                populateVideoContentTile(jQuery(this).attr('value'), jQuery(this).attr('value2'), jQuery(this).attr('value3'), jQuery(this).attr('value4'), jQuery(this).attr('value5'));
            });
            initFullscreenVideoDialog('videoTileFullscreenFlashDiv');
        }
        var populateVideoContentTile = function (videoPath, imagePath, title, width, height) {

            //Show loading flash image
            changeVideoContentTileBg('con-tile-flash-module tile-loading-');

            var params = {};
            params.menu = "false";
            params.scale = "noscale";
            params.bgcolor = "#000000";
            params.wmode = "transparent";

            var attributes = {};
            attributes.align = "middle";

            var flashvars = {};
            flashvars.filePath = videoPath;
            flashvars.posterPath = imagePath;
            flashvars.autoPlay = 'false';
            flashvars.fullScreen = 'false';
            flashvars.time = 'false';
            flashvars.title = title;

            swfobject.embedSWF("/swfs/OutriggerVideoPlayer.swf", "videoTileFlashDiv", width, height, "10.0.0", "/swfs/expressInstall.swf", flashvars, params, attributes, onVideoContentTileLoaded);
        };
        var onVideoContentTileLoaded = function (e) {
            //Show no flash if we fail to embed swf
            if (!e.success) {
                changeVideoContentTileBg('con-tile-flash-module no-flash tile-no-flash-');
            }
        }
        var changeVideoContentTileBg = function (inClass) {
            var videoTileFlashDivParent = jQuery('#videoTileFlashDiv').parent();
            if (videoTileFlashDivParent != null) {
                videoTileFlashDivParent.attr('class', inClass + videoTileFlashDivParent.attr('class').substr(videoTileFlashDivParent.attr('class').length - 2));
            }
        }
        this.showContentTileFullScreenVideo = function () {
            jQuery('.mod-video-tile').each(function (index) {
                showFullScreenVideoDialog(jQuery(this).attr('value'), jQuery(this).attr('value2'), jQuery(this).attr('value3'), 'videoTileFullscreenFlashDiv', '#videoTileFullscreenContainer', false);
            });
        };
        this.initRequestMeeting = function () {
            jQuery('.con-location-ddl').change(function () {
                var jsonObject = null;
                if (typeof (jsonLocations) == "undefined") { return; }
                jsonObject = jsonLocations;

                jQuery('.con-location-value').val(jQuery(this).val());

                var ddlHotels = jQuery('.con-hotel-ddl');
                ddlHotels.html("");
                ddlHotels.change(function () {
                    jQuery('.con-hotel-email').val(jQuery(this).val());
                    jQuery('.con-hotel-name').val(jQuery(":selected", jQuery(this)).text());
                    jQuery('.con-hotel-code').val(jQuery(this).attr('value2'));
                });

                var destination;
                for (var i = 0; i < jsonObject.length; i++) {
                    if (jsonObject[i].Code == jQuery(this).val())
                        destination = jsonObject[i];
                }

                //Populate hotels list
                var listItems = "";
                if (destination !== undefined) {
                    listItems = '<option value="' + destination.PreferredLocationEmail + '" value2="">' + jQuery('.con-any-hotel-value').val() + '</option>';
                    var propObj = destination.Properties;
                    if (propObj) {
                        for (var i = 0; i < propObj.length; i++) {
                            listItems += '<option value="' + propObj[i].PreferredHotelEmail + '"  value2="' + propObj[i].Code + '">' + propObj[i].Name + '</option>';
                        }
                    }
                }
                else {
                    listItems = '<option value="" value2="">Select</option>';
                }
                ddlHotels.html(listItems);
            });

            jQuery('.con-location-ddl').each(function (index) {

                jQuery(this).children('option').each(function (index) {
                    var selectedValue = jQuery(this).parent().siblings('.con-location-value').val();
                    if (selectedValue != "undefined" && String(selectedValue).length > 0) {
                        if (jQuery(this).val() == selectedValue) {
                            jQuery(this).parent().get(0).selectedIndex = index;
                            jQuery('.con-location-ddl').trigger('change');
                        }
                    }
                });
            });

            jQuery('.con-hotel-ddl').each(function (index) {

                jQuery(this).children('option').each(function (index) {
                    var selectedValue = jQuery(this).parent().siblings('.con-hotel-email').val();
                    var selectedCode = jQuery(this).parent().siblings('.con-hotel-code').val();
                    if (selectedValue != "undefined" && String(selectedValue).length > 0) {
                        if (jQuery(this).val() == selectedValue) {
                            jQuery(this).parent().get(0).selectedIndex = index;
                        }
                    }
                    else if (selectedCode != "undefined" && String(selectedCode).length > 0) {
                        if (jQuery(this).attr("value2") == selectedCode) {
                            jQuery(this).parent().get(0).selectedIndex = index;
                            jQuery('.con-hotel-email').val(jQuery(this).val());
                            jQuery('.con-hotel-name').val(jQuery(this).text());
                        }
                    }
                });
            });
        };

//        this.initLoginPoller = function () {
//            var timer = jQuery.timer(function () {
//                //if (jQuery('.con-ta-login').length < 1) {
//                //                if(jQuery('.con-ta-login').contents().html() != null){
//                //                   if(jQuery('.con-ta-login').contents().html().length < 1){
//                //                       showLoadingDialog();
//                //                   }
//                //                }
//            });

//            timer.set({ time: 100, autostart: true });
//        }

        /*
        * initGlobal()
        *
        * Everything that could be included on any page
        */
        this.initGlobal = function () {
            /*
            Add support for form sumbission upon [enter] keystroke for Firefox
            */
            jQuery('.btn-submit, .btn-action, .btn-submit-cta').each(function () {
                var b = this;
                if (b && typeof (b.click) == 'undefined') b.click = function () {
                    var result = true; if (b.onclick) result = b.onclick();
                    if (typeof (result) == 'undefined' || result) { { eval(b.getAttribute('href')); } }
                }
            });

            /* Add click handler to dynamic image overlay
            Create a dialog on the fly (and destroy on close)
            which will display an image with src= set to the href value of
            the calling A, <a class="js-dyn-img-overlay" href=..
            */
            jQuery('.js-dyn-img-overlay').click(function (e) {
                e.preventDefault();
                jQuery('body').append('<div class="js-dyn-overlay"><img src="' + jQuery(this).attr('href') + '" /></div>');
                var dialogDyn = jQuery('.js-dyn-overlay').dialog({
                    bgiframe: true,
                    modal: true,
                    closeText: dialogCloseText,
                    width: photoDialogWidth,
                    open: function (event, ui) {
                        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                            jQuery('select').css('visibility', 'hidden');
                        }
                    },
                    close: function (ev, ui) { jQuery(this).remove(); jQuery('select').css('visibility', 'visible'); }
                });
            });
            //	Property details overlay (helpful links side rail)
            var sideDialogDetails = jQuery('.js-dialog-details-side').dialog({
                bgiframe: true,
                autoOpen: false,
                modal: true,
                closeText: 'Close', //fixme
                width: 729, //	FIXME
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }

            });

            // Display Property Details Modal
            jQuery('.js-dialog-details-side-opener').click(function (e) {
                e.preventDefault();
                openPropertyDetails(jQuery(this).attr('href'));
            });

            //	Display Property Direction Dialogs
            if (jQuery('.js-property-directions').length) {
                //	There is a repeater hat includes a disclaimer dialog for at least one item
                jQuery('.js-property-directions').each(function () {
                    var thisTitle = jQuery('.js-dialog-property-directions', jQuery(this)).attr('title');

                    var dialog = jQuery('.js-dialog-property-directions', jQuery(this))
						.dialog({
						    bgiframe: true,
						    autoOpen: false,
						    modal: true,
						    title: thisTitle,
						    width: smallDialogWidth,
						    closeText: dialogCloseText,
						    maxHeight: maxDialogHeight,
						    height: dialogHeight,
						    buttons: [
                                        {
                                            text: "Print",
                                            click: function () { openPrint(jQuery('.js-property-directions-opener').attr("href")); }
                                        }
                            ],
						    open: function (event, ui) {
						        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
						            jQuery('select').css('visibility', 'hidden');
						        }


						    },
						    close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
						});
                    jQuery('.js-property-directions-opener', jQuery(this)).click(function (e) {
                        e.preventDefault();
                        dialog.dialog('open');
                    });
                });
            }

            //	Disclaimer Dialogs
            if (jQuery('.js-disclaimer-repeater').length) {
                //	There is a repeater hat includes a disclaimer dialog for at least one item
                jQuery('.js-disclaimer-repeater').each(function () {
                    var thisTitle = jQuery('.js-dialog-disclaimer', jQuery(this)).attr('title');
                    var dialog = jQuery('.js-dialog-disclaimer', jQuery(this))
						.dialog({
						    bgiframe: true,
						    autoOpen: false,
						    modal: true,
						    title: thisTitle,
						    width: largeDialogWidth,
						    closeText: dialogCloseText,
						    maxHeight: maxDialogHeight,
						    height: dialogHeight,
						    open: function (event, ui) {
						        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
						            jQuery('select').css('visibility', 'hidden');
						        }
						    },
						    close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
						});
                    jQuery('.js-dialog-disclaimer-opener', jQuery(this)).click(function (e) {
                        e.preventDefault();
                        dialog.dialog('open');
                    });
                });
            }

            //	Share itinerary Dialogs for saved itineraries
            if (jQuery('.js-share-itineraries-repeater').length) {
                //	There is a repeater hat includes a dialog for at least one item
                jQuery('.js-share-itineraries-repeater').each(function () {
                    //var thisTitle = jQuery('.js-dialog-disclaimer', jQuery(this)).attr('title');
                    var dialog = jQuery('.js-dialog-share-email')
						.dialog({
						    bgiframe: true,
						    autoOpen: false,
						    modal: true,
						    width: mediumDialogWidth,
						    closeText: dialogCloseText,
						    open: function (event, ui) {
						        jQuery('.js-dialog-share-email').parent().appendTo(jQuery('form:first'));
						        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
						            jQuery('select').css('visibility', 'hidden');
						        }
						    },
						    close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
						});
                    jQuery('.js-dialog-share-email-opener', jQuery(this)).click(function (e) {
                        e.preventDefault();
                        var itineraryId = jQuery(this).siblings('.js-share-itinerary-id').val();
                        jQuery('.js-share-itinerary-id', jQuery('.js-dialog-share-email')).val(itineraryId);
                        dialog.dialog('open');
                    });

                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery(window).scroll(function () {
                            jQuery(".ui-dialog").css("top", jQuery(window).scrollTop() + 50 + "px");
                        });
                    }
                });
            }
            var interstitialSection = jQuery('.js-interstitial');
            if (interstitialSection != undefined) {
                var interstitial = jQuery('.js-interstitial-body', interstitialSection)
                    .dialog({
                        autoOpen: false,
                        modal: true,
                        width: mediumDialogWidth
                    });
                jQuery('.js-interstitial-opener', interstitialSection).click(function (e) {
                    interstitial.dialog('open');
                });
            }
            //	Help
            jQuery('.js-help-opener').click(function (e) {
                e.preventDefault();
                if (jQuery(this).attr('href').length) {
                    openHelp(jQuery(this).attr('href'));
                }
            });

            //	Print opener
            jQuery('.js-print-opener').click(function (e) {
                e.preventDefault();
                openPrint(jQuery(this).attr("href"));
            });

            //	Print document
            jQuery('.js-print').click(function (e) {
                e.preventDefault();
                window.print();
            });

            if (jQuery('.js-previous-page-link').length && jQuery('.js-previous-page').length) {
                jQuery('.js-previous-page-link').attr('href', jQuery('.js-previous-page').val());
            }

            //  Popup Close
            jQuery('.js-popup-close').click(function (e) {
                e.preventDefault();
                window.close();
            });
            //	Currency Converter opener
            jQuery('.js-currency-opener').click(function (e) {
                e.preventDefault();
                var params = jQuery(this).next("input").val()
                params = params !== undefined ? params : "";
                openCurrencyConverter(params);
            });
            this.initCalendars();
            //  Set min/max date constrains for datepickers
            jQuery('.mod-article-filter .js-date-from').not('.js-allow-prev').datepicker("option", "minDate", 0);
            jQuery('.mod-article-filter .js-date-to').not('.js-allow-prev').datepicker("option", "minDate", 1);
            jQuery('.mod-article-filter .js-date-to').not('.js-allow-prev').datepicker("option", "maxDate", "+1y");
            jQuery('.mod-article-filter .js-date-from').not('.js-allow-prev').datepicker("option", "maxDate", "+1y");
            jQuery('.js-allow-prev').datepicker("option", "minDate", null);

            /*
            CustomConfirmButton
            */

            jQuery("[class^='js-dialog-confirm_']").each(function (index) {

                var confirmTitle = jQuery(this).attr('title');

                var dialogEl = this;

                var trigger = jQuery(this).attr("class").split("_");
                trigger = ".js-prompt-confirm_" + trigger[1];
                var okLabel = jQuery("input[name=label-ok]", this).val();
                var cancelLabel = jQuery("input[name=label-cancel]", this).val();
                var buttonObj = {};
                var callbackID = jQuery("input[name=callbackID]", this).val();
                buttonObj[okLabel] = function (e) {
                    __doPostBack(callbackID, '');
                    jQuery(this).dialog("close");
                };
                buttonObj[cancelLabel] = function (e) {
                    jQuery(this).dialog("close");
                };
                jQuery(trigger).click(function (e) {
                    e.preventDefault();
                    if (!confirmCheckBlanks(this)) {
                        return; //  stop here if button has js-check-blanks class and any required field is empty
                    }
                    jQuery(dialogEl).dialog({
                        bgiframe: true,
                        autoOpen: true,
                        modal: true,
                        title: confirmTitle,
                        width: smallDialogWidth,
                        buttons: buttonObj,
                        open: function (event, ui) {
                            if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                                jQuery('select').css('visibility', 'hidden');
                            }
                        },
                        close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
                    });

                    //dialogConfirm.dialog('open');
                });
            }); //  end each js-dialog-confirm_...

            /*  CustomConfirmButton END */

            /*.datepicker("setDate", new Date())*/;
            jQuery('.js-date-from').change(function () {
                //jQuery('.js-date-from').datepicker('hide');
                //jQuery('.js-date-to').datepicker('show');
                jQuery('.js-date-from').stop(true, true);
                if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                    setTimeout("jQuery('.js-date-to').datepicker('show');", 1200);
                } else {
                    setTimeout("jQuery('.js-date-to').datepicker('show');", 500);
                }
                _currentCheckControl = jQuery('.js-date-to');
                //jQuery('.js-date-to').datepicker('show');
            });
            //  Calendar icon
            _currentCheckControl = jQuery('.js-date-from');
            jQuery('.js-date-from').click(function () { _currentCheckControl = jQuery('.js-date-from'); });
            jQuery('.js-date-to').click(function () { _currentCheckControl = jQuery('.js-date-to'); });

            jQuery('img.js-date-from-opener').click(function () {
                //jQuery('.js-date-from').datepicker('show');
                _currentCheckControl.datepicker('show');
            });

            //  Email Signup ----------------------------------------
            var $emailAddress = jQuery('.js-fld-email-signup');

            //  Perform signup          
            if (jQuery('.js-dialog-signup').length) {
                //	There is a repeater hat includes a disclaimer dialog for at least one item
                jQuery('.js-dialog-signup:first').each(function () {
                    var dialog = jQuery('.js-dialog-signup')
						.dialog({
						    autoOpen: false,
						    modal: true,
						    width: signupPopupConfig.width,
						    height: signupPopupConfig.height,
						    closeText: dialogCloseText,
						    resizable: false,
						    open: function (event, ui) {
						        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
						            jQuery('select').css('visibility', 'hidden');
						        }
						    },
						    close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
						});
                    jQuery('.js-btn-signup-opener').click(function (e) {
                        e.preventDefault();
                        var $signupUrl = jQuery('.js-url-signup').val();
                        var $signupFrame = jQuery('.js-signup-frame'); var $emailAddressWatermark = jQuery('input.js-default-txt-signup:hidden');
                        var $emailAddressValue = "";
                        jQuery('.js-fld-email-signup').each(function () {
                            var fieldVal = jQuery(this).val();
                            if (validateEmail(fieldVal) && fieldVal != $emailAddressWatermark.val()) {
                                $emailAddressValue = jQuery(this).val();
                            }
                        });
                        //if ($emailAddressValue.length > 0 && $emailAddressValue != $emailAddressWatermark.val() && $signupFrame.length) {
                        if ($signupFrame.length) {
                            $signupFrame.attr("src", $signupUrl + $emailAddressValue);
                            jQuery('.js-dialog-signup:first').dialog('open');
                        }
                    });
                });
            }

            //  clear field on click
            $emailAddress.focus(function (e) {
                var $this = jQuery(this);
                var $signupButton = $this.parent().find('input:button');
                var $emailAddressWatermark = $this.parent().siblings('input.js-default-txt-signup:hidden');
                if ($this.val() == $emailAddressWatermark.val()) {
                    $this.val("");
                }
            });

            //  restore default value on blur if empty
            $emailAddress.blur(function (e) {
                var $this = jQuery(this);
                var $emailAddressWatermark = $this.parent().siblings('input.js-default-txt-signup:hidden');
                var $signupButton = $this.parent().find('input:button');
                if ($this.val().length == 0) {
                    $this.val($emailAddressWatermark.val());
                    //$signupButton.attr('disabled', 'disabled');
                }
            });
            //  Email Signup    ----------------------------------------            

            //	Search field
            var defaultTxtSearch = "";
            if (jQuery('.jsDefaultTxtSearch').length && jQuery('.jsDefaultTxtSearch').val() !== undefined) {
                var defaultTxtSearch = jQuery('.jsDefaultTxtSearch').val();
            }
            //	clear field on click
            jQuery('.search-fld').focus(function (e) {
                if (jQuery('.search-fld').val() == defaultTxtSearch) {
                    jQuery('.search-fld').val("");
                }
            });
            //	restore default value on blur if empty
            jQuery('.search-fld').blur(function (e) {
                if (jQuery('.search-fld').val() == "") {
                    jQuery('.search-fld').val(defaultTxtSearch);
                }
            });
            //Close property details popup
            jQuery('.prop-details-popup .prop-details-popup-titlebar a').click(function (e) {
                window.close();
            });

        }; //	end of initGlobal()
        /*  Handle dialog after a profile is removed */
        var handleAfterDeleteDialog = function () {
            dialogEl = jQuery('.js-dialog-after-delete');
            var confirmTitle = jQuery(dialogEl).attr('title') !== undefined ? jQuery(dialogEl).attr('title') : "";
            var okLabel = jQuery("input.label-ok", dialogEl).val() !== undefined ? jQuery("input[name=label-ok]", dialogEl).val() : "OK";
            var buttonObj = {};
            var urlRedirect = jQuery("input.url-redirect", dialogEl).val() !== undefined ? jQuery("input.url-redirect", dialogEl).val() : "";
            buttonObj[okLabel] = function (e) {
                jQuery(dialogEl).dialog("close");
                if (urlRedirect != "") {
                    window.location.href = urlRedirect;
                }
            };
            jQuery(dialogEl).dialog({
                autoOpen: true,
                modal: true,
                title: confirmTitle,
                width: smallDialogWidth,
                close: onAfterDeleteClose,
                buttons: buttonObj,
                open: function (event, ui) {
                    if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
                        jQuery('select').css('visibility', 'hidden');
                    }
                },
                close: function (ev, ui) { jQuery('select').css('visibility', 'visible'); }
            });
        };
        /*  Handle closing dialog after a profile is removed */
        var onAfterDeleteClose = function () {
            if (jQuery("input.url-redirect", jQuery('.js-dialog-after-delete')).val() !== undefined &&
            	jQuery("input.url-redirect", jQuery('.js-dialog-after-delete')).val() != "") {
                window.location.href = jQuery("input.url-redirect", jQuery('.js-dialog-after-delete')).val();
            }
        };

        /*        
        Return false only if were asked to check blanks and there is at least one required
        field blank in current form
        */
        var confirmCheckBlanks = function (button) {
            if (!jQuery(button).hasClass("js-check-blanks")) return true;
            if (!jQuery(".glb-frm").length) return true;
            var v = true;
            jQuery('.frm-required', jQuery(button).closest(".glb-frm")).each(function (index) {
                // if any required field is found blank in this form's context return false
                if (jQuery('input', jQuery(this)).val() == "") v = false;
            });
            if (!v) Page_ClientValidate(getBlanksGroup(jQuery(button).attr("class")));
            return v;
        };
        var getBlanksGroup = function (fullClass) {
            //  look for a class like "js-blanks-group_GROUPNAME" and return GROUPNAME
            var group = fullClass.split('js-blanks-group_');
            if (group.length > 1) {
                group = group[1].split(" ");
                return group[0];
            }
            return "";
        };
        this.initPage();
    }
    outRigPage = new OutRigger();

});
/*  This functions will be overwritten in IE7 by conditional comment */
var removeElFilterIE7 = function (element) { };
var ie7MenuFix = function (el) { };

function internalNavManager() {
    //	Private Vars
    var bar = "";
    var bar2 = ""; 	//	bar selectors
    var menuBar = ""; //menu selector for static hero nav
    var inLinks = {}; //	store internal nav structure
    var $inPages = {}; //	cache sub and sub-sub containers
    var currTab = "";
    var currTab2 = "";
    var $state = {}; //	cache dom element that will hold saved state through posts
    var inParam = "";

    //	Public methods
    /*
    *	init()
    *	
    */
    this.init = function (mainBarSelector, secondaryBarSelector, menuBarSelector, inParamName, postStateSelector) {
        bar = mainBarSelector;
        bar2 = secondaryBarSelector;
        menuBar = menuBarSelector;
        inParam = inParamName;
        inLinks = {};
        var reqState = "";
        if (typeof (postStateSelector) != "undefined" && jQuery(postStateSelector).length) {
            $state = jQuery(postStateSelector);
        }

        //	Find if there is a state saved
        //	from URL hash
        queryString2iNav();
        if (document.location.hash.length) {
            reqState = document.location.hash;
        }
        //	from current postback state
        if ((reqState == "")
			&& ($state.length > 0)
			&& (typeof ($state.val()) != "undefined")
			&& ($state.val() != "")) {
            reqState = $state.val();
        }
        //	Store links and sub-links structure we must handle in inLinks private object. 
        //  Filter out menuBar items that have deeplink attribute because those links are already being populated in array with main content.
        jQuery(bar + ' li a, ' + menuBar + ' li a:not([deeplink])').each(function () {
            if (jQuery(this).attr('href').indexOf('#') != -1) {

                //	Found #
                name = getHash(this);
                var $subPage = jQuery('[name="' + name.substr(1, name.length) + '"]');
                if ($subPage.length) {

                    //	Found content for this tab in current document
                    $subPage.hide();
                    if (name == reqState) {
                        //	Set current page in priv var
                        currTab = name;
                    }
                    //	Remove everything before the # from the href
                    jQuery(this).attr('href', name);
                    inLinks[name] = [];
                    $inPages[name] = $subPage;
                    if (jQuery(bar2, $subPage).length) {

                        //	Found sub-sub-nav
                        jQuery(bar2 + ' li a', $subPage).each(function () {
                            if (jQuery(this).attr('href').indexOf('#') != -1) {

                                //	Found #
                                var name2 = getHash(this);
                                var $subPage2 = jQuery('[name="' + name2.substr(1, name2.length) + '"]');
                                if ($subPage2.length) {

                                    //	Found content for this tab in current document
                                    $subPage2.hide();
                                    if (name2 == reqState) {
                                        //	Set current page in priv var
                                        currTab = name;
                                        currTab2 = name2;
                                    }
                                    //	Remove everything before the # from the href
                                    jQuery(this).attr('href', name2);
                                    inLinks[name].push(name2);
                                    $inPages[name2] = $subPage2;
                                }
                            }
                        });
                    }
                }
            }
        });

        //	Select current active tabs and display appropiate containers
        updateUI();

        //	Attach onclick listeners to links in document that start with # including nav bars.
        //	Deeplinking will navigate away and be handled by targeted page.        
        jQuery('a[href^=#], a[href^="' + window.location.pathname + '#"]').live('click', function (e) {
            var href = getHash(this);
            showTab(href);
        });

        //Attach onhashchange listener for handling of back button and javascript history.back functionality
        jQuery(window).hashchange(function () {
            var href = location.hash;
            showTab(href);
        })
    }

    //	Private methods
    var updateUI = function () {

        //	Determine which subpage or sub-subpage to show
        //	Do we have a sub page defined?
        if (currTab == "") {
            //	Default: first tab
            currTab = jQuery(bar + ' li:first a').attr('href');
            if (currTab.indexOf('#') > 0) {
                currTab = getHash(jQuery(bar + ' li:first a'));
                if ($inPages[currTab] != null) {
                    //$inPages[currTab].show();
                } else {
                    for (var key in $inPages) {
                        currTab = key;
                        if (typeof (first) !== 'function') {
                            break;
                        }
                    }
                }
            }
        }
        $inPages[currTab].show();
        //	Manage selected tab state
        jQuery('li', bar).removeClass("js-active");
        jQuery('a[href="' + currTab + '"]').closest('li').addClass("js-active");
        if ($state.length > 0) {
            $state.val(currTab);
        }

        //	Does this sub page have sub-sub pages?
        if (inLinks[currTab].length) {
            if (jQuery.inArray(currTab2, inLinks[currTab]) == -1) {
                //	Default: first tab
                currTab2 = jQuery(bar2 + ' li:first a', $inPages[currTab]).attr('href');
            }
            $inPages[currTab2].show();
            //	Manage selected tab state
            jQuery('li', bar2).removeClass("js-active");
            jQuery('a[href="' + currTab2 + '"]').closest('li').addClass("js-active");
            if ($state.length > 0) {
                $state.val(currTab2);
            }
        }

        //refresh iFrame content for all except current tab
        jQuery.each($inPages, function (key, value) {
            if (key != currTab) {
                jQuery(this).find('iframe').each(function () {
                    jQuery(this).attr('src', jQuery(this).attr('src'));
                });
            }
        });
        //request to have page simulate page load when switching between tabs OUT-3129
        window.scrollTo(0, 0);
    }
    var getHash = function (a) {
        //	Return the hash part from the passed element's href
        return jQuery(a).attr('href').substr(jQuery(a).attr('href').indexOf('#'), jQuery(a).attr('href').length);
    };
    var queryString2iNav = function () {
        //	Convert something like [url]&inav=tab-archive to [url]#tab-archive
        var tabName = document.location.search.split(inParam + "=");
        if (tabName.length > 1) {
            //	get rid of other params, if there are, after the one that we need
            tabName = tabName[1].split("&");
            tabName = tabName[0];
            if (tabName != "") {
                document.location.hash = "#" + tabName;
            }
        }
    }
    var showTab = function (href) {
        if (href == "") {
            //if no hash set, replicate entry point and show first tab
            $inPages[currTab].hide();
            currTab = "";
            currTab2 = "";
            updateUI();
        }
        else {
            if (jQuery.inArray(href, inLinks[currTab]) != -1) {

                //	Points to sub-sub page in current sub page
                $inPages[currTab2].hide();
                currTab2 = href;
                updateUI();
            }
            else if (typeof (inLinks[href]) != 'undefined') {

                //	Points to sub page
                $inPages[currTab].hide();
                currTab = href;
                updateUI();
            }
            else if (typeof ($inPages[href]) != 'undefined') {

                //	Points to sub-sub page not in current sub page
                jQuery.each(inLinks, function (tab, subTabs) {
                    if (jQuery.inArray(href, subTabs) != -1) {

                        //	Found parent tab, update UI and exit
                        $inPages[currTab].hide();
                        currTab = tab;
                        currTab2 = href;
                        updateUI();
                        return false;
                    }
                });
            }
        }
    };
}
// Needed for the Turnstile page. Redirect to a page specified in the destinationParam, preserving the query string
function redirect(destinationParam) {
    var queries = window.location.search.substring(1).split("&");
    var destination = undefined;
    var strippedQuery = undefined;
    for (var i = 0; i < queries.length; i++) {
        var query = queries[i].split("=");
        if (query[0] == destinationParam) {
            destination = query[1];
        }
        else {
            if (strippedQuery) {
                strippedQuery += "&";
            }
            else {
                strippedQuery = "";
            }
            strippedQuery += query[0] + "=" + query[1];
        }
    }
    if (destination) {
        if (strippedQuery) {
            destination += "?" + strippedQuery;
        }
        jQuery('body').delay(400).queue(function () {
            window.location = "http://" + destination;
        });
    }
}

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 

//Interstitial loading dialog, moved to global.js from book.js for global usage. 07-26-11

//var dialogLoading = jQuery(".dialog-results-loading").dialog({
//    bgiframe: true,
//    autoOpen: false,
//    modal: true,
//    dialogClass: 'results-loading',
//    width: 669,
//    height: 240,
//    zIndex: 3999,
//    position: 'center',
//    resizable: false,
//    open: function (ev, ui) {
//        if (jQuery.browser.msie && jQuery.browser.version.indexOf("6") == 0) {
//            jQuery('select').css('visibility', 'hidden');
//        }
//        jQuery('.results-loading').css('border', '4px solid #999');
//        progressBar();
//    },
//    close: function (ev, ui) {
//        jQuery('select').css('visibility', 'visible');
//    }
//});

//function progressBar() {
//    var jqt = setTimeout(function () { jQuery('.dialog-results-loading .dialog-progressbar').css({ 'background-image': 'url(../images/loader-spinner.gif)' }); }, 250);
//}

//function showLoadingDialog() {
//    dialogLoading.dialog('open');
//}

//function hideLoadingDialog() {
//    dialogLanding.dialog('close');
//}
