﻿var ie6Below = $.browser.msie && parseFloat($.browser.version) <= 6;
var ie7Below = $.browser.msie && parseFloat($.browser.version) <= 7;


function beginRequest(sender, args) {

    var el = sender._postBackSettings.sourceElement;

    // used on the kipproducts page. Having layout issues so blanking entire updatepanel
    $("#" + el.id).closest("[id*='udpKitProducts']").addClass("updatePanelLoading").each(function() {
        //        $(this).children().fadeTo("fast", 0.4);
        var overlay = $('<div class="udpLoadingOverlay"><div/>' + (ie6Below ? '<iframe frameborder="0" src="javascript:false;"></iframe>' : '') + '</div>').css({ height: this.offsetHeight });
        overlay.appendTo(this).show(); //fadeIn();
    });
    //    var parentEl = null;

    //    if (el.id.match(/btnAddToWishlist|btnAddToBag|AddtoCartBtn|btnRemoveItem|Button6/)) {
    //        //        __doPostBack( $j("[id*='updatePanelShoppingBag']").attr("id") , "updatebag" );
    //        el.origValue = el.value;
    //        setButtonDisabledState(el, true, el.id.match(/btnRemoveItem/) ? "Removing" : "Adding");
    //    }

}

function endRequest(sender, args) {
    var el = sender._postBackSettings.sourceElement;

    $(".updatePanelLoading").removeClass("updatePanelLoading");
    $(".udpLoadingOverlay").remove();
    $(".gallery").each(setupGallery);
    $(".shoppingcartquantitytext").attr("disabled", "disabled");

}

$(function() {

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);


    $(".scroller").each(setupScroller);
    // $(".tallScroller").each(setupTallScroller);

    $(".tallScroller").each(setupMultipleRowScroller);
    $(".gallery").each(setupGallery);
    $(".kitProducts").each(setupKitProduct);

    if (ie7Below) {
        $("a.ProductItem[href]").click(function() {
            location.href = this.href;
            return false;
        });
    }

    $(".sizingGuide").each(setupSizingGuide);

    $(".ajax-link").live('click', showAjaxContent);

    $("#forwardToWorldPay").each(function() {
        var cookieData = pageTracker._getLinkerUrl(location.href).match(/[^\?](\?.+)/)[1];
        $(this).append('<input type="hidden" name="GoogleCookieData" value="' + cookieData + '"/>');
    });

    $(".shoppingcartquantitytext").attr("disabled", "disabled");

});

