var featuredMod = false;
var brands = false;
var preloader = false;
var carousel = false;

var BrandAds = Class.create({
	initialize: function(brands,skinurl){
		this.brands = brands;
		this.currentBrand = 1;
		this.nextBrand = 2;
		this.paused = false;
		this.skinUrl = skinurl;
		this.brandIntervals;
		
		$('nav-right').observe('click', function(e){
			Event.stop(e);			
			this.pause();
			this.loadNextBrand(false);
		}.bind(this));
		$('nav-mid').observe('click', function(e){
			Event.stop(e);
			this.pausePlay();
		}.bind(this));
		$('nav-left').observe('click', function(e){
			Event.stop(e);
			this.pause();
			this.loadNextBrand(true);
		}.bind(this));
	},
	loadNextBrand: function(reverse){		
		if(reverse){
			this.nextBrand = (this.currentBrand == 1)?3:this.currentBrand - 1;
			this.brandLoader();
			switch(this.currentBrand){
				case 1: this.currentBrand = 3; break;
				case 2: this.currentBrand--; break;
				case 3: this.currentBrand--; break;
			}
		} else {		
			this.nextBrand = (this.currentBrand < 3)?this.currentBrand + 1:1;		
			this.brandLoader();
			switch(this.currentBrand){
				case 1: this.currentBrand++; break;
				case 2: this.currentBrand++; break;
				case 3: this.currentBrand = 1; break;
			}
		};
	},
	brandLoader: function(){
/* 		$('gpdb-prod-mask').addClassName('home-loading'); */
		$('shop-this-product').setAttribute('href',this.brands[this.currentBrand-1]);
		$('gpdb-prod-display-box').writeAttribute('class','home-ad-'+this.nextBrand);
/* 		setTimeout("$('gpdb-prod-display-box').writeAttribute('class','home-ad-'+brands.nextBrand)", 2000); */
/* 		setTimeout("$('gpdb-prod-mask').removeClassName('home-loading')",2000); */
	},
	pausePlay: function(){		
		if(this.paused){			
			this.play();
		} else {
			this.pause();
		}	
	},
	pause: function(){
		$('nav-mid').addClassName('play');
		clearInterval(this.brandIntervals);
		this.paused = true;
	},
	play: function(){
		$('nav-mid').removeClassName('play');
		this.loadNextBrand();
		this.brandIntervals = setInterval("brands.loadNextBrand()",4500);
		this.paused = false;
	},
	preload: function(){
		preloader.add(skinPath + 'images/home/home-ad-2.png');
		preloader.add(skinPath + 'images/home/home-ad-3.png');
		preloader.onFinish(this.brandIntervals = setInterval("brands.loadNextBrand()",4500));
		preloader.load();		
	}
});

Event.observe(window,'load',function() {
	// brands ads
	if (!brands){
		brands = new BrandAds(['/by-brand/i-to-l/innate-response.html','/by-brand/a-to-d/amber-lyn-chocolates.html','/by-brand/u-to-z/zico.html'],skinPath);
	}	
	
	if(!preloader){
		preloader = new Preloader;
		brands.preload();
	}
	
	if (!carousel) {
        carousel = new Carousel('new-product-carousel', 305, 2);
    }
});
