﻿function moveScroller(anchor, scroller) {
    var a = function () {
        var b = $(window).scrollTop();
        var d = $(anchor).offset({ scroll: false }).top;
        var c = $(scroller);

        if (c.height() >= $(window).height()) {
            return; //If the div is greater than the height of the window, then dont scroll
        }

        if (b > d) {
            c.css({ position: "fixed", top: "0px" })
        } else {
            if (b <= d) {
                c.css({ position: "relative", top: "" })
            }
        }
    };
    $(window).scroll(a); a()
}



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 SingleClickButton(sender, validationGroup) {
    if (typeof (validationGroup) == 'boolean' && validationGroup === false) //Does not require validation on client-side
    {
        sender.onclick = function () { alert('Request is being processed... Please wait...'); return false; }
    }
    else { //client side validation may be required
        var validated = true;
        if (typeof (Page_ClientValidate) == 'function') {
            validated = Page_ClientValidate(validationGroup);
        }
        if (validated) {
            sender.onclick = function () { alert('Request is being processed... Please wait...'); return false; }
        }
        else {
            return false;
        }
    }

}

function getQuerystring(urlWithQueryString, key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(urlWithQueryString);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function checkCookie() {
    username = getCookie('username');
    if (username != null && username != "") {
        alert('Welcome again ' + username + '!');
    }
    else {
        username = prompt('Please enter your name:', "");
        if (username != null && username != "") {
            setCookie('username', username, 365);
        }
    }
}



function closeHomePageSplashGeneric(val, storeCode) {
    //var storeCode = '<%=CurrentStore.RWStore.StoreCode%>';
    var id = 'divHomePageSplashContainer';
    var cookieName = "HomePageSplash-" + storeCode; //not a good idea to create cookie for each store, but for faster delivery have to do this
    var promo = val;
    var toCookieValue = '';
    var embHomePageFlash = document.getElementById("divHomePageSplashContainer").getElementsByTagName("embed");
    if (embHomePageFlash) {
        var src = embHomePageFlash[0].getAttribute("src");
        if (src) {
            promo = getQuerystring(src, "promo");
        }
    }
    if (typeof (promo) !== "undefined" && promo != '') {
        toCookieValue = promo;
        var existingCookie = getCookie(cookieName);
        if (existingCookie != null && existingCookie != "") {
            if (existingCookie.indexOf(promo) >= 0) {
                toCookieValue == ''; //No need to set the cookie because it already exists
            }
            else {
                //If value doesn't exist in the list, then add it
                toCookieValue = existingCookie + " " + promo;
            }
        }
    }

    if (toCookieValue != null && toCookieValue != '') {
        setCookie(cookieName, toCookieValue, null);
    }

    document.getElementById(id).style.display = 'none';

}


/****** (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 () {

    if($(".hiddenPopupClicker") !== null)
    {
        $(".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) blink ********/
String.prototype.format = function () {
    var s = this,
        i = arguments.length;

    while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
    }
    return s;
};

function startBlink(ctrlId, class1, class2) {
    setInterval("doBlink('{0}', '{1}', '{2}')".format(ctrlId, class1, class2), 1000);
}

function doBlink(ctrlId, class1, class2) {
    var lblPaymentInstruction = document.getElementById(ctrlId);
    if (lblPaymentInstruction.className) lblPaymentInstruction.className = (lblPaymentInstruction.className == class1) ? class2 : class1;
}

/***** (END) blink ********/

/***(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)  New JIT version Nivo Slider ********************/


function LoadNivoSliderFor(selector) {



   var total = $(''+selector +' img').length;
   var current_slide_no = 1; // garbage


    $(selector).nivoSlider({
        effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 3000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 1, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function () { }, // Triggers before a slide transition
        afterChange: function(){
                current_slide_no =  $(selector).data('nivo:vars').currentSlide;
                 $('#nivo-slider-status > .current-slide').html(current_slide_no+1); 
                 }, // Triggers after a slide transition
        slideshowEnd: function () { }, // Triggers after all slides have been shown
        lastSlide: function () { }, // Triggers when last slide is shown
        afterLoad: function () { } // Triggers when slider has loaded
    });

     $('#nivo-slider-status').show();
     $('#nivo-slider-status > .total-slides').html(total);
     current_slide_no = $(selector).data('nivo:vars').currentSlide;
     $('#nivo-slider-status > .current-slide').html(current_slide_no+1);


}

/***** (END)  New JIT version Nivo Slider ********************/

/***** (START)  Clue Tip ********************/

function LoadClueTipsFor(selector, closeTextImagePath) {
    // function() { 
    $(selector).cluetip({

        width: 'auto',
        height: 'auto',
        showTitle: true,
        sticky: true,
        mouseOutClose: false,
        ajaxCache: true,
        arrows: true,
        tracking: false,
        waitImage: true,
        closePosition: 'title',
        titleAttribute: 'title',
        hoverClass: 'highlight',
        closeText: "<img src='" + closeTextImagePath + "' alt='close' />",
        fx: {
                              open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
                              openSpeed:  '500'
            },



    });
    // });
}
/***** (END)  Clue Tip ********************/