function showAjaxContent() {

    var anchor = this;
    var ajaxPopup = null;

    $.ajax({
        url: anchor.href,
        cache: true,
        dataType: "html",
        success: function(html) {
            var strContent = html.match(/<!--CONTENTSTART-->([.\s\S]*)<!--CONTENTEND-->/i);
            if (!strContent || !strContent[1]) {
                location.href = anchor.href;
                return false;
            }
            var content = $("<div/>").append(strContent[1]).html();

            //content

            displayPanel(content);
        },
        error: function() {
            location.href = anchor.href;
        }
    });

    function removePopup() {
        ajaxPopup.fadeOut("slow", function() { $(this).remove(); $(".popFrame").remove(); });
        $(window).unbind("scroll");
        return false;
    }

    function displayPanel(html) {

        ajaxPopup = $('<div class="popup"></div><div class="ajaxContent"></div>').css("visibility", "hidden");
        ajaxPopup.filter(".popup").css("opacity", "0.4").click(removePopup);
        
        var close = $('<a class="topClose" title="Close window" href="#">x close</a>').click(removePopup)

        var sizingGuide = ajaxPopup.eq(1).append(html, close).find(".sizingGuide").each(setupSizingGuide);

        $("body").append(ajaxPopup);

        var popupTop = ajaxPopup.eq(1).offset().top;
        //var popupPaddingTop = ajaxPopup.eq(1).css("padding-top");
        var popupPaddingBottom = ajaxPopup.eq(1).css("padding-bottom").replace("px", "");

        if (sizingGuide.length) {
            var tabTop = sizingGuide.find(".tabContainer").offset().top;
            var tabPaddingTop = sizingGuide.find(".tabContainer").css("padding-top").replace("px", "");
            // 40px offset for top and bottom
            sizingGuide.find(".tabContent").height($(window).height() - (tabTop - popupTop) - popupPaddingBottom - 40 - tabPaddingTop);
        }
        else {
            ajaxPopup.eq(1).find(".contentGroup").height($(window).height() - 80).css("overflow", "auto");
        }
        //ajaxPopup.eq(0).height(document.body.scrollHeight);
        ajaxPopup.eq(0).height($(".outsideWrapper")[0].scrollHeight);

        ajaxPopup.hide().css("visibility", "visible");

        ajaxPopup.fadeIn();

        if (ie6Below) {
            ajaxPopup.eq(1).css({ top: (getScrollXY()[1] + 30), position: "absolute" });
            $(window).bind("scroll", function() {
                ajaxPopup.eq(1).stop().animate({ top: getScrollXY()[1] + 40 }, 500);
            });

            $("body").append('<iframe class="popFrame" style="position:absolute;top:0;left:0;width:100%;height:' + $(".outsideWrapper")[0].scrollHeight + 'px" frameborder="0" src="javascript:false;"></iframe>').find(":last").css("opacity", 0);

        }
        else {
            ajaxPopup.eq(1).css("top", 20);
        }

    }

    return false;
}

function setupSizingGuide() {
    var tabContainer = $('<div class="tabContainer"/>');
    var hash = 0;
    var tabs = $("h2", this).each(function(idx) {
        var tab = $('<div id="tab' + idx + '" class="tabContent"/>');
        $(this).addClass("tab");
        if (idx > 0) {
            tab.hide();
        }

        this.index = idx;

        $(this).nextAll().each(function() {
            if ($(this).is("h2")) return false;
            tab.append(this);
        });
        tabContainer.append(tab);
    }).click(function() {
        tabContainer.find(".tabContent").hide().eq(this.index).show();
        tabs.removeClass("active");
        $(this).addClass("active");
    });
    $(".contentGroupCopy", this).append(tabContainer).addClass("tabbing");
    tabs.eq(hash).addClass("active");
}

function setupKitProduct() {
    //    $(".ProductItem", this).each(function() {
    //        this.href = "#Show product";
    //        this.title = $(".productName", this).text();
    //    })
    $(".kitProducts .ProductItem").live('click', function() {
        __doPostBack($("input", this).attr("name"), '');
        return false;
    });
}

function setupScroller() {

    var productRow = $(".productRow", this);

    if (!productRow.length) return;

    var itemsPerPage = productRow.eq(0).children().length;

    // reuse the first produt row and puts all elements into it
    var items = $(".ProductItem", this);
    var scrollContainer = $(this);

    // Size of visible panel
    var visWidth = $(this).innerWidth();

    var imgNum = items.length;

    var pageNum = Math.ceil(imgNum / itemsPerPage);
    // Setup Scroller Controls

    var pageNumbering = $('<div class="pageNumbers"><strong><span class="low">1</span> - <span class="high">' + (imgNum > itemsPerPage ? itemsPerPage : imgNum) + '</span></strong> of ' + imgNum + '</div>');
    pageNumbering.appendTo(scrollContainer);

    if (pageNum > 1) {
        var imgWidth = items.eq(0).outerWidth(true);
        var scrollerWidth = imgWidth * imgNum;
        productRow.eq(0).append(items);
        productRow.filter(":gt(0)").remove();
        productRow = productRow.eq(0);
        productRow.css("width", scrollerWidth);

        var leftBut = $('<a href="#previous" class="prevBut lEnd">previous</a>');
        var rightBut = $('<a href="#next" class="nextBut">next</a>');
        pageNumbering.prepend(leftBut).append(rightBut);

        var pointer = 0;
        leftBut.add(rightBut).click(function(evt) {

            if (this.className.match(/.End/)) return false;

            var direction = (!this.className.match(/prevBut/) * 2) - 1;

            scroll(direction);
            return false;
        });

        function scroll(direction) {

            var move = direction * itemsPerPage;

            pointer = pointer + move;

            if (pointer + move > imgNum) pointer = imgNum - itemsPerPage;
            if (pointer < 0) pointer = 0;

            var low = pointer + 1;
            var high = pointer + itemsPerPage;

            if (pointer == 0) {
                leftBut.addClass("lEnd");
                rightBut.removeClass("rEnd");
            }
            else if (high == imgNum) {
                rightBut.addClass("rEnd");
                leftBut.removeClass("lEnd");
            }
            else {
                leftBut.removeClass("lEnd");
                rightBut.removeClass("rEnd");
            }

            productRow.animate({ marginLeft: -(imgWidth * pointer) }, 500);
            $(".low", scrollContainer).text(low);
            $(".high", scrollContainer).text(high);
        }

    }
}

