﻿
hs.showCredits = 0;
hs.graphicsDir = '/highslide/graphics/';
hs.allowSizeReduction = false;
hs.preserveContent = false;
hs.align = 'center';
hs.dimmingDuration = 0;
hs.objectLoadTime = 'before';
hs.dragByHeading = false;
hs.padToMinWidth = true;




$(document).ready(function() {
    app.init();
    $(document).pngFix();
    shop.init(language);
});

var shop = {

    module: 'shop',
    articles: 0,
    language: 'fr',
    isEffectMoving: false,

    init: function(lang) {
        shop.language = lang;
        $('.price').click(function() {


            if (!shop.isEffectMoving) {
                shop.isEffectMoving = true;
                var productNo = +($(this).attr('id').substring(1));
                var this_ID = $(this).attr('id');

                /* Animate */
                var productX = $('#' + this_ID).offset().left;
                var productY = $('#' + this_ID).offset().top;
                var basketX = $("#myCart").offset().left;
                var basketY = +($("#myCart").offset().top);

                var gotoX = basketX - productX;
                var gotoY = basketY - productY;

                var newImageWidth = $('#' + this_ID).width() / 3;
                var newImageHeight = $('#' + this_ID).height() / 3;

                $('#' + this_ID).clone().prependTo('#pp' + productNo).css('z-index', 2000)
	            .css({ 'position': 'absolute' })
	            .animate({ opacity: 0.8 }, 100)
	            .animate({ opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight }, 1200, function() {
	                $(this).remove();
	                shop.isEffectMoving = false;
	                shop.addToCart(productNo, productNo);
	            });
            }
        });
        $(".price").tooltip({ track: true, delay: 0, showURL: false, fixPNG: true, showBody: " - ", extraClass: "pretty", top: 5, left: -105 });
        $('.price').dblclick(function() { shop.hideCartWidget(); });
        if ($("#cartTitle").attr('className') == 'on') {
            $("#myCart").click(function() {
                var that = this;
                shop.showCartWindow(that)
            });
        };
        $("#myCart").tooltip({ track: true, delay: 0, showURL: false, fixPNG: true, showBody: " - ", extraClass: "pretty bottom", top: 5, left: -105 });

        
        
    },

    addToCart: function(productNo, productId) {
        if (shop.articles == 0) { }
        $("#myCart").hide();
        shop.addItemToCart(productNo, productId, 1);
    },

    addItemToCart: function(productNo, productId, productQty) {
        if (productNo > 0 && productQty > 0) {
            var strUrl = '/common/shop/cart.asp?hl=' + shop.language + '&pno=' + productNo + '&qty=' + productQty;
            $.getJSON(strUrl,
            function(data) {
                if (data.counter > 0) {
                    shop.articles = data.counter;
                    shop.showCartWidget();

                } else {
                    shop.articles = 0;
                    shop.hideCartWidget();
                }
            });
        }
    },

    /*
    
    trans.
    "oGoEmpty":"",
    "oEmpty":"Votre commande est vide.",
    "oContains";"Votre commande contient",
    "oArticle":"article",
    "oArticles":"articles",
    "ttDetail":"Cliquez vous voir le détail de votre commande et pour nous l'envoyer."
    */



    showCartWidget: function() {
        var strContains = '';
        $('#cartImage').attr('src', '/images/icons/caddie_on_30.gif');
        if (shop.articles == 1) { strContains = trans.oContains + ' 1 ' + trans.oArticle } else { strContains = trans.oContains + ' ' + shop.articles + ' ' + trans.oArticles };
        $('#cartTitle').attr('className', 'on').html(strContains);

        $('#myCart').addClass('on').click(function() {
            var that = this;
            shop.showCartWindow(that)
        }).attr('title', strContains + ' - ' + trans.ttDetail).tooltip({ track: true, delay: 0, showURL: false, fixPNG: true, showBody: " - ", extraClass: "pretty bottom", top: 5, left: -105 });
        $("#myCart").fadeIn('slow');
    },



    hideCartWidget: function() {
        $('#cartImage').attr('src', '/images/icons/caddie_off_30.gif');
        $('#cartTitle').attr('className', 'off').html(trans.oEmpty);
        $('#myCart').removeClass('on').click(function() { }).attr('title', trans.oEmpty).tooltip({ track: true, delay: 0, showURL: false, fixPNG: true, showBody: " - ", extraClass: "pretty bottom", top: 5, left: -105 });
        $("#myCart").fadeIn('slow');
    },
    
    emptyCart: function () {
        if (confirm(trans.oGoEmpty)){
            var strUrl = '/common/shop/empty_cart.asp?hl=' + shop.language;
            $.getJSON(strUrl,
                function(data) {
                    if (data.status == 200) {
                        shop.hideCartWidget();
                        if (hs) {hs.close();}
                    } else {
                        alert('an error has occured');
                    }
                }
            );
        }
    
    },

    showCartWindow: function(that) {

        app.pageWidth = $(window).width();
        app.pageHeight = $(window).height();

        hs.htmlExpand(that, {
            src: '/' + language + '/shop/order.asp',
            outlineType: 'outer-glow',
            objectLoadTime: 'after',
            objectType: 'iframe',
            width: 950,
            height: 530,
            wrapperClassName: 'outer-glow no-footer',
            dimmingOpacity: 0.75,
            align: 'center',
            dragByHeading: false
        })
    },

    openContact: function(that) {

        app.pageWidth = $(window).width();
        app.pageHeight = $(window).height();

        hs.htmlExpand(that, {
            src: '/' + language + '/shop/order-contact.asp',
            outlineType: 'outer-glow',
            objectLoadTime: 'after',
            objectType: 'iframe',
            width: 950,
            height: 530,
            wrapperClassName: 'outer-glow no-footer',
            dimmingOpacity: 0.75,
            align: 'center',
            dragByHeading: false
        })
    }  
    
};




var app = {

    module: 'homepage',
    menuTopX: 0,
    menuTopY: 0,
    menuBtmX: 0,
    menuBtmY: 0,
    pageX: 0,
    pageY: 0,
    pageWidth: 0,
    pageHeight: 0,

    init: function() {
        if ($('#gallery').length) {
            $('#gallery a').lightBox({ fixedNavigation: true });
        };
        
        app.pageWidth = $(window).width();
        app.pageHeight = $(window).height();

        $(window).scroll(function() {
            var cTop = $(this).scrollTop();
            var cBot = $('#page').height() - ($('#leftMain').height() + cTop);
            if (cTop > 140 && cBot > 100) { $('#leftMain').css('top', (cTop - 141) + "px"); }
            else if (cTop < 141) { $('#leftMain').css('top', "0px"); };
        });

    }
};


