//scripter zirho zirho6@gmail.com
//2011 03 03

var orslider = new RewardSlider();

$(document).ready(function(){
	$('.reward').hover(function(){
		orslider.autoGoOff();
	},function(){
		orslider.autoGoOn();
	});

	orslider.autoGo();
});

function RewardSlider(){
	this.selected = 5;
	this.orsliderTimer;
	this.orsliderSwitch = 1;
	this.itemwidth = 141;
	this.speed = 200;
	this.delay = 3000;
}

RewardSlider.prototype.moveTo = function(newindex){
	if(this.selected == newindex) return;
	//move 
	$('.rewardProducts').animate({'left': '-'+(newindex - 1) * this.itemwidth}, this.speed);
	$('.rewardProductsButtonFrame img:nth-child(' + this.selected + ')').attr('src', img_dir + 'rewardbuttonwhite.png');
	$('.rewardProductsButtonFrame img:nth-child(' + newindex + ')').attr('src', img_dir + 'rewardbuttonblue.png');
	//done
	this.selected = newindex;
}

RewardSlider.prototype.autoGoOff = function(){
	clearTimeout(this.orsliderTimer);
	this.orsliderSwitch = 0;
}

RewardSlider.prototype.autoGoOn = function(){
	this.orsliderSwitch = 1;
	this.orsliderTimer = setTimeout("orslider.autoGo()", this.delay);
}

RewardSlider.prototype.autoGo = function(){
	

	if(this.selected == 5) this.moveTo(1);
	else this.moveTo(this.selected + 1);
	
	if(this.orsliderSwitch == 1)
		this.orsliderTimer = setTimeout("orslider.autoGo()", this.delay);
}


