﻿
// ***************************************
// ***** GUI Global UI initialization ****
// ***************************************


$(document).ready(function() {

    // Left margin featured widget init
    $(".widget-leftfeatured a.title").click(function() {
        $(this).next().toggle();
        return false;
    });

    // Middle Accordion init
    $("#accordion-middle .title").not($('.opened')).next().hide();

    $("#accordion-middle .title-red").click(function() {
        $("#accordion-middle .title-red").not(this).next().hide('slow');
        $(this).toggleClass("title-red-hide");
        $(this).next().toggle('slow');
    });

    $("#accordion-middle .title").click(function() {
        $("#accordion-middle .title").not(this).next().hide('slow');
        $(this).toggleClass("title-hide");
        $(this).next().toggle('slow');

    });

    // Simple tabs
    $("#simpletabs #tabs .tab").click(function() {
        var idx = $("#simpletabs #tabs > li").index($(this).parent());
        $("#simpletabs #tabcontent > li").hide();
        $("#simpletabs #tabcontent > div").hide();
        $("#simpletabs #tabcontent > li").eq(idx).show();
        $("#simpletabs #tabcontent > div").eq(idx).show();
        $("#simpletabs #tabs .tab-on").removeClass("tab-on");
        $(this).addClass("tab-on");
    });


    // Image preloader
    // Usage: $.preLoadImages("image1.gif","image2.gif");

    var preloadcache = [];
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            preloadcache.push(cacheImage);
        }
    }

    Sys.Application.add_load(function() {
        // UI QUICKVIEW **** TURNED OFF *****
        //$("a[href*=/product/]").each(function() {
        //    QuickViewInit(this);
        //});

        //$("area[href*=/product/]").each(function() {
        //    QuickViewInit(this);
        //});
    });

})

/******************************************************************************************************************************/
/*
/*      User Interface Module - QUICKVIEW
/*
/*      Developer: Scott Yu
/*      Date: 01/08/2010
/*
/******************************************************************************************************************************/