function setupTallScroller() {

    var productRow = $(".productRow", this);

    if (!productRow.length) return;

    var itemsPerPage = productRow.eq(0).children().length;

    // reuse the first produt row and puts all elements into it
    var items = $(".ProductItem", this);
    var scrollContainer = $(this);


    // Size of visible panel
    var visWidth = $(this).innerWidth();

    var imgNum = items.length;

    var pageNum = Math.ceil(imgNum / itemsPerPage);
    // Setup Scroller Controls

    var pageNumbering = $('<div class="pageNumbers"><strong><span class="low">1</span> - <span class="high">' + (imgNum > itemsPerPage ? itemsPerPage : imgNum) + '</span></strong> of ' + imgNum + '</div>');
    pageNumbering.appendTo(scrollContainer);


    var div1 = $('<div class="scrollerItemContainer"></div>');



    if (pageNum > 1) {
        var imgWidth = items.eq(0).outerWidth(true);
        var scrollerWidth = imgWidth * imgNum;
        productRow.eq(0).append(items);

        productRow.filter(":gt(0)").remove();
        productRow = productRow.eq(0);

      
        var allItems = items;
       
        productRow.empty();

        for (var p = 0; p < allItems.length; p++) {
            //number is even
            if (!(p % 2)) {
                if (p != 0) {
                    productRow.append(div1);
                }
                div1 = $('<div class="scrollerItemContainer"></div>');
            }
            div1.append(allItems[p]);
        }

 
            productRow.append(div1);



        productRow.css("width", scrollerWidth);
        productRow.css("height", "630px");

        var leftBut = $('<a href="#previous" class="prevBut lEnd">previous</a>');
        var rightBut = $('<a href="#next" class="nextBut">next</a>');
        pageNumbering.prepend(leftBut).append(rightBut);

        var pointer = 0;
        leftBut.add(rightBut).click(function(evt) {

            if (this.className.match(/.End/)) return false;

            var direction = (!this.className.match(/prevBut/) * 2) - 1;

            scroll(direction);
            return false;
        });


        function scroll(direction) {

            var move = direction * itemsPerPage;

            pointer = pointer + move;

            if (pointer + move > imgNum) pointer = imgNum - itemsPerPage;
            if (pointer < 0) pointer = 0;

            var low = pointer + 1;
            var high = pointer + itemsPerPage;

            if (pointer == 0) {
                leftBut.addClass("lEnd");
                rightBut.removeClass("rEnd");
            }
            else if (high == imgNum) {
                rightBut.addClass("rEnd");
                leftBut.removeClass("lEnd");
            }
            else {
                leftBut.removeClass("lEnd");
                rightBut.removeClass("rEnd");
            }


//We change the pointers for these tall kinds because it is actually the pointer cut in half
            var tempPointer = pointer;
            if (imgNum % 2 && direction == 1) {
                tempPointer = (tempPointer + 1) / 2;
      
            }
          
            else
            {
                tempPointer = tempPointer / 2;
             
            }
            
            productRow.animate({ marginLeft: -(imgWidth * (tempPointer)) }, 500);
            $(".low", scrollContainer).text(low);
            $(".high", scrollContainer).text(high);
        }

    }
}


