ToplistRegular = function(options){
	this.init(options);
}

ToplistRegular.prototype = {
	options : null,
	tableTemplate: '<table id="table-toplist" class="table-toplist"><thead>{0}</thead><tbody>{1}</tbody></table>',
	headingTemplateIT: '\
					<tr>\n\
						<th scope="col" class="table-heading-toplist-rank table-heading-toplist-first">{0}</th>\n\
						<th scope="col" class="poker-room">{1}<span class="icon icon-tooltip" title="{2}">?</span></th>\n\
						<th scope="col" class="table-heading-toplist-rating">{3}</th>\n\
						<th scope="col">{5}</th>\n\
						<th scope="col">{6}</th>\n\
						<th scope="col" class="table-heading-toplist-playnow table-heading-toplist-last">{7}</th>\n\
					</tr>' ,
	headingTemplate: '\
					<tr>\n\
						<th scope="col" class="table-heading-toplist-rank table-heading-toplist-first">{0}</th>\n\
						<th scope="col" class="poker-room">{1}<span class="icon icon-tooltip" title="{2}">?</span></th>\n\
						<th scope="col" class="table-heading-toplist-rating">{3}</th>\n\
						<th scope="col" class="table-heading-toplist-playersonline">{4}</th>\n\
						<th scope="col">{5}</th>\n\
						<th scope="col">{6}</th>\n\
						<th scope="col" class="table-heading-toplist-playnow table-heading-toplist-last">{7}</th>\n\
					</tr>' ,
	rowTemplateIT: '\
				<tr{12}>\n\
						<td class="table-cell-toplist-rank table-cell-toplist-first" scope="row">{0}.</td>\n\
						<td class="table-cell-toplist-pokerroom"><span class="logo-container"><a class="icon-logo-square icon-logo-square-{1} link-main" id="abcd-toplist-logo" href="{2}" rel="nofollow">{3}</a><a class="link-review" id="abcd-toplist-review" href="{4}">{5}</a>{6}</span></td>\n\
						<td class="table-cell-toplist-rating">{7}</td>\n\
						<td class="table-cell-toplist-bonus">{9}</td>\n\
						<td class="table-cell-toplist-exclusive"><ul>{10}</ul></td>\n\
						<td class="table-cell-toplist-playnow table-cell-toplist-last">{11}</td>\n\
				</tr>',
	rowTemplate: '\
				<tr{12}>\n\
						<td class="table-cell-toplist-rank table-cell-toplist-first" scope="row">{0}.</td>\n\
						<td class="table-cell-toplist-pokerroom"><span class="logo-container"><a class="icon-logo-square icon-logo-square-{1} link-main" id="abcd-toplist-logo" href="{2}" rel="nofollow">{3}</a><a class="link-review" id="abcd-toplist-review" href="{4}">{5}</a>{6}</span></td>\n\
						<td class="table-cell-toplist-rating">{7}</td>\n\
						<td class="table-cell-toplist-rating">{8}</td>\n\
						<td class="table-cell-toplist-bonus">{9}</td>\n\
						<td class="table-cell-toplist-exclusive"><ul>{10}</ul></td>\n\
						<td class="table-cell-toplist-playnow table-cell-toplist-last">{11}</td>\n\
				</tr>',
	usFlagTemplate : '<img class="country-flag tooltip" src="{0}" alt="{1}" title="{2}"/>',
	bonusTemplatePercent : '<span class="increase"><a href="{0}" id="abcd-bonus-match-percent" rel="nofollow">{1}%</a></span> <span class="text-description">{2}</span>\n\
							<span class="text-bonus-max"><a href="{0}" id="abcd-max-bonus-amount" rel="nofollow">{3}{4}</a><span class="icon icon-tooltip" title="{5}">?</span></span>\n\
							{6}',
	bonusTemplateFlat: '<span class="text-bonus-max"><a href="{0}" id="abcd-max-bonus-amount" rel="nofollow">{1} {2}{3}</a><span class="icon icon-tooltip" title="{4}">?</span></span>\n\
						{5}',
	standardBonusTemplatePercent : '<span class="text-bonus-standard">{0}: {1}% / {2}{3}</span>',
	standardBonusTemplateFlat : '<span class="text-bonus-standard">{0}: {1} {2}{3}</span>',
	playerVolume: '<a href="{0}" rel="nofollow">{1}</a>',
	playerVolumeNotAvailable : '<span class="text-description">{0}</span>',
	exclusiveOfferListItemTemplate : '<li{0}><a href="{1}" id="abcd-toplist-exclusive-offers" rel="nofollow">{2}</a><span class="icon icon-tooltip" title="{3}">?</span></li>',
	reviewTemplate : '<a href="{0}" rel="nofollow" class="button button-cta"><span>{1} ></span></a><span class="text-download"><a class="link-download" href="{2}" rel="nofollow">{3}</a></span>',
	playNowTemplate : '<a href="{0}" rel="nofollow" id="abcd-toplist-visit" class="button button-cta"><span>{1} ></span></a><span class="text-download"><a class="link-download" id="abcd-toplist-freedownload" href="{2}" rel="nofollow">{3}</a></span>',
	init : function(options) {
		this.options = options;
		this.options.rows = this.options['default'].rows;
		this.options.translations = this.options['default'].translations;

		if( options[this.options.currentCountry] !== undefined){
			if( options[this.options.currentCountry].rows !== undefined ) {
				this.options.rows = options[ this.options.currentCountry ].rows;
			}
			if( options[this.options.currentCountry].translations !== undefined ) {
				this.options.translations = options[ this.options.currentCountry ].translations;
			}
		}
	},
	render : function() {
		this.options.container.innerHTML = ''; //@todo fix this for IE
		var html = '';
		var rows = this.options.rows;
		var rowHtml = '', locale = '';
		for(i = 0; i < rows.length; i++ ){
			var row = rows[i];
			var usFlagTemplate = '';
			if( row.Review.CurrentLocale === 'en_US' ) {
				if(row.Partner.AllowedInUSA == '1') usFlagTemplate = pl2.utils.sprintf(this.usFlagTemplate, 
						pl2.cdnPath+'images/flag-us.jpg',
						'USA',
						this.options.translations['Tooltip.TOOLTIP_ACCEPTS_US_PLAYERS']);
			} else {
				if( row.Review.IsLocal == '1' ) usFlagTemplate = pl2.utils.sprintf(this.usFlagTemplate,
						this.options.translations['ToplistFlag.PATH'],
						this.options.translations['ToplistFlag.ALT'],
						this.options.translations['ToplistFlag.TOOLTIP_ACCEPTS_US_PLAYERS']);
			}
			
			if (row.Review.CurrentLocale === 'it_IT') {
				locale = 'it';
			}else {
				locale = '';
			}


			//if(row.Partner.AllowedInUSA == '1') usFlagTemplate = pl2.utils.sprintf(this.usFlagTemplate, this.options.translations['Tooltip.TOOLTIP_ACCEPTS_US_PLAYERS']);
			//var bonusTemplate = pl2.utils.sprintf(this.bonusTemplate, row.Review.OutClick, row.Partner.BonusInfo.MaxBonusAmount, row.Translations['Tooltip.TOOLTIP_DEPOSIT_FLAT']);
			//html += pl2.utils.sprintf(this.rowTemplate, i + 1, row.Partner.CSSName, row.Review.OutClick, row.Partner.Name, usFlagTemplate, bonusTemplate, row.Partner.Rating.OverallRating, row.Review.URLSegment, this.options.translations['TopListIndex.REVIEW']);

			var exclusiveOfferHTML = '';
			for(var j = 0; j < row.Review.ExclusiveOffers.length; j++){
				if(j > 1) break;
				var itemClass = '';
				if(j == 1 || j == row.Review.ExclusiveOffers.length - 1) itemClass = ' class="list-item-last"';
				
				if ( row.Review.ExclusiveOffers[j].Title.length == 0 )
				{
					exclusiveOfferHTML = '';	
				}
				else 
				{
					exclusiveOfferHTML += pl2.utils.sprintf(this.exclusiveOfferListItemTemplate, itemClass, row.Review.OutClick, this.truncate( row.Review.ExclusiveOffers[j].Title, 30 ), row.Review.ExclusiveOffers[j].Text);					
				}				
			}

			var standardBonusTemplate = '';
			if(row.Partner.Bonuses.StandardBonusMatchPercent){
				standardBonusTemplate = pl2.utils.sprintf(this.standardBonusTemplatePercent, this.options.translations['TopListRegular.REGULAR'], row.Partner.Bonuses.StandardBonusMatchPercent, row.Partner.Bonuses.StandardMaxBonus.Symbol, row.Partner.Bonuses.StandardMaxBonus.AmountFormated);
			}
			else {
				standardBonusTemplate = pl2.utils.sprintf(this.standardBonusTemplateFlat, this.options.translations['TopListRegular.REGULAR'], this.options.translations['TopListRegular.FLAT'], row.Partner.Bonuses.StandardMaxBonus.Symbol, row.Partner.Bonuses.StandardMaxBonus.AmountFormated );
			}
			
			var bonusTemplate = '';
			if(row.Partner.Bonuses.BonusMatchPercent){
				bonusTemplate = pl2.utils.sprintf(this.bonusTemplatePercent, row.Review.OutClick, row.Partner.Bonuses.BonusMatchPercent, this.options.translations['TopListRegular.UP_TO'], row.Partner.Bonuses.MaxBonus.Symbol, row.Partner.Bonuses.MaxBonus.AmountFormated, row.translations['Tooltip.TOOLTIP_DEPOSIT_PERCENT'], standardBonusTemplate);	
			}
			else {
				bonusTemplate = pl2.utils.sprintf(this.bonusTemplateFlat, row.Review.OutClick, this.options.translations['TopListRegular.FLAT'], row.Partner.Bonuses.MaxBonus.Symbol, row.Partner.Bonuses.MaxBonus.AmountFormated, row.translations['Tooltip.TOOLTIP_DEPOSIT_FLAT'], standardBonusTemplate);
			}
			
			var ctaTemplate = '';
			if(this.options.isReview) {
				ctaTemplate = pl2.utils.sprintf(this.reviewTemplate, row.Review.Link, this.options.translations['TopListRegular.BUTTON_READ_REVIEW'], row.Review.OutClick, row.translations['TopListRegular.LINK_VISIT']);
			}
			else {
				ctaTemplate = pl2.utils.sprintf(this.playNowTemplate, row.Review.OutClick, this.options.translations['TopListRegular.BUTTON_PLAY_NOW'], row.Review.OutClickDownload, this.options.translations['TopListRegular.LINK_FREE_DOWNLOAD']);
			}
			
			var rowAttributes = ' id="regular-' + (Number(this.options.offset) + i) + '-' + row.Partner.CSSName + '"';
			if(i == rows.length - 1) rowAttributes += ' class="table-row-toplist-last"';

			var playerVolumeTemplate = row.Review.Players ? pl2.utils.sprintf(this.playerVolume, row.Review.OutClick, row.Review.PlayersFormated) : pl2.utils.sprintf(this.playerVolumeNotAvailable, this.options.translations['TopListRegular.INFO_NOT_AVAILABLE']);

		/****************************************************/
		/* hide players online column for IT */
		var tableHead, tableRow;

		if (locale === 'it') {
			tableHead = this.headingTemplateIT;
			tableRow = this.rowTemplateIT;
		}else {
			tableHead = this.headingTemplate;
			tableRow = this.rowTemplate;
		}
		/****************************************************/

			rowHtml += pl2.utils.sprintf(tableRow, Number(this.options.offset) + i, row.Partner.CSSName, row.Review.OutClick, row.Partner.Name, row.Review.Link, this.options.translations['TopListRegular.LINK_READ_REVIEW'], usFlagTemplate, row.Partner.Rating, playerVolumeTemplate, bonusTemplate, exclusiveOfferHTML, ctaTemplate, rowAttributes);//, bonusTemplate, row.Partner.Rating.OverallRating, row.Review.URLSegment, this.options.translations['TopListIndex.REVIEW']);
		}



		if( rows.length ) {
			html += pl2.utils.sprintf(this.tableTemplate,
				pl2.utils.sprintf(tableHead, this.options.translations['TopListRegular.TABLE_HEADING_RANK'], this.options.translations['TopListRegular.TABLE_HEADING_POKER_SITE'], this.options.translations['Tooltip.TOOLTIP_POKER_SITE'], this.options.translations['TopListRegular.TABLE_HEADING_RATING'], this.options.translations['TopListRegular.TABLE_HEADING_PLAYERS_ONLINE'], this.options.translations['TopListRegular.TABLE_HEADING_BEST_SIGN_UP_BONUS'], this.options.translations['TopListRegular.TABLE_HEADING_EXCLUSIVE_OFFER'], this.options.isReview ? this.options.translations['TopListRegular.TABLE_HEADING_READ_REVIEW'] : this.options.translations['TopListRegular.TABLE_HEADING_PLAY_NOW']),
				rowHtml
			);
			this.options.container.innerHTML = html;
		}
	},
	truncate : function( string, length ) {
		if( string === undefined || string === null ) string = '';
		if( length === undefined || length === null ) length = 25;
		var stringLength = string.length;
		if( stringLength > length ) {
			string = string.substring( 0, length - 3 ) + '...';
		}
		return string;
	}
}



