
Object.extend(Number.prototype, {
    numberFormat : function(decimals) {
        var pow, nStr, x, x1, x2;
        var dot = '';
        var rgx = /(\d+)(\d{3})/;
       
        decimals = decimals || 0;
        pow = Math.pow(10, decimals);
        nStr = (parseFloat(Math.round(this*pow)) / pow).toString();
        
        if(decimals > 0) {
            dot = '.';
        }
        
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? x[1] : '';
        
        while(x2.length < decimals) {
            x2 += '0';
        }
        x2 = dot + x2;

        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;

    }
});

var lang = {
    current : 'en',
    get: function(what) {
        what = what || 'en';
        var str = this[this.current] ? this[this.current][what] : '['+what+']';
        if(typeof arguments[1] != 'undefined') {
            str = str.replace(/%s/gi, arguments[1]);
        }
        return str;
    },

    en : {

        add_to_cart:        "Add to your cart",
        remove_from_cart:   "Remove from your cart",
        update_cart:        "Update cart",

        added_to_cart:      "Added to your cart",
        removed_from_cart:  "Removed from your cart",
        updated_cart:       "Updated cart",

        adding_to_cart:      "Adding to your cart",
        removing_from_cart:  "Removing from your cart",
        updating_cart:       "Updating cart",

        update_quantity:     "Update Quantity",

        mand_fields:        "Mandatory fields are marked with a *",

        please_wait:        "Please wait...",

        no_items_in_cart:   "There are no items in your cart",
        minimum_quantity:   "Minimum Quantity",
        quantity_too_low:   "Sorry, this product has a minimum quantity of %s",
		quantity_error:     "Quantity Error",
		invalid_quantity:   "You have entered an invalid quantity, please check your entry",

        maximum_quantity:   "Stock Exceed",
        quantity_too_high:  "We currently only have %s of this item stock. Please reduce the quantity to %s or less",
		
		information:		"Information",	
		message:			"Message"		
    
    },
    fr : {
        add_to_cart:        "Ajoutez � votre demande",
        remove_from_cart:   "Retirez votre demande",

        added_to_cart:      "Ajout� � votre demande",
        removed_from_cart:  "Retir� de votre demande",

        adding_to_cart:     "S'ajouter � votre demande",
        removing_from_cart: "�limination de votre demande",

        mand_fields:        "Les champs marqu�s * sont obligatoires",

        please_wait:        "Attendez svp...",

        no_items_in_cart:   "Il n'y a aucun article dans votre demande",
        minimum_quantity:   "Quantit� minimale",
        quantity_too_low:   "D�sol�, pour cet article, il faut une quantit� minimale de"
    }

}


/*
	<head>
		<script src="Scripts/scriptaculous/lib/prototype.js"></script>
		<script src="Scripts/scriptaculous/src/scriptaculous.js?load=effect,builder"></script>
	</head>
*/
//- <a href="#" onclick="Lightbox.lightBox('images/theimage.png', 400, 500); return false">Link</a>

var Lightbox = {

    //- -----------------------------------------------------------------------------------
    //- General Conf... may bust this out into a separtate 'conf' object at some point...
    
    fadeSpeed : 0.5,    //- Duration of the fade on the open/close of the lightbox and info pop ups

    iconSpinner:'images/ajax-loader.gif',
    iconClose:  'images/close.png',



    //- --------------- LightBox image display methods and properties ---------------------
    
    working : false,
    fireNext : '',
    layerId : 'productdetail',
    
    lightBoxId : 'productLightBox',
    lightBox : function(id, w, h) {
        var el = $(this.lightBoxId);
        
        this.dimmerShow();
        
        if(!el) { //- init on first use
            el     = new Element('DIV', {id:this.lightBoxId, style:'display:none'});
            xbut   = new Element('IMG', {id:this.lightBoxId+'Close', src:this.iconClose, title:'Close'});
            theimg = new Element('IMG', {id:this.lightBoxId+'Img'});
            loader = new Element('IMG', {id:this.lightBoxId+'Loader', src:this.iconSpinner});
            loader.show();

            //black  = new Element('DIV', {id:this.lightBoxId+'Dimmer',style:'width:'+($(document.body).getWidth())+'px;height:'+($(document.body).getHeight())+'px;'});
            //black.setOpacity(0.6);
			el.observe('click', function() {
                Event.stopObserving(document, 'scroll');

                new Effect.Fade(this.lightBoxId,{
                    duration:this.fadeSpeed,
                    afterFinish : function() {
                        $(this.lightBoxId+'Img').src = 'shop/img/transpx.gif';
                        this.dimmerHide();
                    }.bind(this)
                });
            }.bindAsEventListener(this));
            
            el.appendChild(theimg);
            el.appendChild(xbut);
            el.appendChild(loader);

            //document.body.appendChild(black);
            document.body.appendChild(el);
        }
        else {
            theimg = $(this.lightBoxId+'Img');
            loader = $(this.lightBoxId+'Loader');
            loader.show();
            //$(this.lightBoxId+'Dimmer').show();
        }

        this.setLightBoxPosition(el, w, h);
            
        Event.observe(document, 'scroll', function() {
            this.setLightBoxPosition(el, w, h);
        }.bindAsEventListener(this));
        
        theimg.observe('load', function() {
            $(this.lightBoxId+'Loader').hide();
        }.bindAsEventListener(this));
		
	
        theimg.src = id;
        theimg.setStyle({width:w+'px', height:h+'px'});
		//alert();
        new Effect.Appear(el, {duration:this.fadeSpeed});

    },

    setLightBoxPosition : function(el, w, h) {
        viewport_width  = document.viewport.getWidth();
        viewport_height = document.viewport.getHeight();
        vpscroll_top    = document.viewport.getScrollOffsets()['top'];
        new_top = ((viewport_height - h) / 2) + vpscroll_top;
        el.setStyle({marginLeft:'-'+Math.round(w/2)+'px', left:'50%', top:new_top+'px'});
    },

    dimmerShow : function() {

        if(!$(this.lightBoxId+'Dimmer')) {
        
            var black  = new Element('DIV', {id:this.lightBoxId+'Dimmer',style:'width:'+($(document.body).getWidth())+'px;height:'+($(document.body).getHeight())+'px;display:none'});
            black.setOpacity(0.6);
            document.body.appendChild(black);

        }
        else {
            var black = $(this.lightBoxId+'Dimmer');
        }

        black.show();

    },

    dimmerHide : function() {
        var black = $(this.lightBoxId+'Dimmer');
        if(black) {
            black.hide()
        }
    }
}
