jQuery(function($){
	

	var COL_COUNT = 12;
	//SKIMAX Premium image
	var PREMIUM_IMG = "/images/skimax.gif";
	//Star rating CSS effect
	var STAR_RATING_MULTIPLER = 25;
	

        /***jQuery tab init***/
	$('#tabs').tabs();


	/*** Accomodations Webapp Shared Header redraw***/

	$("table.ratetable th.rm_shared").each(function(){
		//$this = <td class="rm_shared">header1-1_header2-3_header3-2</td>
		//where '-' delimiter specifies the colspan for specific header
		//where '|' delimiter acts as separator for <th> contents
		var columnarr = $(this).html().split("|");
		var htmlwrite = "";
		var i = 0;
		
		for(i=0; i < columnarr.length;i++){
			if(columnarr[i] != "" && columnarr[i].split("-").length == 2)
				htmlwrite += "<th colspan='"+ columnarr[i].split("-")[1] +"'>" + columnarr[i].split("-")[0] +"</th>";
			else
				htmlwrite += "<th>&nbsp;</th>";
		}
		
		//add remaining columns on the end
		if(i < COL_COUNT)
			htmlwrite += "<th colspan='"+ (COL_COUNT - i).toString() +"'>&nbsp;</th>";
		
		
		
		//rewrite header shared header if htmlwrite not empty
		if(htmlwrite != "")
			$(this).replaceWith(htmlwrite);
	});
	
	//remove unused rows
	$("table.ratetable tr").each(function(){
		if($(this).find("td.lalign:first").html() == "")
			$(this).remove();
	});
	
	
	
	/*** Star Rating CSS: http://www.komodomedia.com/blog/2006/01/css-star-rating-part-deux***/
	//set initial resort rating via star_rating css.
	$("ul.star-rating li.current-rating").each(function(){
		$(this).css("width", parseFloat($(this).text()) * STAR_RATING_MULTIPLER);
	
	});
	
	/*** SKIMAX premium image show when isPremium field is true ***/
	$(".lodge .premium-cont").each(function(){
		if($(this).text() == "1")
			$(this).html("<img src='" + PREMIUM_IMG +"' alt='premium' />").show();
	});
	
	/*** show Max box if {tag_maxtext} is not empty ***/
	$(".lodge .max-cont").each(function(){
		if($(this).html() != "")
			$(this).parent().show();
	});
	
	
	
	// fix pager on the Accomodation tab //
	var $accomodationTab = $('#accomodation'),
		$hotDealsTab = $('#hot_deals');
		
	$pagerLinks1 = $accomodationTab.find('ul.pagination a');
	if ($pagerLinks1.length) {
		$pagerLinks1.each(function () {
			this.href = this.href+'#accomodation';
		});
	}
	
	$pagerLinks2 = $hotDealsTab.find('ul.pagination a');
	if ($pagerLinks2.length) {
		$pagerLinks2.each(function () {
			this.href = this.href+'#hot_deals';
		});
	}
	
	$accomodationTab.find('td:empty').remove();
	/**/
	$accomodationTab.find('th').each(function () {
		if ($.trim(this.innerHTML.toLowerCase()) === '&nbsp;') {
			$(this).remove();
		}
	});
	/**/
	$accomodationTab.find('table.ratetable').css('width', '100%').each(function () {
		if ($.trim($(this).text()) === '') {
			$(this).remove();
		}
	});	
    

});
