function navigation()
{
	$('ul#nav-main > li').mouseover( function()
	{
		$('a', this).addClass('selected');
		$('ul', this).css('display', 'block');
	});
	$('ul#nav-main > li').mouseout( function()
	{
		$('a', this).removeClass('selected');
		$('ul', this).css('display', 'none');
	});
}

function ro()
{
	$('.ro').mouseover( function()
	{
		rep = ".";
		ext = $(this).attr('src').substr(-4, 4);
		src = $(this).attr('src').replace(rep, "-on.");
		$(this).attr('src', src);
		
	});
	$('.ro').mouseout( function()
	{
		rep = "-on.";
		ext = $(this).attr('src').substr(-4, 4);
		src = $(this).attr('src').replace(rep, ".");
		$(this).attr('src', src);
		
	});
}

function removeItem(){
	$('.removeItem').click(function(evt){
		url = "/action/purchase/cartUpdate.php?product-id=" + $(this).attr('href') + "&send=cart&qty=0";		
		location.href=url;
		evt.preventDefault();
	});
}

function updateItem(){
	$('.updateItem').click(function(evt){
		evt.preventDefault();
		var $item_id = parseInt($(this).attr("rel"));
		var $qty = parseInt($('input[rel=' + $item_id + ']', $('#shopping_cart')).val());
		url = "/action/purchase/cartUpdate.php?product-id=" + $item_id + "&send=cart&qty=" + $qty;		
		location.href=url;		
	});
}

$(function(){
	navigation();
	ro();
	removeItem();	
	updateItem();
	$('#filterby').change(function(){
		location.href = '/products/brand/' + $('option:selected', $(this)).val() + '/';							   
	});
	$('#updateCart').click(function(evt){
		evt.preventDefault();
		$('#shopping_cart').submit();
	});
	$('#public_registry').change(function(){
		if($('#public_registry:checked').length > 0){
			$value = 0;
		} else {
			$value = 1;	
		}
		$.post("/action/accounts/changeWishlist.php", {value: $value});
	});
});