var base = "/";$(document).ready(function(){
	Cufon.replace('.fgm', {fontFamily: 'Franklin Gothic Medium'});
	Cufon.replace('.fgh', {fontFamily: 'Franklin Gothic Heavy', hover:true});
	Cufon.replace('.fgb', {fontFamily: 'Franklin Gothic Book'});
	Cufon.replace('.fgd', {fontFamily: 'Franklin Gothic Demi'});
	Cufon.replace('.title', {fontFamily: 'Franklin Gothic Heavy', color: '-linear-gradient(#ffffff, #adadad)',textShadow: '2px 2px #000000'});
	Cufon.replace('.title2', {fontFamily: 'Franklin Gothic Heavy', color: '-linear-gradient(#ffffff, #adadad)'});
	Cufon.replace('#middle li.ui-tabs-selected a', {color: '#b75b00'});
	$('#topnav li a').mouseover(function(){
		$('#topnav li.active').removeClass('active');
		if($(this).parent().hasClass('products')){
		  $(this).parent().addClass('active');
		  $('#header div#products-sub').show();
		}
		else{
		  $(this).parent().addClass('active');
		  $('#header div#products-sub').hide();
		}
	});
	$('#topnav li a').mouseout(function(){
		if(!$(this).parent().hasClass('products')){
		  $(this).parent().removeClass('active');
		}
	});
	$('#header h1').mouseover(function(){
		$('#header div#products-sub').hide();
		$('#topnav li.active').removeClass('active');
	})
	$('#header div#products-sub').mouseleave(function(){
		$('#header div#products-sub').hide();
		$('#topnav li.products').removeClass('active');
	})
	// $('#header li.products').click(function(){return false})
	// set up rating functionality
	/*
	$(".product-rate .starrate").bind('click',function(){ 
		// page: will be {$cur_page.id}
		$.ajax({url:'/modules/ajax.php?rateItem' , dataType:"json", type: "POST", data:{type: 'product', itemid: $("#rater").attr("title"), rate: $(this).attr("id")}, success:function(response) {
			var perc = response.your_rate*20;
			$('#current-rating').attr("style","width:"+perc+"%; background-position: left bottom;");
			$('#avg_rate').html(response.avg_rate+"/5 average rating");
		}});
		return false;
	});
	*/
	$(".rate-review .starrate").live('click', function(){ 
		$('#current-rating.my').attr("style","width:"+($(this).attr("id")*20)+"%; background-position: left bottom;");
		$('#rate').val($(this).attr("id"));
		return false;
	});
	
	$('#perpagego').hide(); // the submit btn is hidden for js-enabled users
	$('#perpage select').change(function() {updateDisplay()});
	
	if (!$.browser.msie()){
	  if($.browser.OS() == "Mac"){
	    $('div#products-sub').css('left', '69px');
	  }
  }
  // 
});

function updateDisplay() {
	$.ajax({url:base+'modules/ajax.php?setDisplayOpts' , dataType:"json", type: "POST", data:{q: $('#query').html(), sortby: $('#sortby').val(), perpage: $('#showperpage').val(), product_category_id: $('#product_cat_id').html(), brand_id: $('#brand_id').val(), vehicle_id: $('#vehicle_id').val()}, success:function(response) {
		$('#product_page').html(response.data);
		$('#perpage select').change(function() {updateDisplay()});
	}});
	return false;
}

function goTo(url) {
	window.location = url;
}

