$(document).ready(function(){
	//return;
	jQuery.fn.reverse = function(){ return this.pushStack(this.get().reverse(), arguments);};
	
	var rev = false;
	taboffset = 15;
	var tabBox = $('.tab-box');
	if(tabBox.length == 0) tabBox = $('.tab-box-on'); 
	
	if(tabBox.hasClass('tbx-off') == false) {
		tabBox.addClass('tab-box-on').removeClass('tab-box');
		tabs = $('.tab', $('.tab-content'));

		if (tabBox.hasClass('reverse-tab-order')) {
			//jQuery.fn.reverse = Array.prototype.reverse;
			tabs = tabs.reverse();
			rev = true;
		}
		tabs.each(function(){
			var target = $(this).parent('.tab-content');
			var cTab = $(this).remove();
				cTab.insertBefore(target);
			$(this).css({left:taboffset+'px'});
			taboffset = taboffset+$(this).width();
			target.css({zIndex:0});
			$(this).click(function(){
				$('.tab-content').hide();
				if(jQuery.browser.msie && jQuery.browser.version < 7 && $('.tab-content').find('select').length > 0)
					$('.tab-content').find('select').hide(); //fix for IE6 select boxes coming through
				$('.tab').removeClass('active');
				$(this).addClass('active');
				target.show();
				if(jQuery.browser.msie && jQuery.browser.version < 7 && $('.tab-content').find('select').length > 0)
					target.find('select').show(); //fix for IE6 select boxes coming through
				return false;
			});
		});
		
		//$(tabs.get((rev == true) ? tabs.length-1 : 0)).trigger('click');
		if (tabBox.hasClass('show-last-tab')) {
			$(tabs.get(tabs.length-1)).trigger('click');
		} else {
			$(tabs.get(0)).trigger('click');
		}
		
	}
	//Image manipulation code
	//Makes sure that our instant styled images are fitting in the boxes
	$('.featured-props').css({visibility:'hidden'});
	var tW = 0;
	var tH = 0;
	var $imgs = $('img', $('.featured-props'));
		$imgs.wrap('<div class="tframe"></div>').parent('div').each(function(index){
			$(this).addClass('featured_'+index);
			tW = $(this).width();
			tH = $(this).height();
		});
		$imgs.width('auto');
		$imgs.height('auto');
		$imgs.each(function(){
			var w = $(this).width();
			var h = $(this).height();
			if((w/h>1)&&(w/h<tW/tH)){
				$(this).width(tW);
			}else{
				$(this).height(tH);
			}
			if($(this).width() > (tW + 30))
				
				$(this).css({left:'-'+Math.ceil(tW/2-($(this).width()/2)/2)+'px'});
		});
		$('.featured-props').css({visibility:'visible'});
});

