﻿
function PreCacheMenuNavigationImages(paramImgUrls) {
    var imgUrls = paramImgUrls;
    var loaded = 0;
    var errorTimer;

    var settings = {
        errorDelay: 999 // handles 404-Errors in IE
    };


    function onImgComplete() {
        clearTimeout(errorTimer);
        if (imgUrls && imgUrls.length && imgUrls[loaded]) {
            loaded++;
            loadImgs();
        }
    }


    function loadImgs() {
        //only load 1 image at the same time / most browsers can only handle 2 http requests, 1 should remain for user-interaction (Ajax, other images, normal page requests...)
        // otherwise set simultaneousCacheLoading to a higher number for simultaneous downloads
        if (imgUrls && imgUrls.length && imgUrls[loaded]) {
            var img = new Image(); //new img obj
            img.src = imgUrls[loaded]; //set src either absolute or rel to css dir
            if (!img.complete) {
                jQuery(img).bind('error load onreadystatechange', onImgComplete);
            } else {
                onImgComplete();
            }
            errorTimer = setTimeout(onImgComplete, settings.errorDelay); // handles 404-Errors in IE
        }
    }

    loadImgs(); //Call the function to start the function
    return imgUrls;
}



function bindUpdatePanelEndRequest() {
    if (typeof (Sys) != "undefined") {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(OnUpdatePanelEndRequest);
    }
}

function OnUpdatePanelEndRequest() {
    if (typeof (_wr_i) != "undefined") {
        _wr_i(_wr_d.body);
    }
    if (typeof (_wr_re) != "undefined") {
        _wr_re(_wr_d.body);
    }
}

function ShowEnlargedRoomImgThumb(link, largeImgId, thumbNailHandlerPath) {

    if (typeof (link) != "undefined") {
        var largeImg = document.getElementById(largeImgId);
        if (largeImg) {
            var thumbImgUrl = thumbNailHandlerPath + "&Width=" + largeImg.width + "&Height=" + largeImg.height;
            //var thumbImgUrl = thumbNailHandlerPath + "&Width=211&Height=158";
            largeImg.src = thumbImgUrl;
        }
    }

    return false;
}



/****** (START) Social Media Marketing Control ************/

var addthis_config = {
    data_track_clickback: true,
    services_exclude: 'twitter'
};

function fb_comments(sender, url) {
    var FBGraphURL = "https://graph.facebook.com/?ids=" + escape(url) + "&callback=?";
    $.getJSON(FBGraphURL, function(data) {
        var commentsCount = 0;
        if (data[url].comments) {
            commentsCount = data[url].comments;
        }
        $("#" + sender).innerHTML = commentsCount;
    });
}

/****** (END) Social Media Marketing Control ************/


/***** (START) FancyBox  **************/

$(document).ready(function() {

    $(".hiddenPopupClicker").each(
        function() {
            var fancybox_iframe = $('.hiddenPopupClicker');
            if (fancybox_iframe.length > 0) {
                fancybox_iframe.each(function(index) {
                    // Inline frame width param                    

                    if ($(this).attr('href').match(/width=[0-9]+/i)) {
                        var fWidth = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=', ''));
                    } else {
                        var fWidth = '70%';
                    }
                    // Inline frame height param
                    if ($(this).attr('href').match(/height=[0-9]+/i)) {
                        var fHeight = parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=', ''));
                    } else {
                        var fHeight = '70%';
                    }
                    if (window.console && window.console.log) {
                        console.log('fWidth #' + index + ': ' + fWidth);
                        console.log('fHeight #' + index + ': ' + fHeight);
                    }

                    $(this).fancybox({
                        'padding': 0,
                        'zoomOpacity': true,
                        'zoomSpeedIn': 500,
                        'zoomSpeedOut': 500,
                        'overlayOpacity': 0.75,
                        'hideOnContentClick': false,
                        'hideOnOverlayClick': true,
                        'overlayShow': true,
                        'modal': false,
                        'titlePosition': 'outside',
                        'titleShow': false,
                        'speedIn': 500,
                        'speedOut': 500,
                        'transitionIn': 'elastic',
                        'transitionOut': 'elastic',
                        'autoScale': false,
                        'autoDimensions': false,
                        'width': fWidth,
                        'height': fHeight,
                        'enableEscapeButton': true,
                        'orig': this
                    });
                });
            }
        });
});

/***** (END) FancyBox  **************/


/******(START) Carousel ***************/

var oRotator = null;
function onRotatorLoadHandler(sender, args) {
    oRotator = sender;
}


function RadRotatorResume(radrotatorId) {

    var rotatorWrapper = $find(radrotatorId);
    if (rotatorWrapper) {
        rotatorWrapper.repaint();
        //   alert(rotatorWrapper.get_items());
        //rotatorWrapper.start();
        rotatorWrapper.resume();
        rotatorWrapper.showNext(Telerik.Web.UI.RotatorScrollDirection.Left);
    }
}

function LoadCarousel(selector) {

    $("." + selector).jcarousel({
        wrap: 'circular',
        scroll: 1,
        auto: 1,
        visible: 4,
        animation: 1000,
        initCallback: mycarousel_initCallback
    });

}

function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto();
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto();
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
        if (oRotator)
            RadRotatorResume(oRotator);
    }, function() {
        carousel.startAuto();
    });
};