function setupMultipleRowScroller() {
    numberOfRows = 2;
    var productRow = $(".productRow", this);

    if (!productRow.length) return;

    var itemsPerPage = productRow.eq(0).children().length;
    
    
    // reuse the first produt row and puts all elements into it
    var items = $(".ProductItem", this);
    var scrollContainer = $(this);


    // Size of visible panel
    var visWidth = $(this).innerWidth();

    var imgNum = items.length;

    var pageNum = Math.ceil(imgNum / itemsPerPage);
    // Setup Scroller Controls

    var pageNumbering = $('<div class="pageNumbers"><strong><span class="low">1</span> - <span class="high">' + (imgNum > itemsPerPage ? itemsPerPage : imgNum) + '</span></strong> of ' + imgNum + '</div>');
    pageNumbering.appendTo(scrollContainer);


    var div1 = $('<div class="scrollerItemRow"></div>');
    
    var outsideDiv = $('<div class="outerItemContainer"></div>');



    if (pageNum > 1) {
        var imgWidth = items.eq(0).outerWidth(true);
        var imgHeight = items.eq(0).outerHeight(true);

        var outsideDivHeight = imgHeight * numberOfRows;

        var tempImagNum = imgNum;
        if (imgNum % numberOfRows > 0) {
            tempImagNum = tempImagNum + (imgNum % numberOfRows);

        }
            var scrollerWidth = imgWidth * (tempImagNum /numberOfRows);

        var individualItemRowWidth = imgWidth * (itemsPerPage / numberOfRows);
        productRow.eq(0).append(items);

        productRow.filter(":gt(0)").remove();
        productRow = productRow.eq(0);


        var allItems = items;

        productRow.empty();

//Put the items into the rows.
        for (var rowNumber = 1; rowNumber <= numberOfRows; rowNumber++) {
            var k = -1 + rowNumber;
            div1 = $('<div style="float:left;" class="scrollerItemRow"></div>');
           // div1.css("width", individualItemRowWidth);
            div1.css("height", imgHeight);
            while (k < allItems.length) {
         
            if (allItems[k] != undefined) {
                div1.append(allItems[k]);
                    }
                 k = k + numberOfRows;
             }
        outsideDiv.append(div1);

    }
    productRow.append(outsideDiv);

    outsideDiv.css("height", outsideDivHeight);
        
/*
        for (var p = 0; p < allItems.length; p++) {
            //number is even
            if (p == numberOfRows) {
                if (p != 0) {
                    productRow.append(div1);
                }
                div1 = $('<div class="scrollerItemRow"></div>');
            }
            div1.append(allItems[p]);
        }


        productRow.append(div1);

*/



        productRow.css("width", scrollerWidth);
        productRow.css("height", outsideDivHeight);

        var leftBut = $('<a href="#previous" class="prevBut lEnd">previous</a>');
        var rightBut = $('<a href="#next" class="nextBut">next</a>');
        pageNumbering.prepend(leftBut).append(rightBut);

        var pointer = 0;
        leftBut.add(rightBut).click(function(evt) {

            if (this.className.match(/.End/)) return false;

            var direction = (!this.className.match(/prevBut/) * 2) - 1;

            scroll(direction);
            return false;
        });


        function scroll(direction) {

            var move = direction * itemsPerPage;
            
            pointer = pointer + move;
            var tempImagNum = imgNum;
            if (imgNum % numberOfRows > 0) {
                tempImagNum = tempImagNum + (imgNum % numberOfRows);
            }

            if (pointer + move > tempImagNum) pointer = tempImagNum - itemsPerPage;
           
           
            if (pointer < 0) pointer = 0;

            var low = pointer + 1;
            var high = pointer + itemsPerPage;

            if (pointer == 0) {
                leftBut.addClass("lEnd");
                rightBut.removeClass("rEnd");
            }
            else if (high == imgNum) {
                rightBut.addClass("rEnd");
                leftBut.removeClass("lEnd");
            }
            else {
                leftBut.removeClass("lEnd");
                rightBut.removeClass("rEnd");
            }


            //We change the pointers for these tall kinds because it is actually the pointer cut in half
            var tempPointer = pointer;
            if (imgNum % numberOfRows && direction == 1) {

                tempPointer = (tempPointer + ((tempImagNum) % numberOfRows)) / numberOfRows;
                
            }

            else {
                tempPointer = tempPointer / numberOfRows;
            }

            productRow.animate({ marginLeft: -(imgWidth * (tempPointer)) }, 500);
            $(".low", scrollContainer).text(low);
            $(".high", scrollContainer).text(high);
        }
    }
}

