var Preloader = {
  callbacks: [],
  images: [],
  loadedImages: [],
  imagesLoaded: 0,

  add: function(image){
    if (typeof image == 'string') this.images.push(image);
    if (typeof image == 'array' || typeof image == 'object'){
      for (var i=0; i< image.length; i++){
        this.images.push(image[i]);
      }
    }
  },
  onFinish: function(func){
    if (typeof func == 'function') this.callbacks.push(func);
    if (typeof func == 'array' || typeof func == 'object'){
      for (var i=0; i< func.length; i++){
        this.callbacks.push(func[i]);
      }
    }
  },
  load: function(){
    for(var i=0; i<this.images.length; i++){
      this.loadedImages[i] = new Image();
      this.loadedImages[i].onload = function(){ Preloader.checkFinished.apply(Preloader) }
      this.loadedImages[i].src = this.images[i];
    }
  },

  checkFinished: function(){
    this.imagesLoaded++;
    if (this.imagesLoaded == this.images.length) this.fireFinish();
  },
  fireFinish: function(){
    for (var i=0; i<this.callbacks.length; i++){
      this.callbacks[i]();
    }
    this.images = [];
    this.loadedImages = [];
    this.imagesLoaded = 0;
    this.callbacks = [];
  }
}

var preloadImages = new Array(
	'http://photoframed.com/skin/frontend/default/default/images/white.png',
	'http://photoframed.com/skin/frontend/default/default/images/logo.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/design-by-myself1.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/design-by-myself-down.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/design-with-template1.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/design-with-template-down.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/middle_container_bg.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/process/process1.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/process/process2.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/process/process3.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/process/process4.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/process/process5.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/gift.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/example1.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/example2.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/example3.png',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/back/little_pic_middle_left.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/back/little_pic_middle_middle.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/back/little_pic_middle_right.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/header_bg.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/header_top_bg.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/header_nav.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/foot/dt1.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/foot/td2.jpg',
	'http://photoframed.com/skin/frontend/default/default/images/photoframe/foot/td3.jpg'
);
if (window.location.href == 'http://photoframed.com/') {
	Preloader.add(preloadImages);
	//Preloader.onFinish(nothing);
	Preloader.load();
}