function LoadCarouselExpand(selector) {

    $("ul." + selector + " li div div").hover(function() {

        //   setTimeout(function () { $find(radrotatorId).repaint(); }, 10);

        $(this).find('div.info').addClass("Expanddisplay");
        $(this).find('div.info').removeClass("ExpanddisplayNone");
        $(this).find('div.info').addClass("hover").stop().animate({ height: '200px', top: '-80px', right: '0px' }, 200);
    }, function() {

        $(this).find('div.info').removeClass("Expanddisplay");
        $(this).find('div.info').removeClass("hover").stop().animate({ height: '0px', top: '0px', right: '0px' }, 400);
        var dothis = this;
        window.setTimeout(function() {

            $(dothis).find('div.info').addClass("ExpanddisplayNone");
        }, 300);
    });
}



/******(END) Carousel ***************/


/*********** (START) ScrollBar *************/

function LoadScrollBar(contentainer, pSize, pSizethumb) {
    $(document).ready(function() {

        pSize = pSize || 'auto';
        pSizethumb = pSizethumb || 'auto';

        $('#' + contentainer).tinyscrollbar({
            sizethumb: pSizethumb,
            size: pSize
        });
    });
}

/******** (END) ScrollBar  ****************/


/***(START) Added by kapil for Social Media Control Cookie ********/
function ShowHideSocialMediaControl(Url) {
    var result = confirm('Are you sure you want to close this panel?');
    if (result) {
        window.location.href = Url;
    }
}
/***(END) Added by kapil for Social Media Control Cookie ********/

$(document).ready(function() {
    if (typeof addthis === 'undefined' || addthis == null) {
        return;
    }
    addthis.init();
});

/*********** (START) Easy Slider **********/
function LoadEasySlider(control, pAuto, pContinuous, pSpeed, pPause) {
    $(document).ready(function () {

        pAuto = pAuto || 'false';
        pContinuous = pContinuous || 'false';
        pSpeed = pSpeed || 800;
        pPause = pPause || 2000;
        $('#' + control).easySlider({
            auto: pAuto,
            continuous: pContinuous,
            speed: pSpeed,
            pause: pPause
        });
    });
}
/*********** (END) Easy Slider ************/



/**************** (START) Set BIG Image For Showing In Popup( Rooms And Facility Page)  **********/

function ShowBigImage(link, largeImgId, thumbNailHandlerPath, type, typeValue) {
    if (typeof (link) != "undefined") {

        var imgLink = document.getElementById('linkImage');
        var vdoLink = document.getElementById('linkVideo');

        if (type == "image") {
            if (imgLink) {
                imgLink.href = typeValue;
                imgLink.setAttribute("type", type);
                imgLink.style.display = "block";
            }

            if (vdoLink) {
                vdoLink.style.display = "none";
            }
        }

        if (type == "video") {
            if (vdoLink) {
                vdoLink.href = typeValue;
                vdoLink.setAttribute("type", type);
                vdoLink.style.display = "block";
            }

            if (imgLink) {
                imgLink.style.display = "none";
            }
        }

        var largeImg = document.getElementById(largeImgId);

        if (largeImg) {
            largeImg.src = thumbNailHandlerPath;
        }

        //       var divThumbImgCollection = document.getElementById("divThumbImageCollection");
        //        for (i = 0; i < divThumbImgCollection.childNodes.length; i++) {

        //            var divThumbImage = divThumbImgCollection.childNodes.item(i);
        //            var thumbAnchor = $(divThumbImage).find("a");
        //            var thumbImage = $(divThumbImage).find("img");
        //            if (thumbAnchor == link) {
        //                thumbImage.className = "selectedImage";
        //            }
        //            else {
        //                thumbImage.className = "roomsImageBorder";
        //            }         
        //        }         
    }
    return false;
}

/****** Load the Image And Video PopUp ***********/

function LoadImageAndVideoPopup(ImageLink, VideoLink) {
    $(document).ready(function() {
       
        var popupImageAnchor = document.getElementById(ImageLink);
        var popupVideoAnchor = document.getElementById(VideoLink);

        LoadImagePopup(popupImageAnchor);
        LoadVideoPopup(popupVideoAnchor);

    });
}

/******** End of Image And Video Popup ************/



function LoadImagePopup(sender) {
    $(sender).fancybox({
        'padding': 0,
        'zoomOpacity': true,
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 500,
        'overlayOpacity': 0.75,
        'hideOnContentClick': false,
        'hideOnOverlayClick': true,
        'overlayShow': true,
        'modal': false,
        'titlePosition': 'outside',
        'titleShow': false,
        'speedIn': 500,
        'speedOut': 500,
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'autoScale': false,
        'autoDimensions': false,
        'width': 800,
        'height': 600,
        'enableEscapeButton': true,
        'orig': sender
    });

    return false;
}

function LoadVideoPopup(sender) {

    $(sender).fancybox({
        'padding': 0,
        'autoScale': false,
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'title': sender.title,
        'width': 680,
        'height': 495,
        'orig': sender,
        'speedIn': 500,
        'speedOut': 500,
        'href': sender.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
        'type': 'swf',
        'swf': {
            'wmode': 'transparent',
            'allowfullscreen': 'true'
        }
    });


    return false;
}



/**************** (END)Set BIG Image For Showing In Popup( Rooms And Facility Page *******************/

