function animatedBox() {
	
	this.visible = false;
	this.timer = "";
	this.number = -1;
	
}
	
animatedBox.prototype.init = function(num) {
	this.number = num;
}

animatedBox.prototype.setTimer = function() {
	var self = this;
	if (this.visible) {
		this.timer = setTimeout(function () {self.closeTab();},400);
	}
	
}

animatedBox.prototype.cancelTimer = function() {
	if (this.timer) {
		clearTimeout(this.timer);
	}
}

animatedBox.prototype.closeTab = function() {
	$('#open_box_'+this.number).animate(
		{ 	       
			top:"45px"
		}, 
		1000,
		"linear"
	);
	this.visible = false;
}

animatedBox.prototype.openTab = function() {
	var self = this;
	self.cancelTimer();
	if (!this.visible) {
		$('#open_box_'+this.number).animate(
			{ 
				top:"5px"
			}, 
			1000,
			"linear"
		);
		this.visible = true;
	}	
}


box = new Array();

$(document).ready(function() {
	
	$('.dynamicBox').each(function(i){
	  box.push(new animatedBox());
	  box[i].init(i);
	  this.id = this.id + "_" + i;
	  $('.trigger', $('#'+this.id)).each(
	   		function(){
	  	 		this.id = "box_" + i;
	   		}
	   );
	});
	
	$('.box_top_animation_open').each(function(i){
	   this.id = this.id + "_box_" + i;
	});

	$('.trigger').mouseover(function(event) {
		var num = event.currentTarget.id.substr(4);
		box[num].openTab();

	});
	
	$('.trigger').mouseout(function(event) {
		var num = event.currentTarget.id.substr(4);
		box[num].setTimer();
	});
	
});

