﻿var oshop_iLastWindowHeight = 0;

function oshop_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;
    }

    var arRet = new Array();
    arRet.push(myWidth);
    arRet.push(myHeight);
    return arRet;
}

function oshop_resizer() {
    var arWndSize = oshop_getWindowSize();
    var iWndHeight = arWndSize[1];
    if (iWndHeight != oshop_iLastWindowHeight) {
        jQuery('#oshop_mainbox_container').css('height', 'auto');
        jQuery('#oshop_mainbox').css('height', 'auto');

        var iHeaderHeight = jQuery('#oshop_header').attr('offsetHeight');
        var iMiddleHeight = jQuery('#oshop_mainbox').attr('offsetHeight');
        var iFooterHeight = jQuery('#oshop_footer').attr('offsetHeight');

        var iTotalHeight = iHeaderHeight + iMiddleHeight + iFooterHeight;

        if (iTotalHeight < iWndHeight) {
            jQuery('#oshop_mainbox').css('height', (iMiddleHeight + (iWndHeight - iTotalHeight)) + 'px');
            jQuery('#oshop_mainbox_container').css('height', (iMiddleHeight + (iWndHeight - iTotalHeight)) + 'px');
        }

        oshop_iLastWindowHeight = iWndHeight;
    }

    setTimeout('oshop_resizer();', 50);
}

jQuery(document).ready(function() {
    oshop_resizer();
});

var oshop_arOfferProductGUIDS = new Array();
var oshop_arOfferCurProductIndex = 0;

function oshop_OfferNext_FadedOut() {
    var strProductGUID = oshop_arOfferProductGUIDS[oshop_arOfferCurProductIndex];
    if (++oshop_arOfferCurProductIndex >= oshop_arOfferProductGUIDS.length) {
        oshop_arOfferCurProductIndex = 0;
    }

    jQuery.ajax({
        cache: false,
        dataType: 'xml',
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            oshop_OfferNext();
        },
        success: function(data, textStatus) {
            jQuery(data).children('*').each(function() {
                jQuery(this).children('product').each(function() {
                    var strName = jQuery(this).children('Name').text();
                    var strShortDescription = jQuery(this).children('ShortDescription').text();
                    var strImageURL = jQuery(this).children('ImageURL').text();
                    var strProductLink = jQuery(this).children('ProductLink').text();
                    var strOldPrice = jQuery(this).children('OldPrice').text();
                    var strNewPrice = jQuery(this).children('NewPrice').text();

                    jQuery('#' + oshop_offer_hlOfferTitle).attr('href', strProductLink).text(strName);
                    if (strImageURL.length > 0) {
                        jQuery('#' + oshop_offer_hlOfferImage).css('display', 'block').attr('href', strProductLink);
                        jQuery('#' + oshop_offer_imgOffer).attr('src', strImageURL);
                    }
                    else {
                        jQuery('#' + oshop_offer_hlOfferImage).css('display', 'none');
                    }

                    if (strShortDescription.indexOf('<br />') > -1) {
                        jQuery('#' + oshop_offer_lblOfferDescription).html(strShortDescription);
                    }
                    else {
                        jQuery('#' + oshop_offer_lblOfferDescription).text(strShortDescription);
                    }
                    jQuery('#' + oshop_offer_lblOfferOldPrice).text(strOldPrice);
                    jQuery('#' + oshop_offer_lblOfferPrice).text(strNewPrice);

                    jQuery('#' + oshop_offer_panelOffer).fadeTo(500, 1.00, oshop_OfferNext_FadedIn);
                });
            });
        },
        timeout: 60000,
        url: oshop_webBasePath + 'OShop/AJAX/GetPromotionProduct.aspx?ProductGUID=' + strProductGUID
    });
}

function oshop_OfferNext_FadedIn() {
    if (jQuery.browser.msie) {
        this.style.removeAttribute('filter');
    }

    window.setTimeout('oshop_OfferNext();', oshop_offer_nextInterval);
}

function oshop_OfferNext() {
    jQuery('#' + oshop_offer_panelOffer).fadeTo(500, 0.01, oshop_OfferNext_FadedOut);
}

var arOnPageLoadActions = new Array();

