var ProgressBar = function(aImagesToLoad){
	this.images = [];
	this.aImagesToLoad = aImagesToLoad;
	this.barwidth = 137;
	this.blocksize = this.barwidth/(this.aImagesToLoad.length);
	this.loadonce = false;
	this.loaded = 0;
	this.hidethebar = false;
	this.init();
}
var p = ProgressBar;
p.prototype.action = function(){
		this.hidebar();
		}
p.prototype.loadimages = function(){
	var _self = this;
    $(".progressp").show();
    $(".progressp > span > em").css("left", "2px")

    for(n=0; n<this.aImagesToLoad.length; n++){
        this.images[n] = new Image();
        this.images[n].src = this.aImagesToLoad[n];
        if(this.images[n].complete){
        	this.dispbars();
        }
        this.images[n].onload = function(){_self.dispbars();}
        this.images[n].onerror = function(){_self.dispbars();}
        
    }
}
p.prototype.dispbars = function(){
    var _self = this;
    this.loaded++;
    $(".progressp > span").animate({width: this.blocksize*this.loaded}, 100);
    if(this.loaded >= this.aImagesToLoad.length && !this.hidethebar){
    	setTimeout(function(){_self.action();},3000);
    }
}
p.prototype.hidebar = function() {
    $(".roll_zoom, .roll_zoom_text, .product_flash").css("display", "block");
    $(".progressp").hide();
    //myHarrods.makeZoom();
    var theImage = $(".main_prod_img > img");
    MojoMagnify.init(theImage);

}
p.prototype.get_cookie = function(Name) {
    var search = Name+"=";
    var returnvalue = "";
    if(document.cookie.length>0){
        offset = document.cookie.indexOf(search);
        if(offset!=-1){
            offset += search.length;
            end = document.cookie.indexOf(";",offset);
            if(end == -1){
            	end = document.cookie.length;
            }
            returnvalue = unescape(document.cookie.substring(offset,end));
        }
    }
    return returnvalue;
}
p.prototype.init = function(){
    var _self = this;
    var okPB = false;
    if (this.loadonce){
        if(this.get_cookie("progB")== ""){
            okPB = true;
            document.cookie = "progB=yes";
        }
    }else {
    	okPB=true;
    }
    if(okPB){
    	setTimeout(function(){_self.loadimages();},3000);
    }
}