function scottishNameCheck(current) {

    var indexOfMC = current.value.toUpperCase().indexOf('MC');
    if (indexOfMC > -1) {
        current.value = current.value.substring(0, indexOfMC + 1).toUpperCase() + current.value.substring(indexOfMC + 1, indexOfMC + 2) + current.value.substring(indexOfMC + 2).toUpperCase();
    }
   else {
        current.value = current.value.toUpperCase();
    }
}


function updatePrice(current) {

    scottishNameCheck(current);
    
    
if($("input[name$='CustomShirtName']").val().trim() != '' ||  $("input[name$='CustomProductNumber']").val().trim() != '')
{
    $('.printingPriceLabel')[0].innerHTML = $("input[name$='printingPriceHidden']").val();
    $('.fullPriceLabel')[0].innerHTML = $("input[name$='totalPriceHidden']").val();
 }
 else
 {

    $('.printingPriceLabel')[0].innerHTML = $("input[name$='printingPriceHiddenLower']").val();
             $('.fullPriceLabel')[0].innerHTML = $("input[name$='totalPriceHiddenLower']").val();

 }
      
    }

function setupGallery() {
    if (this.setup) return true;
    this.setup = true;
    var featureContainer = $(".mainImage", this);
    var featureImg = $(".doubleSize", featureContainer);
    var featureImgSmall = $(".feature", featureContainer);
    featureImgSmall.addClass("activeFeature");
    
    var thumbs = $(".item", this);
    thumbs.click(function() {
        var displaySrc = $(this).attr("displaySrc");
        if (displaySrc) {
            // don't need to change the alt at the moment as all the gallery images have the same alt. Nice one nop!
            featureImg.attr("src", $(this).attr("displaySrc")).attr("largeSrc", this.href); //.attr("alt" , this.alt).next().attr("alt", this.alt);
            $(".zoomcontainer", featureContainer).remove();
            featureContainer.unbind("click").one("click", imageZoom);
            thumbs.removeClass("selected");
            $(this).addClass("selected");
            return false;
        }
    }).eq(0).click();

    if (!thumbs.length) {
        featureContainer.one("click", imageZoom);
    }

    var clickForMore = $("<div class='clickForMore'><span class='moreImages'><img src='/App_Themes/Equator/images/cssimages/zoomMagnify.gif' class='magnifyingGlass' /> More images of this product</span></div>")
        .click(lightBoxEvent)
        .appendTo(this);



    $('.galleryThumbs').hide();

    $(this).addClass('galleryTemp');
}