function QuickViewInit(obj) {
    // reset link
    var url = $(obj).attr("href");
    var isPostback = false;
    var baselink = $(obj);
    // parse link
    var qv_lang = url.match(/(en|fr)-CA/gi)[0];
    var qv_sku = url.match(/((M|BDL|B)?[0-9]+)\.\aspx/gi)[0].replace(/\.\aspx/gi, "");

    if (qv_lang && qv_sku && !$(obj).attr("onclick") && $(obj).attr("rel") != "noqv" && $(obj).parent().attr("id") != "languages") {

        // mouse-over event
        var qv_delay;
        var newmousepos_x, newmousepos_y;
        baselink.mouseover(function(kmouse) {
            if ($("#qv_" + qv_sku).length == 0) {
                $("body").append('<div class="quickview" id="qv_' + qv_sku + '"><img src="/images/common/pictures/progress.gif" border="0" class="loading"></div>');
                $("#qv_" + qv_sku).attr("rel", kmouse.pageX + "," + kmouse.pageY);
                $("#qv_" + qv_sku).load("/" + qv_lang + "/quickview/" + qv_sku + ".aspx?AllowSecure=True .box", null, function(rt, status) {
                    if (status == "success") {
                        // remove title link
                        $("#qv_" + qv_sku).find("a").each(function() {
                            var temp = $(this).html();
                            $(this).replaceWith(temp);
                        });

                        if (navigator.appName == "Microsoft Internet Explorer") {
                            $("#qv_" + qv_sku).find(".customerrating").css("margin-bottom", "7px");
                        }

                        // fix rating image path
                        $("#qv_" + qv_sku).find(".rating img").each(function() {
                            $(this).attr("src", $(this).attr("src").replace(/(\.\.\/)+/gi, "/")); // firefox
                            $(this).attr("src", $(this).attr("src").replace(/^(.*)images/gi, "/images")); // ie
                        });

                        // spec alt row style
                        $("#qv_" + qv_sku).find(".stdlist3 li:even").addClass("alt");
                        if ($("#qv_" + qv_sku).find(".stdlist3 li").length == 0)
                            $("#qv_" + qv_sku).find(".stdlist3").hide();

                        // spec seperate value from name
                        $("#qv_" + qv_sku).find(".stdlist3 li").each(function() {
                            $(this).html("<span class=\"name\">" + $(this).text().replace(/:( )?/, ":</span><span class=\"value\">") + "</span>");
                            if (navigator.appName != "Microsoft Internet Explorer") {
                                $(this).append("<div class=\"clear\"></div>");
                            } else {
                                $(this).css("display", "inline-block");
                            }
                        });

                        // availability
                        $("#qv_" + qv_sku).append("<div class=\"availability\"><ul class=\"stores\">");
                        $("#qv_" + qv_sku).find(".availability").prepend("<span class=\"title\">" +
                        $("#qv_" + qv_sku).find(".onlineavailability h3").text().match(/(Availability|Disponibilité)/gi) +
                        "</span>");

                        // online availability
                        var onlineli;
                        if ($("#qv_" + qv_sku).find(".onlineavailability p span").text().search(/not/gi) > 0) {
                            onlineli = $("<li>").html("<img src=\"/images/common/pictures/ico-out-of-stock.gif\" border=\"0\">futureshop.ca")
                        } else {
                            onlineli = $("<li>").html("<img src=\"/images/common/pictures/ico-in-stock.gif\" border=\"0\">futureshop.ca")
                        }
                        $("#qv_" + qv_sku).find(".availability .stores").append(onlineli);

                        // in-store availability

                        $("#qv_" + qv_sku).find(".in-store-availability ul li").each(function() {
                            var tempStore;
                            tempStore = $("<li>").html("<img src=\"" + $(this).find("input").attr("src") + "\" border=\"0\">" + $(this).text().trim());
                            $("#qv_" + qv_sku).find(".availability .stores").append(tempStore);
                        });

                        // customer review
                        if ($("#qv_" + qv_sku).find("#readreviews").text().search(/\(/g) > 0) {
                            var txt_review;
                            txt_review = $("#qv_" + qv_sku).find("#readreviews").text().match(/\([0-9]*\)/g);
                            if (qv_lang == "fr") {
                                txt_review = String(txt_review).replace(/\(/g, "").replace(/\)/g, "") + " évaluations des clients";
                            } else {
                                txt_review = String(txt_review).replace(/\(/g, "").replace(/\)/g, "") + " customer reviews";
                            }

                            $("#qv_" + qv_sku).find("#ProductImageControlMainContainer").prepend("<span class=\"customerreview\">" + txt_review + "</span>");
                        }
                        $("#qv_" + qv_sku).width(250);
                        if ($("#qv_" + qv_sku).attr("rel") != "") {
                            newmousepos_x = parseInt($("#qv_" + qv_sku).attr("rel").split(",")[0]);
                            newmousepos_y = parseInt($("#qv_" + qv_sku).attr("rel").split(",")[1]);
                        }
                        var move_x, move_y;
                        if (newmousepos_y - 65 < getScrollY() + 5) {
                            move_y = getScrollY() + 5;
                        } else if (newmousepos_y - 65 + $("#qv_" + qv_sku).height() > getScrollY() + getViewSize()[1] - 20) {
                            move_y = getScrollY() + getViewSize()[1] - 20 - $("#qv_" + qv_sku).height();
                        } else {
                            move_y = newmousepos_y - 65;
                        }
                        move_x = (newmousepos_x + 75 + $("#qv_" + qv_sku).width() > getViewSize()[0]) ?
                                newmousepos_x - 35 - $("#qv_" + qv_sku).width() :
                                newmousepos_x + 35;
                        if (parseInt($("#qv_" + qv_sku).css("left").replace(/px/gi, "")) > 0) {
                            $("#qv_" + qv_sku).animate({ left: move_x, top: move_y }, { queue: false, duration: 100 });
                        }
                    } else {
                        $("#qv_" + qv_sku).remove();
                    }
                });
            }
            qv_delay = setTimeout(function() {
                $("#qv_" + qv_sku).css({ opacity: 0 });
                $("#qv_" + qv_sku).animate({ opacity: 1 }, { queue: false, duration: 500 });
            }, 1000);
        }).mousemove(function(kmouse) {
            var move_x, move_y;
            if (kmouse.pageY - 65 < getScrollY() + 5) {
                move_y = getScrollY() + 5;
            } else if (kmouse.pageY - 65 + $("#qv_" + qv_sku).height() > getScrollY() + getViewSize()[1] - 20) {
                move_y = getScrollY() + getViewSize()[1] - 20 - $("#qv_" + qv_sku).height();
            } else {
                move_y = kmouse.pageY - 65;
            }
            move_x = (kmouse.pageX + 75 + $("#qv_" + qv_sku).width() > getViewSize()[0]) ?
                    kmouse.pageX - 35 - $("#qv_" + qv_sku).width() :
                    kmouse.pageX + 35;
            $("#qv_" + qv_sku).css({ left: move_x, top: move_y });
            $("#qv_" + qv_sku).attr("rel", kmouse.pageX + "," + kmouse.pageY);
        }).mouseout(function() {
            clearTimeout(qv_delay);
            $("#qv_" + qv_sku).css({ left: -9999 }).animate({ opacity: 0 }, { queue: false, duration: 20 });
        }).click(function() {
            clearTimeout(qv_delay);
            $("#qv_" + qv_sku).css({ left: -9999 }).animate({ opacity: 0 }, { queue: false, duration: 20 });
        });

    }
}

function FeatureProductEqualiseBoxesHeight() {
    var divHeight = 144;

    if ($.browser.msie) {
        divHeight = 147;
    }
    
    $(".featureproduct .content").height($(".pdpdetailbox .dheight1-2:first").height() + divHeight);
}

function simpletabsSelect(idx) {
    $("#simpletabs #tabs .tab").eq(idx).click();
}

/******************************************************************************************************************************/
/*
/*      User Interface Module - LIGHTBOX
/*
/*      Developer: Scott Yu
/*      Date: 12/02/2009
/*
/******************************************************************************************************************************/

/******************************************************************************************************************************/
// LIGHTBOX TRIGGER POINTS
// set up links for popover
//
// PARAMS: ele = lightbox object

$.fn.uilightboxlink = function(ele) {
    var counter = 1;
    return this.each(function() {
        var url = $(this).attr("href");
        $(this).attr("href", "#"); // modify link behavior
        if ($(this).attr("ref")) {
            counter = $(this).attr("ref"); // position in gallery view if available		
        } else {
            $(this).attr("ref", counter); // auto assign position in gallery view
            counter++;
        }
        var lbl = $(this);
        $(this).click(function() {
            $(ele).find(".ui-viewpanel").uiLoader(true);
            $(ele).show();

            var cb;
            if ($(ele).find(".ui-loader").attr("ref") == "autorun") {
                if (url.match(/([^\/\\]+)\.(jpg|jpeg|gif|png)$/i)) {
                    cb = function() { LoadImageViwer(ele, url, $(lbl).attr("ref")) }; // load image
                } else if (url.match(/([^\/\\]+)\.(swf)/i)) {
                    cb = function() {
                        // parse querystring
                        var qs = url.slice(url.search(/[?]/i) + 1);
                        var i, qsPairs = new Array(), qsPair;
                        for (i = 0; i < qs.split("&").length; i++) {
                            qsPair = qs.split("&")[i];
                            qsPairs[qsPair.split("=")[0]] = qsPair.split("=")[1];
                        }
                        LoadVideoPlayer(ele, url, $(lbl).attr("ref"), { // load video
                            varAutoRun: qsPairs["varAutoPlay"],
                            width: parseInt(qsPairs["width"]),
                            height: parseInt(qsPairs["height"]),
                            srcFlv: qsPairs["varSource"]
                        });
                    };
                } else if (url.match(/(^#.{1,})/i)) {
                    // div content available
                    cb = function() {
                        LoadPopoverContent(ele, url);
                    }
                }
                runLoader(ele, cb);
            } else {
                setLoader(ele, 0); // not being used atm
            }

            $("#ui-lightbox-dim").show();
            return false;
        });
    });
}

// initialize gallery view
$.fn.uilightboxgallery = function(ele) {
    return this.each(function() {
        $(ele).uiImageViewer(this);
        $(this).find("li > a").uilightboxlink(ele);
    });
}

/******************************************************************************************************************************/
// LIGHTBOX
//
// creating a new lightbox intance
function uilightbox(id) {

    var obj = $("<div>").addClass("ui-lightbox").attr("id", id).append('<div class="ui-viewpanel"></div>'); // html
    $("BODY").append(obj);

    if (!$("#ui-lightbox-dim").length) {
        $("BODY").append('<div id="ui-lightbox-dim"></div>'); // setting up bg if not exist
        dimBackground($("#ui-lightbox-dim"));

        $("#ui-lightbox-dim").click(function() { // close lb on click outside
            $(".ui-lightbox").fadeOut(function() {
                $(this).find(".ui-viewpanel").empty();
            });
            $("#ui-lightbox-dim").hide();
            return false;
        });
    }

    var lb = $("#" + id); // lightbox object
    //$(lb).draggable();

    // set up control panel
    $(lb).prepend('<div class="ui-controls"></div>');

    $(lb).find(".ui-controls").append('<div class="pnlClose"><a href="#" class="btnClose">close</a></div>'); // html

    // CLOSE button
    $(lb).find(".pnlClose").css({ opacity: 1 });
    $(lb).find(".btnClose").click(function() {
        $("#ui-lightbox-dim").click();
        return false;
    });

    positionPanel(lb); // position controls

    // on windows resize
    $(window).bind('resize', function() {
        if ($(lb).css("display") != "none" && $(lb).css("opacity") == 1) {
            dimBackground($("#ui-lightbox-dim"));
            positionPanel(lb, $(lb).width(), $(lb).height()); // re-position controls
        }
    });

    // on page scroll - disabled because of ff redraw problem
    //$(window).scroll(function() {		
    //	if ($(lb).css("display") != "none" && $(lb).css("opacity") == 1) {
    //		positionPanel(lb,$(lb).width(),$(lb).height()); // position controls
    //	}
    //});		

    return obj;
}

/******************************************************************************************************************************/
// GALLERY VIEW
//
// initialize gallery view
$.fn.uiImageViewer = function(galleryview) {
    return this.each(function() {

        var iv = this;
        $(this).addClass("ui-imageviewer");

        // set up controls
        if (galleryview) {
            $(this).find(".ui-controls").append('<div class="pnlPrevious"><a href="#" class="btnPrevious">previous</a></div>');
            $(this).find(".ui-controls").append('<div class="pnlNext"><a href="#" class="btnNext">next</a></div>');
            $(this).find(".ui-controls").append('<a href="#" class="btnNext-extend"></a>');
            $(this).find(".ui-controls").append('<a href="#" class="btnPrevious-extend"></a>');
        }
        positionPanel(iv); // reposition

        if (galleryview) {

            var totalImages = $(galleryview).find("li a").length;
            var currentImage;

            // NEXT button
            $(this).find(".btnNext").css({ opacity: 0 });
            $(this).find(".btnNext").click(function() {
                if ($(iv).find(".ui-viewpanel img").attr("ref")) {
                    currentImage = parseInt($(iv).find(".ui-viewpanel img").attr("ref"));
                } else if ($(iv).find(".ui-viewpanel div.phVideo").attr("ref")) {
                    currentImage = parseInt($(iv).find(".ui-viewpanel div.phVideo").attr("ref"));
                } else {
                    currentImage = 0;
                }
                if (currentImage == totalImages) {
                    $(galleryview).find("li:nth-child(1) a").click();
                } else {
                    $(galleryview).find("li:nth-child(" + (currentImage + 1) + ") a").click();
                }
                return false;
            });
            $(this).find(".btnNext").hover(function() {
                $(this).animate({ opacity: 1 }, { queue: false, duration: 250 });
            }, function() {
                $(this).animate({ opacity: 0 }, { queue: false, duration: 250 });
            });

            // PREVIOUS button
            $(this).find(".btnPrevious").css({ opacity: 0 });
            $(this).find(".btnPrevious").click(function() {
                if ($(iv).find(".ui-viewpanel img").attr("ref")) {
                    currentImage = parseInt($(iv).find(".ui-viewpanel img").attr("ref"));
                } else if ($(iv).find(".ui-viewpanel div.phVideo").attr("ref")) {
                    currentImage = parseInt($(iv).find(".ui-viewpanel div.phVideo").attr("ref"));
                } else {
                    currentImage = 0;
                }

                if (currentImage == 1) {
                    $(galleryview).find("li:nth-child(" + totalImages + ") a").click();
                } else {
                    $(galleryview).find("li:nth-child(" + (currentImage - 1) + ") a").click();
                }
                return false;
            });
            $(this).find(".btnPrevious").hover(function() {
                $(this).animate({ opacity: 1 }, { queue: false, duration: 250 });
            }, function() {
                $(this).animate({ opacity: 0 }, { queue: false, duration: 250 });
            });

            // NEXT-extend button
            var btnNextextend = $(this).find(".btnNext-extend");
            $(btnNextextend).click(function() {
                $(iv).find(".btnNext").click();
                return false;
            });
            $(btnNextextend).mouseover(function() {
                $(iv).find(".btnNext").mouseover();
            });
            $(btnNextextend).mouseout(function() {
                $(iv).find(".btnNext").mouseout();
            });

            // PREVIOUS-extend  button		
            var btnPreviousextend = $(this).find(".btnPrevious-extend");
            $(btnPreviousextend).click(function() {
                $(iv).find(".btnPrevious").click();
                return false;
            });
            $(btnPreviousextend).mouseover(function() {
                $(iv).find(".btnPrevious").mouseover();
            });
            $(btnPreviousextend).mouseout(function() {
                $(iv).find(".btnPrevious").mouseout();
            });
        }
    });
}

/******************************************************************************************************************************/
//  LOADING ANIMATION
//
// initialize loader
$.fn.uiLoader = function(autorun) {
    $(this).empty().html('<div class="ui-loader"><span class="ui-loader-bar"></span><span class="ui-loader-percentage"></span></div>');
    $(this).find(".ui-loader").css("top", $(this).parent().height() / 2 - 10);
    if (autorun) {
        $(this).find(".ui-loader").attr("ref", "autorun");
    }
}

// fake load
function runLoader(ele, cb) {
    var loader = $(ele).find(".ui-loader");
    $(loader).find(".ui-loader-bar").css({ backgroundPosition: "-99px 0" });
    $(loader).find(".ui-loader-bar").animate({
        backgroundPosition: "0px 0"
    }, { duration: 250, complete: cb });
}

// not being used. created for real precentage loading
function setLoader(ele, p, cb) {
    var loader = $(ele).find(".ui-loader");
    $(loader).find(".ui-loader-bar").animate({
        backgroundPosition: (-99 * (100 - p) / 100) + "px 0"
    }, { duration: 500, complete: cb });
}

/******************************************************************************************************************************/
// LOADERS
//
// load image into lightbox
function LoadImageViwer(ele, url, counter) {
    $(ele).find(".ui-viewpanel").empty().html('<img src="' + url + '" border="0" class="gallery-image" ref="' + counter + '" style="opacity:0">');

    var cb = function() {
        $(ele).find(".ui-viewpanel .gallery-image").animate({ opacity: 1 }, { queue: false, duration: 250 });
    }
    positionPanel(ele, $(ele).find(".ui-viewpanel .gallery-image").width(), $(ele).find(".ui-viewpanel .gallery-image").height(), cb); // reposition
}


// load div content into lightbox
function LoadPopoverContent(ele, url) {
    $(ele).find(".ui-viewpanel").empty().html($(url).html());

    var cb = function() {
        $(ele).find(".ui-viewpanel").animate({ opacity: 1 }, { queue: false, duration: 250 });
    }
    var tureWidth, trueHeight;
    trueHeight = $(ele).find(".ui-viewpanel .popcontent").height() + parseInt($(ele).find(".ui-viewpanel .popcontent").css("padding-top"))
        + parseInt($(ele).find(".ui-viewpanel .popcontent").css("padding-bottom"));
    trueHeight = (trueHeight > (getViewSize()[1] * 0.9)) ? (getViewSize()[1] * 0.9) : trueHeight;
    $(ele).find(".ui-viewpanel .popcontent").height(
        trueHeight - parseInt($(ele).find(".ui-viewpanel .popcontent").css("padding-top"))
        - parseInt($(ele).find(".ui-viewpanel .popcontent").css("padding-bottom"))
    );
    tureWidth = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)?
        $(url).width() + 28:
        $(url).width();
    positionPanel(ele, tureWidth, trueHeight, cb); // reposition

}

// load video into lightbox
function LoadVideoPlayer(ele, url, counter, vars) {
    var width, height;
    width = vars.width ? vars.width : 400; // default size
    height = vars.height ? vars.height : 300;

    $(ele).find(".ui-viewpanel").empty().html('<div class="phVideo" ref="' + counter + '"><div id="phVideo"></div></div>');
    $(ele).find(".ui-viewplanel .phVideo").css({
        width: width,
        height: height
    });

    var cb = function() {
        var flashvars = {
            varAutoPlay: vars.varAutoRun,
            varSource: vars.srcFlv
        };

        var params = {
            wmode: "transparent",
            allowscriptaccess: "always",
            base: ".",
            menu: "false"
        };
        var attributes = {};
        swfobject.embedSWF(url, "phVideo", width, height, "9.0.0", false, flashvars, params, attributes);
        $(ele).find(".ui-viewpanel .plVideo").animate({ opacity: 1 }, { queue: false, duration: 250 });
    }
    positionPanel(ele, width, height, cb); // re-position
}

/******************************************************************************************************************************/
// POSITIONING
//
// position background
function dimBackground(ele) {
    $(ele).css({
        width: getViewSize()[0],
        height:
			($("body").height() + parseInt($("body").css("margin-top").replace("px", ""))
				+ parseInt($("body").css("margin-bottom").replace("px", ""))
				+ parseInt($("body").css("padding-top").replace("px", ""))
				+ parseInt($("body").css("margin-bottom").replace("px", ""))) < getViewSize()[1]
			? getViewSize()[1]
			: ($("body").height() + parseInt($("body").css("margin-top").replace("px", ""))
				+ parseInt($("body").css("margin-bottom").replace("px", ""))
				+ parseInt($("body").css("padding-top").replace("px", ""))
				+ parseInt($("body").css("margin-bottom").replace("px", "")))
    });
}

/////////////////////////////////////////////// CUSTOMIZABLE //////////////////////////////////////////////////////////////////

// control positioning
function positionPanel(ele, w, h, cb) {

    if (w) {
        // default callback
        // if (!cb) { 
        // 	cb = function() {
        // 		$(ele).find(".pnlClose").animate({opacity:1},{queue:false,duration:250});					
        // 	}				
        // }
        var winHeight = 0, winWidth = 0;

        winWidth = getViewSize()[0];
        winHeight = getViewSize()[1];


        $(ele).find(".pnlClose").css({ opacity: 1 });
        $(ele).stop().animate({
            width: (w),
            height: (h),
            top: (winHeight - h) / 2 + getScrollY() - 10,
            left: (winWidth - w) / 2
        }, { queue: false, duration: 150, complete: cb }).css("overflow", "visible");


        $(ele).find(".pnlClose").animate({
            left: (w + 7)
        }, { queue: false, duration: 150 });

        $(ele).find(".pnlNext").animate({
            left: (w + 7),
            top: (h / 2 - 26)
        }, { queue: false, duration: 150 });

        $(ele).find(".pnlPrevious").animate({
            left: -26 - 7,
            top: (h / 2 - 26)
        }, { queue: false, duration: 150 });

        // position next-extend button
        $(ele).find(".btnNext-extend").animate({
            left: (w * 0.5 + 26 + 7),
            height: h
        }, { queue: false, duration: 150 });

        $(ele).find(".btnPrevious-extend").animate({
            left: -26 - 7,
            height: h
        }, { queue: false, duration: 150 });
    }

    // position loading bar
    $(ele).find(".ui-loader").css({
        top: (h / 2 - $(ele).find(".ui-loader").height() / 2)
    });
}

/******************************************************************************************************************************/
// cross browser functions
//

function getViewSize() {
    var winWidth = 0, winHeight = 0;
    if (typeof ($(window).width()) == 'number') {
        //Non-IE
        winWidth = $(window).width();
        winHeight = $(window).height();
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        winWidth = document.documentElement.clientWidth;
        winHeight = document.documentElement.clientHeight;
    }
    return [winWidth, winHeight];
}

function getScrollY() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && document.body.scrollTop) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}