if (typeof (CKEDITOR) != 'undefined' && CKEDITOR != null) {
    CKEDITOR.editorConfig = function(config) {

        config.toolbar = [
            ['Maximize', '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo', '-', 'Find',
                'Replace', '-', 'SelectAll', '-', 'Image', 'Table', 'HorizontalRule', 'SpecialChar', '-', 'Source'],
                '/',
             ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-',
             'TextColor', 'BGColor', '-', 'NumberedList', 'BulletedList', '-', 'RemoveFormat', '-', 'Link', 'Unlink', 'Anchor'],
             '/',
             ['Format', 'Font', 'FontSize', ',', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv']
        ];
    };
}

function getAjaxObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        return new ActiveXObject('Microsoft.XMLHTTP');
    }
    else {
        return null;
    }
}

function printContent() {
    window.print();
}

function stringStartsWith(str, strStart) {
    if (str.substr(0, strStart.length) == strStart) {
        return true;
    }
    else {
        return false;
    }
}

function refreshShoppingCartCadgetUI(iArticleCount, strTotal, strCurrencySign) {
    return false;
}

function refreshShoppingCartCadgetV2() {
    if (typeof (refreshShoppingCartCadgetV2_impl) != 'undefined') {
        refreshShoppingCartCadgetV2_impl();
    }
}


function refreshShoppingCartCadgetV2_real(strArticleCountID, strTotalID, strWebBasePath) {
    var objRequest = getAjaxObject();
    objRequest.open('GET', strWebBasePath + 'OShop/AJAX/GetShoppingCart.aspx?MNO=' + Math.random(), true);
    objRequest.onreadystatechange = function() {
        if (objRequest.readyState == 4) {
            if (objRequest.status == 200) {
                var elemResponse = objRequest.responseXML.getElementsByTagName('response')[0];
                if (elemResponse.getAttribute('success') == '1') {
                    for (var i = 0; i < elemResponse.childNodes.length; i++) {
                        if (elemResponse.childNodes[i].nodeName == 'ShoppingCart') {
                            var elemShoppingCart = elemResponse.childNodes[i];
                            var strTotal = elemShoppingCart.getAttribute('Total');
                            var iArticleCount = elemShoppingCart.getAttribute('ArticleCount');
                            var strCurrencySign = elemShoppingCart.getAttribute('CurrencySign');

                            if (!refreshShoppingCartCadgetUI(iArticleCount, strTotal, strCurrencySign)) {
                                document.getElementById(strTotalID).innerHTML = '';
                                document.getElementById(strTotalID).appendChild(document.createTextNode(strCurrencySign + ' ' + strTotal));
                                document.getElementById(strArticleCountID).innerHTML = '';
                                document.getElementById(strArticleCountID).appendChild(document.createTextNode(iArticleCount));
                            }

                            break;
                        }
                    }
                }
            }
        }
    }

    objRequest.send(null);
}

jQuery.extend({
    getUrlVars: function() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[decodeURIComponent(hash[0])] = decodeURIComponent(hash[1]).replace(/\+/g, ' ');
        }
        return vars;
    },
    getUrlVar: function(name) {
        return jQuery.getUrlVars()[name];
    }
});

jQuery(document).ready(function() {
    if (self.location.href.toLowerCase().indexOf('/form.htm') > -1) {
        var vars = jQuery.getUrlVars();

        jQuery('input[type="text"],textarea').each(function() {
            var strName = jQuery(this).attr('name');
            if (strName.length > 7) {
                strName = strName.substr(7);
                var strVal = vars[strName];
                if (typeof (strVal != 'undefined') && strVal != null) {
                    jQuery(this).val(strVal);
                }
            }
        });
    }
});