function setupLightBox(parent) {
    var close = $('<a href="#" title="Close window" class="topClose">x close</a>');
    close.click(lightBoxClose);
    close.hide();
    parent.append(close);

    var featureContainer = $(".mainImage", parent);

    var featureImg = $(".feature", featureContainer);

    featureImg.removeClass('activeFeature');
    var dblSizefeatureImg = $(".doubleSize", featureContainer);
    dblSizefeatureImg.addClass('activeFeature');
    
    var overlay = $(".overlay", featureContainer);
    overlay.addClass("largeOverlay");

    var thumbs = $(".item", parent);
    thumbs.click(function() {
        var displaySrc = $(this).attr("displaySrc");
        if (displaySrc) {
            // don't need to change the alt at the moment as all the gallery images have the same alt. Nice one nop!
            featureImg.attr("src", $(this).attr("displaySrc")).attr("largeSrc", this.href); //.attr("alt" , this.alt).next().attr("alt", this.alt);
            $(".zoomcontainer", featureContainer).remove();
            featureContainer.unbind("click").one("click", imageZoom);
            thumbs.removeClass("selected");
            $(this).addClass("selected");
            return false;
        }
    }).eq(0).click();

    if (!thumbs.length) {
        featureContainer.one("click", imageZoom);
    }

    var zoomText = $('<p class="zoomText">Click image to zoom;</p>');
    zoomText.hide();
    featureContainer.after(zoomText);

    if ($('.popup').length == 0) {
        var ajaxPopup = $('<div class="popup"></div>').css("visibility", "hidden");
        ajaxPopup.css("opacity", "0.4");
        ajaxPopup.height($(".outsideWrapper")[0].scrollHeight);
        $("body").append(ajaxPopup);
    }
    
    if (ie6Below) {
        var iframe = $('<iframe class="popFrame" style="z-index:499;position:absolute;top:0;left:0;width:100%;height:' + $(".outsideWrapper")[0].scrollHeight + 'px" frameborder="0" src="javascript:false;"></iframe>').css("opacity", 0);
        $("body").append(iframe);
    }
}


function lightBoxEvent(evt) {
    var parent = $(this).parent().clone();

    setupLightBox(parent);
       

    $(".popup").hide().css("visibility", "visible");
    $(".popup").fadeIn();

    $(".popFrame").fadeIn();
    parent.find('.clickForMore').fadeOut();
    parent.find('.zoomText,.galleryThumbs,.topClose').fadeIn();

    parent.removeClass('galleryTemp');
    parent.addClass('lightboxContainer');


    var topVar = $(this).parent().offset().top;
    //var leftVar = $(this).parent().offset().left;
    parent.css({ top: topVar });
    var prodDetails = $('<div class="productDetails lightboxHolder" />');
    prodDetails.append(parent);

    $("body").append(prodDetails);
    return false;
}

function lightBoxClose(evt) {
    var parent = $(this).parent().parent();

    parent.remove();
    $(".popFrame").fadeOut();
    $(".popup").fadeOut();

    parent.remove();

    return false;
}

