$(document).ready(function(){
	
	//cart edit/view item dropdown slides etc...
	$('div#left-your_cart ul.cart_list > li a').click(function(){		
		//if current subs are showing, do nothing
		if($(this).parent().attr('class') == 'active_edit_cart_item') {
			return false;
		}
		//hide current subs
		$('div#left-your_cart ul.cart_list > li:has(div) div').slideUp('slow',function(){
			$(this).parent().removeClass('active_edit_cart_item');
		});
		//add class to selected parent li
		$(this).parent().addClass('active_edit_cart_item');
		//show selected category subs
		$(this).parent().children('div').slideDown('slow');
		//return false so it doesnt go crap
		return false;		
	});
	
	//category dropdown slides etc...
	$('div#left-product_catalogue_categories ul.categories > li a').click(function(){		
		//if current subs are showing, do nothing
		if($(this).parent().attr('class') == 'active_catalogue_category') {
			return false;
		}
		//if no sub then goto link
		if($(this).parent('li:has(ul)').length == 0) {
			return true;
		}
		//hide current subs
		$('div#left-product_catalogue_categories ul.categories > li:has(ul) ul').slideUp('slow',function(){
			$(this).parent().removeClass('active_catalogue_category');
		});
		//add class to selected parent li
		$(this).parent().addClass('active_catalogue_category');
		//show selected category subs
		$(this).parent().children('ul').slideDown('slow');
		//return false so it doesnt go crap
		return false;		
	});
	
	//product catalogue category list
	$('ul#catalogue_category_list li').hover(
		function () { $(this).addClass("hover") },
		function () { $(this).removeClass("hover") }
	);
	
	//product catalogue category list click
	$('ul#catalogue_category_list li').click(function() {
	 window.location = $(this).children('a').attr('href');
	});
	
	//alternating colours for product list display
	$('ul#catalogue_product_list li:even').addClass('odd');
	
	//alternating colours for product list display
	$('ul#latest_news_list li:even').addClass('odd');
	
	//use margin to position thumbnails in product images section
	$('#product_images .small_images a:even').addClass('even');
	
	//alternate table row background colors
	$('table.zebra tr:even').addClass('alt');
	
	//make our forms pretty and accesible	
	$(document).ready(function() {                
		if(jQuery.browser.mozilla) {
			$('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
				var $labelContent = $(this).html();
				var $labelWidth = $(this).css('width');
				$(this).empty();
				$(this).append('<span style="display: block; width: '+$labelWidth+';">');
				$(this).prepend('</span>');
				$(this).css('display', '-moz-inline-box');
				$(this).find('span').html($labelContent);
				$('form.cmxform').show();
			});
		};             
	});
  
  /*
    used just to show functionality
    should be deleted once programming has changed this functionality
  */
  //add to cart ajax update
  $('#product_detail-add_to_cart_complete').hide();
  $('#_5_add_to_cart_button').click(function() {
    $('#product_detail-add_to_cart').hide();
    $('#product_detail-add_to_cart_complete').show();
    $(this).blur();
    return false;
  });
	
	$('#navigation li').hover(
		function(){
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
		}
	)
	
	// open links with rel="external" in a new window
	$('a[@rel$="external"]').click(function(){
     this.target = "_blank";
  });
	
});