
var LP_Serie = function (jSerie) {
	
	if (jSerie.find('td.LP_serie_title').length != 0) {
		this.title		= jSerie.find('td.LP_serie_title').html();
	} else {
	
		this.title 		= false;
		this.name 		= jSerie.find('td.LP_serie_name').html();
		this.rollover 	= jSerie.find('td.LP_serie_rollover').html();
		this.link 		= jSerie.find('td.LP_serie_link').html();
		
		this.machines = new Array();
		
		var that = this;
		jSerie.find('table.LP_machine tr.LP_machine').each(function(i){
			that.machines[i] = new LP_Machine(that, $(this));
		});
		
		this.totalMachines = this.machines.length;
		
	}
};

LP_Serie.prototype.getOutput = function () {
	
	if (this.title != false) {
		
		var data = {
			title: this.title
		};
			
		var tpl = new Template(LP_Serie_Title_Template);
		return tpl.evaluate(data);
		
	} else {
		
		var machines = '';
		$.each(this.machines, function(i, machine){
			machines += machine.getOutput(i);
		});
		var data = {
			machines: machines
		};
		
		var tpl = new Template(LP_Serie_Template);
		return tpl.evaluate(data);
		
	}
};

var LP_Serie_Template 	 = '<table cellspacing="0" cellpadding="0" class="LP_series">'+newline;
LP_Serie_Template 		+= '{[machines]}';
LP_Serie_Template 		+= '</table>'+newline;

var LP_Serie_Title_Template 	 = '<table cellspacing="0" cellpadding="0" class="LP_series">'+newline;
LP_Serie_Title_Template 		+= tab+'<tr class="LP_serie_title_row">'+newline;
LP_Serie_Title_Template 		+= tab+tab+'<td class="LP_title_serie">{[title]}</td>'+newline;
LP_Serie_Title_Template 		+= tab+'</tr>'+newline;
LP_Serie_Title_Template 		+= '</table>'+newline;
