jQuery(document).ready(function($) {
	$('.listing-tab').each(function() {
		var oListing = $(this);
		
		$('li', oListing).click(function() {
			var target = null;
			
			if ($('li.item-selected a', oListing) != $(this)) {
				
				// Hide the current shown
				target = $('li.item-selected a', oListing).attr('href');
				target = target.substr(target.lastIndexOf('#'));
				
				$(target).hide();
				
				$('li.item-selected', oListing).removeClass('item-selected');
			
				// Show clicked item
				target = $('a', this).attr('href');
				target = target.substr(target.lastIndexOf('#'));
				
				$(target).show();
				
				$(this).addClass('item-selected');
			}
			
			return false;
		}).css('cursor', 'pointer');
	});
	$('#fm_main').change(function() {
		var id = "";
 		id = $("#fm_main option:selected").val();
		$('#sub_prods select').each(function() {
			var listing = $(this);	
			$(listing).addClass('hide');
		});
		
          	 $("#fm_sub"+id).removeClass('hide'); 
		var sub_id = $("#fm_sub"+id+" option:selected").val();
		$('#sub_prods_price label').each(function() {
			var listing = $(this);	
			$(listing).addClass('hide');
		});
		$("#price"+sub_id).removeClass('hide'); 

	});
	$('#sub_prods select').change(function() {
		var sub_id = $(this).val();
		$('#sub_prods_price label').each(function() {
			var listing = $(this);	
			$(listing).addClass('hide');
		});
		$("#price"+sub_id).removeClass('hide'); 
	});
	var main_id = $("#fm_main option:selected").val();
	$('#sub_prods select').each(function() {
		var listing = $(this);	
		$(listing).addClass('hide');
	});
		
	$("#fm_sub"+main_id).removeClass('hide');
	
	var sub_id = $("#fm_sub"+main_id+" option:selected").val();
	$('#sub_prods_price label').each(function() {
		var listing = $(this);	
		$(listing).addClass('hide');
	});
	$("#price"+sub_id).removeClass('hide');
	
	$('#mc_signup_form input[type=text]').each(function() {
		var value = $(this).prev().prev().text().replace(' *', '') + ' ';
		$(this).val(value);
		$(this).focus(function() {
				if ($(this).val() == value) $(this).val('');
			}).blur(function() {
				if ($(this).val() == '') $(this).val(value);
			});;
	});
});

jQuery(window).load(function() {
	// Post listing page
	var i=1;
	
	jQuery('.listing-posts li').each(function() {
		if (i%2 == 0) {
			var iHeight = jQuery(this).height() > jQuery(this).prev().height() ? jQuery(this).height() : jQuery(this).prev().height();
			
			jQuery(this).height(iHeight);
			jQuery(this).prev().height(iHeight);
		}
		
		++i;
	});
});



