
var DropdownListItem = function (jqueryTitle, jquerySubtitles, timing) {
	this.jqueryTitle 		= jqueryTitle;
	this.jquerySubtitles 	= jquerySubtitles;
	this.name 				= this.jqueryTitle.attr('title');
	
	timing 					= (timing != null)?timing:1;
	this.timing 			= timing * 1000;
	
	this.openByDefault = false;
};

DropdownListItem.timer;

DropdownListItem.prototype.getName = function () {
	return this.name;
};

DropdownListItem.prototype.isOpenByDefault = function () {
	return this.openByDefault;
};

DropdownListItem.prototype.init = function () {
	var that = this;
	
	if (this.isOpenByDefault()) {
		this.jqueryTitle.live('mouseenter', function(){
			that.onRollOverHandler();
		});
		this.jqueryTitle.die('mouseleave');
	}
	else {
		this.jqueryTitle.live('mouseenter', function(){
			that.onRollOverHandler();
		});
		this.jqueryTitle.live('mouseleave', function(){
			that.onRollOutHandler();
		});
	}
};

DropdownListItem.prototype.onRollOverHandler = function () {
	this.showSubtitles();
	window.clearTimeout(DropdownListItem.timer);
	DropdownList.instance.currentItem = this;
	DropdownList.instance.hideOthersItem();
};

DropdownListItem.prototype.onRollOutHandler = function () {
	var that = this;
	DropdownListItem.timer = window.setTimeout(function(){
													DropdownList.instance.currentItem = null;
													that.hideSubtitles();
												}, this.timing);
};

DropdownListItem.prototype.showSubtitles = function () {
	this.jquerySubtitles.fadeIn('slow');
	
	var that = this;
	
	if (this.isOpenByDefault()) {
		this.jquerySubtitles.die('mouseenter');
		this.jquerySubtitles.die('mouseleave');
	}
	else {
		this.jquerySubtitles.live('mouseenter', function(){
			that.subtitlesOnRollOverHandler();
		});
		this.jquerySubtitles.live('mouseleave', function(){
			that.subtitlesOnRollOutHandler();
		});
	}
};

DropdownListItem.prototype.hideSubtitles = function () {
	this.jquerySubtitles.fadeOut('fast');
	DropdownList.instance.showOpenedByDefault();
};

DropdownListItem.prototype.subtitlesOnRollOverHandler = function () {
	window.clearTimeout(DropdownListItem.timer);
};

DropdownListItem.prototype.subtitlesOnRollOutHandler = function () {
	var that = this;
	DropdownListItem.timer = window.setTimeout(function(){
													DropdownList.instance.currentItem = null;
													that.hideSubtitles();
												}, this.timing);
};

DropdownListItem.prototype.open = function () {
	this.openByDefault = true;
	
	this.init();
	this.showSubtitles();
};
