


function sliderInit(minPrice, maxPrice){
	
	$j( "#priceSlider" ).slider({
		range: true,
		min: minPrice,
		max: maxPrice,
		animate: true,
		values: [ minPrice, maxPrice ],
		slide: function( event, ui ) {
			var curSymbol = $j('.curSymbol').html();
			//$j("#priceFilter a").eq(0).html('<span class="uiTrackerButtonNo uiTracker1">'+ $j('.curSymbol').html()+ ui.values[ 0 ] +'</sapn>');
			//$j("#priceFilter a").eq(1).html('<span class="uiTrackerButtonNo uiTracker2">'+ $j('.curSymbol').html()+ ui.values[ 1 ] +'</sapn>');
			$j("#priceRange").html('Showing Products Between <br /><b>' + curSymbol + ui.values[ 0 ] + ' &amp; ' + curSymbol + ui.values[ 1 ] + '</b>')
		},
		stop: function(event, ui){ doPriceFilter(ui.values[0], ui.values[1]) }
	});
	
}


function getMinPrices(){
	
	var minPrice = 0;
	
	$j(".product-item-cont").each(function(){
		
		var itemPrice = $j(this).find('#category-product-price').html();
		itemPrice = itemPrice.substring(1);
		itemPrice = parseFloat(itemPrice)
		itemPrice = Math.floor(itemPrice);
		//console.log(itemPrice);
		if(minPrice == 0) minPrice = itemPrice;
		
		if(itemPrice < minPrice) {minPrice = itemPrice;}
	});
	
	return minPrice;
	
}

function getMaxPrices(){
	
	var maxPrice = 0;
	
	$j(".product-item-cont").each(function(){
		
		var itemPrice = $j(this).find('#category-product-price').html();
		//var itemPrice = 
		itemPrice = itemPrice.substring(1);
		itemPrice = parseFloat(itemPrice);
		itemPrice = Math.ceil(itemPrice);
		//console.log(itemPrice);
		
		if(itemPrice > maxPrice ) {maxPrice = itemPrice;}
	});
	
	return maxPrice;
	
}

function doPriceFilter(minPrice, maxPrice){
	
	$j(".product-item-cont").each(function(){
		
		var itemPrice = $j(this).find('#category-product-price').html();
		itemPrice = itemPrice.substring(1);
		itemPrice = parseFloat(itemPrice);
		
		if ((itemPrice <= minPrice) || (itemPrice >= maxPrice)) {
			$j(this).hide();
			$j(this).removeClass('priceShow');
		}
		else {
			$j(this).show(); $j(this).addClass('priceShow');
		}
		
		// COUNT NUMBER OF ITEMS IN VIEW
		if($j('.product-item-cont:visible').length == 0) {
			if( $j("#NoContentToShow").length == 0 ){
				$j("#category-products").append('<div id="NoContentToShow"><h4>Price Range Too Strict</h3>Try increasing your product price range</div>');
			}
		}
		else {
			if( $j("#NoContentToShow").length != 0 ){
				$j("#NoContentToShow").remove();
			}
		}
		
	});
	
}


$j(window).bind('load', function(){
	var curSymbol = $j('.curSymbol').html();
	sliderInit(getMinPrices(), getMaxPrices());
	$j("#priceRange").html('Showing Products Between <br /><b>' + curSymbol + getMinPrices() + ' &amp; ' + curSymbol + getMaxPrices() + '</b>')
	
	if( $j("#category-products").length != 0 ) {$j("#priceFilter").fadeIn();}

});


function sameHeight(c){
	var h = 0;
	
	$j(c).each(function(){
		var th = $j(this).height()
		h = (th > h)? th : h;
	});
	
	$j(c).height(h);	
}

$j(function(){
	sameHeight('#category-products .product-item-cont');
});


