/* @author : Thomas Rambaud, 2009 */
var Calyps = null;

var CalypsiaJs = function(){
	this.ban_msgs_timer = null;
	this.ban_msgs_count = null;
	this.ban_msg = 0;
	this.ban_msgs_duration = 2500;
	this.ban_msgs_path = '#Ban .Messages span';
	this.hp_timer = null;
	this.hp_count = null;	
	this.hp_duration = 4000;
	this.hp_item = 0;	
	this.hp_item_path = '#Carrousel .Item';
}

CalypsiaJs.prototype = {
	init : function(){
		this.ban_msgs_count = $(this.ban_msgs_path).length - 1;
		this.initBanMessagesTimeout();
		if(this.isHomePage())
			this.initHomePage();
	},	
	
	
	initBanMessage : function(){		
		var next = (this.ban_msg == this.ban_msgs_count) ? 0 : this.ban_msg+1;
		$(this.ban_msgs_path+':eq('+this.ban_msg+')').fadeOut('slow');
		$(this.ban_msgs_path+':eq('+next+')').fadeIn('slow');
		this.ban_msg = next;
		this.initBanMessagesTimeout();
	},
	
	initBanMessagesTimeout : function(){
		if(this.isDefined(this.ban_msgs_timer))
			clearTimeout(this.ban_msgs_timer);
		this.ban_msgs_timer = setTimeout('Calyps.initBanMessage()', this.ban_msgs_duration);
		
	},
	
	initHomePage : function(){
		this.hp_count = $(this.hp_item_path).length - 1;
		if(this.hp_count != 0)
			this.initHomePageTimeout();
	},
	
	initHomePageItem : function(){
		var next = (this.hp_item == this.hp_count) ? 0 : this.hp_item+1;
		$(this.hp_item_path+':eq('+this.hp_item+')').fadeOut('slow');
		$(this.hp_item_path+':eq('+next+')').fadeIn('slow');
		this.hp_item = next;
		this.initHomePageTimeout();
	},
	
	initHomePageTimeout : function(){
		if(this.isDefined(this.hp_timer))
			clearTimeout(this.hp_timer);		
		this.hp_timer = setTimeout('Calyps.initHomePageItem()', this.hp_duration);
	},
	
	isHomePage : function(){
		return $('.HomePage').length > 0;
	},
	
	isPizzasPage : function(){
		return $('.Pizzas').length > 0;
	},
	
	isDefined : function(obj){
		return obj != null && obj != 'undefined';
	}
};

$(document).ready(function(){
	Calyps = new CalypsiaJs();
	Calyps.init();				
});