(function($) {
    var displayDiff = null;

    var methods = {
        init: function(options) {
        },
        showImage: function(iIndex) {
            var theData = this.data('productListMouseOverListGallery_data');

            theData.imgThumbContainer.children('img').removeClass('active');

            theData.imgContainer.hide();
            theData.loadingContainer.show();


            var objPreloader = new Image();
            objPreloader.jq = this;
            objPreloader.imgthumb = theData.arImageThumbs[iIndex];
            objPreloader.onload = function() {
                var theData = this.jq.data('productListMouseOverListGallery_data');

                theData.imgBig.unbind('click').click(function() {
                    window.open(theData.arImageHrefs[iIndex], '_self')
                }).css('cursor', 'pointer');

                var iNewHeight = this.height + 88;
                var iDiff = iNewHeight - theData.currentHeight;
                if (iDiff == 0) {
                    theData.imgBig.attr('src', this.src);
                    theData.imgContainer.show();
                    theData.loadingContainer.hide();
                    objPreloader.imgthumb.addClass('active');
                }
                else {
                    var strSrc = this.src;

                    theData.currentHeight = iNewHeight;
                    objPreloader.jq.data('productListMouseOverListGallery_data', theData);

                    var iNewTop = theData.initialTop;
                    var iBrowserHeight = $(window).height();
                    var iBottomFixed = iNewTop + 9 + iNewHeight - $(window).scrollTop();
                    if (iBottomFixed > iBrowserHeight) {
                        iNewTop -= (iBottomFixed - iBrowserHeight);
                    }

                    var iNewBg2Top = (theData.initialTop - iNewTop) + 60;

                    theData.topBg2Container.animate({ top: iNewBg2Top }, 500);
                    theData.topBg1Container.animate({ top: iNewTop }, 500);
                    theData.displayContainer.animate({ height: iNewHeight, top: iNewTop + 9 }, 500, function() {
                        theData.imgBig.attr('src', strSrc);
                        theData.imgContainer.show();
                        theData.loadingContainer.hide();
                        objPreloader.imgthumb.addClass('active');
                    });
                }
            };
            objPreloader.src = theData.arImageSrcs[iIndex];
        },
        startshow: function(iLeft, iTop) {
            var objExclude = this;

            $('.productListMouseOver_productlist_product_imagegallery').each(function() {
                if ($(this) != objExclude) {
                    $(this).productListMouseOverListGallery('hide');
                }
            });

            var theData = this.data('productListMouseOverListGallery_data');
            if (theData != null && theData.timeoutHide != null) {
                clearTimeout(theData.timeoutHide);
            }

            this.productListMouseOverListGallery('show', iLeft, iTop);
        },
        starthide: function() {
            var theData = this.data('productListMouseOverListGallery_data');
            if (theData != null && theData.bIsVisible) {
                var jq = this;

                theData.timeoutHide = setTimeout(function() {
                    jq.productListMouseOverListGallery('hide');
                }, 500);
            }
        },
        hide: function() {
            var theData = this.data('productListMouseOverListGallery_data');
            if (theData != null && theData.displayContainer != null) {
                theData.displayContainer.hide();
                theData.topBg1Container.hide();

                if (theData.timeoutHide != null) {
                    clearTimeout(theData.timeoutHide);
                    theData.timeoutHide = null;
                }

                theData.bIsVisible = false;
                this.data('productListMouseOverListGallery_data', theData);
            }
        },
        show: function(iLeft, iTop) {
            var theData = this.data('productListMouseOverListGallery_data');
            if (theData == null) {
                theData = {
                    displayContainer: null,
                    topBg1Container: null,
                    imgContainer: null,
                    imgBig: null,
                    imgThumbContainer: null,
                    arImageSrcs: null,
                    arImageHrefs: null,
                    currentHeight: 351,
                    loadingContainer: null,
                    arImageThumbs: null,
                    bIsVisible: false,
                    timeoutHide: null,
                    initialLeft: 0,
                    initialTop: 0,
                    topBg2Container: null
                };
            }

            theData.initialLeft = iLeft;
            theData.initialTop = iTop;

            if (theData.displayContainer == null) {
                theData.displayContainer = $(document.createElement('div'));
                theData.displayContainer.hide();
                theData.displayContainer.addClass('productListMouseOver_productlist_product_imagegallery_container');
                $(document.body).append(theData.displayContainer);

                var jq = this;

                theData.displayContainer.mouseover(function() {
                    var theData = jq.data('productListMouseOverListGallery_data');
                    if (theData != null && theData.timeoutHide != null) {
                        clearTimeout(theData.timeoutHide);
                    }
                });

                theData.displayContainer.mouseout(function() {
                    jq.productListMouseOverListGallery('starthide');
                });

                theData.topBg2Container = $(document.createElement('div'));
                theData.topBg2Container.addClass('vlig_topbg');
                theData.displayContainer.append(theData.topBg2Container);

                theData.topBg1Container = $(document.createElement('div'));
                theData.topBg1Container.addClass('productListMouseOver_productlist_product_imagegallery_container_topbg1');
                $(document.body).append(theData.topBg1Container);

                theData.imgContainer = $(document.createElement('div'));
                theData.imgContainer.addClass('vlig_imgcontainer');
                theData.displayContainer.append(theData.imgContainer);

                theData.imgBig = $(document.createElement('img'));
                theData.imgContainer.append(theData.imgBig);

                theData.imgThumbContainer = $(document.createElement('div'));
                theData.imgThumbContainer.addClass('vlig_imgthumbcontainer');
                theData.displayContainer.append(theData.imgThumbContainer);

                theData.loadingContainer = $(document.createElement('div'));
                theData.loadingContainer.addClass('vlig_loading');
                theData.displayContainer.append(theData.loadingContainer);

                theData.loadingContainer.append(
                    $(document.createElement('img')).attr('src', oshop_webBasePath + 'OShop/images/productListImagePopup/loading.gif'));

                theData.arImageSrcs = new Array();
                theData.arImageThumbs = new Array();
                theData.arImageHrefs = new Array();

                this.children('a').each(function() {
                    var imgThumb = $(document.createElement('img'));
                    imgThumb.attr('title', $(this).attr('title'));
                    imgThumb.attr('alt', $(this).attr('title'));
                    imgThumb.attr('src', $(this).children('img').attr('src'));

                    theData.imgThumbContainer.append(imgThumb);
                    theData.arImageSrcs.push($(this).attr('href'));
                    theData.arImageHrefs.push($(this).attr('oshop_vpurl'));
                    theData.arImageThumbs.push(imgThumb);

                    imgThumb.data('vlimg_imgindex', theData.arImageSrcs.length - 1);

                    imgThumb.click(function() {
                        var theData = jq.data('productListMouseOverListGallery_data');
                        jq.productListMouseOverListGallery('showImage', $(this).data('vlimg_imgindex'));
                    });
                });

                this.data('productListMouseOverListGallery_data', theData);
            }

            if (theData.bIsVisible) {
                theData.displayContainer.hide();
                theData.topBg1Container.hide();
            }
            else {
                var iBrowserHeight = $(window).height();
                var iBottomFixed = iTop + 9 + theData.displayContainer.height() - $(window).scrollTop();
                if (iBottomFixed > iBrowserHeight)
                    iTop -= (iBottomFixed - iBrowserHeight);

                var iNewBg2Top = (theData.initialTop - iTop) + 60;

                theData.topBg2Container.css('top', iNewBg2Top);

                theData.topBg1Container.css('left', iLeft);
                theData.topBg1Container.css('top', iTop);
                theData.displayContainer.css('left', iLeft);
                theData.displayContainer.css('top', iTop + 9);
                theData.displayContainer.show();
                theData.topBg1Container.show();
                this.productListMouseOverListGallery('showImage', 0);
            }

            theData.bIsVisible = !theData.bIsVisible;
            this.data('productListMouseOverListGallery_data', theData);
        }
    }

    $.fn.productListMouseOverListGallery = function(method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        }
        else if (typeof (method) === 'object' || !method) {
            return methods.init.apply(this, arguments);
        }
    };
})(jQuery);

function getProductMouseOverImageGalleryCoords(objOver, event) {
    var offsets = jQuery(objOver).offset();

    return {
        x: offsets.left + 110,
        y: offsets.top - 53
    };
}

jQuery(document).ready(function() {
    jQuery('.productListMouseOver_productlist_product_imagegallery').productListMouseOverListGallery();
    jQuery('.productListMouseOver_productlist_product_imagegallery').prev().prev().each(function() {
        var v1 = jQuery(this);

        jQuery(this).prev().children('img').mouseover(function(e) {
            var coords = getProductMouseOverImageGalleryCoords(this, e);
            v1.next().next().productListMouseOverListGallery('startshow', coords.x, coords.y);
        }).mouseout(function() {
            v1.next().next().productListMouseOverListGallery('starthide');
        });
    });
});