function imageZoom(evt) {
    var mainImage = $(this);
    var featureImg = $(".activeFeature", mainImage);
    var bigImg = new Image();
    bigImg.onload = loaded;
    bigImg.error = noload;

    bigImg.src = $(".feature", mainImage).attr('largeSrc');
    var zooming = false;


    function loaded() {

        var zoomContainer = $('<div class="zoomcontainer"/>');

        var origWidth = featureImg.width();
        var origHeight = featureImg.height();
        var zoomContainerWidth = mainImage.width();
        var zoomContainerHeight = mainImage.height();
        zoomContainer
            .width(zoomContainerWidth)
            .height(zoomContainerHeight)

        $(bigImg).css({ top: featureImg[0].offsetTop, left: featureImg[0].offsetLeft });
        //            .css({ top: 0, left: 350 });

        var miniZoom = $('<div class="miniImg"><img src="' + featureImg.attr("src") + '"/><span></span></div>');
        var zoom = $('<div id="zoom" class="zoom">');
        var fakeLayer = $('<div class="fakeLayer"></div>');
        zoomContainer.append(miniZoom, zoom, fakeLayer);



        // outsideContainer.append(zoomContainer);
        mainImage.append(zoomContainer);



        var ZOOMRATIO = 2 / 3;
        var MINIZOOMRATIO = 0.25;

        var miniZoomWindow = miniZoom.find("span");

        zoom.append(bigImg);

        if (bigImg.width < origWidth * 2) {
            bigImg.width = bigImg.width * 2;
            bigImg.height = bigImg.height * 2;
        }

        var bigWidth = bigImg.width; ;
        var bigHeight = bigImg.height; ;
        //        var zoomWidthOffset = zoomWidth / 2;

        var miniWidth = origWidth * MINIZOOMRATIO;
        var miniHeight = origHeight * MINIZOOMRATIO;
        $("img", miniZoom).width(miniWidth);

        //        var zoomWidth = origWidth * ZOOMRATIO;
        //        zoom.width(zoomWidth).height(zoomWidth);


        var offset = zoomContainer.offset();
        var ratio = { x: (bigWidth - zoomContainerWidth) / origWidth, y: (bigHeight - zoomContainerHeight) / origHeight };
        var miniZoomWidth = Math.ceil(miniWidth * zoomContainerWidth / bigWidth);
        var miniZoomHeight = Math.ceil(miniHeight * zoomContainerHeight / bigHeight);
        var miniRatio = { x: (miniWidth - miniZoomWidth) / origWidth, y: (miniHeight - miniZoomHeight) / origHeight };

        miniZoomWindow.width(miniZoomWidth).height(miniZoomHeight);

        var moveMapRatio = { x: origWidth / zoomContainerWidth, y: origHeight / zoomContainerHeight };

        zoomContainer.click(zoomState);

        function zoomState(evt) {
            var type = evt.type;
            var origTop = featureImg[0].offsetTop;
            var origLeft = featureImg[0].offsetLeft;
            if (type == "click") {
                zooming = !zooming;
                if (zooming) {
                  
                
                    $(bigImg).css({ top: origTop, left: origLeft, width: origWidth, height: origHeight });
                    zoom.show();

                    $(bigImg).animate({ width: bigWidth, height: bigHeight, left: (-(evt.pageX - offset.left) * moveMapRatio.x * ratio.x), top: (-(evt.pageY - offset.top) * moveMapRatio.y * ratio.y) }, 500, function() {
                        moveZoom(evt);
                        fakeLayer
                            .add(miniZoom)
                            .show()
                            .mousemove(moveZoom)
                            .mouseout(zoomState);
                    });



                }
                else {
                    type = "mouseout";
                }
            }

            if (type == "mouseout") {
                zooming = false;
                fakeLayer.unbind().add(miniZoom).fadeOut();
                $(bigImg).animate({ width: origWidth, height: origHeight, left: origLeft, top: origTop }, 500, function() {
                    zoom.hide();
                });



            }
        }

        function moveZoom(evt) {
            var x = evt.pageX - offset.left;
            var y = evt.pageY - offset.top;
            //console.info(x + " " + y);
            //            zoom.css({ left: x * moveMapRatio.x - zoomWidthOffset, top: y * moveMapRatio.y - zoomWidthOffset });
            //            $(bigImg).css({ left: (-x * moveMapRatio.x * ratio + zoomWidthOffset), top: (-y * moveMapRatio.y * ratio + zoomWidthOffset) });
            $(bigImg).css({ left: (-x * moveMapRatio.x * ratio.x), top: (-y * moveMapRatio.y * ratio.y) });
            //            miniZoomWindow.css({ left: miniRatio * x * moveMapRatio.x - miniZoomWidth / 2, top: miniRatio * y * moveMapRatio.y - miniZoomWidth / 2 });
            miniZoomWindow.css({ left: miniRatio.x * x * moveMapRatio.x, top: miniRatio.y * y * moveMapRatio.y });
        }
        zoomState(evt);

    }

    function noload() {

    }
}

//Jscript to generate window height
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

