jQuery.noConflict();
jQuery(document).ready(function($) {
								
	$('.tabs li a').click(function(){
		$('.panels .panel.visible').fadeOut();
		$($(this).attr('href')).fadeIn().addClass('visible');
		$('ul.tabs li a').each(function(){
			$(this).removeClass('active');
		})
		$(this).addClass('active');
		return false;
	});
	
	//Make sure the top catalogue is always selected
	$('.breadcrumbs a').each(function() {
		var pagehref = $(this).attr('href');
		$('.sidebar a[href="' + pagehref + '"]').parent().addClass('selected');
		$('#linkbar a[href*="' + pagehref + '"]').parent().addClass('selected');
	});
	
	//Remove the top sidebar sub-catalogue border
	$('.sidebar ul li:first-child a').css('border','none');
	
	//When on product page remove the catalog <h2> tag
	if ((location.href).search('_product_')>0 || (location.href).search('ProductID')>0) {
		$('h2.catalog_name').remove();	
	};
	
	//Copy the pagination from the top to the bottom or remove if not exist
	if ($('#pagination a').is('#pagination a')) {
		var pagination = $('div#page-top').html();
		$('div#page-bottom').html(pagination);
	} else {
		$('div#page-top').remove();
	}
	
	//Add the blank prev and next page buttons
	if (!($('.page_prev').children().is('a'))) {
		$('.page_prev').html('<img alt="previous page" src="/images/cssimg/page_prev_blank.gif"/>');
	}
	if (!($('.page_next').children().is('a'))) {
		$('.page_next').html('<img alt="next page" src="/images/cssimg/page_next_blank.gif"/>');
	}
	
	//make hover and focus events for add to cart
	$('.addToCartSmall').live('mouseover',function(){
		$(this).attr('src','/Images/cssimg/add-to-cart-small-hover.png');
	});
	$('.addToCartSmall').live('mouseout',function(){
		$(this).attr('src','/Images/cssimg/add-to-cart-small.png');
	});
	$('.addToCartSmall').live('mousedown',function(){
		$(this).attr('src','/Images/cssimg/add-to-cart-small-active.png');
	});
	$('.addToCartSmall').live('mouseup',function(){
		$(this).attr('src','/Images/cssimg/add-to-cart-small.png');
	});

	$('#added-bubble .close').click(function(){
		$('#added-bubble').stop();
		bubble.hide();
		return false;
	})
	
	var bubble = {

		show:function(){
			$('#added-bubble').css({'display':'block','width':'0','left':'0','opacity':'0','height':'0'});
			$('#added-bubble').stop().animate({'width':'475','left':'-450','opacity':'1','height':'195'},1000)
			.animate({'opacity':1},3000,'',function(){
				bubble.hide();
			});
			
		},
		hide:function(){
			$('#added-bubble').fadeOut(500,function(){
				$('#added-bubble').css('display','none');
			});
		}
	}
	
	
	//Catagory list page - jquery used to enable hover effect in IE6 and activate click
	if($.browser.msie){
		$('.catalogueList li').hover(function(){
			$(this).addClass('hover');
		},function(){
			$(this).removeClass('hover');
		});
		$('.shop-product-small').hover(function(){
			$(this).addClass('hover');								
		},function(){
			$(this).removeClass('hover');
		});
	}
	$('.catalogueList li').click(function(){
		location.href = $(this).find('a').attr('href');
	});
	
	//Catch alert messages
	window.alert = function(msg) {
		$('.alert').html('<span>' + msg + '</span>');
		if (msg.search('ERROR')>=0) {
			$('.alert span').css({'border':'2px solid #9B3939','background-color':'#FFBDBD'});  
		}
		$('html, body').animate({scrollTop:0}); 
		
	//if addtocart clicked
		if(msg == '1 item(s) added to your cart.'){
			bubble.show();
		}
		
		addToCartInput = '';
		return false;
	};
	var sidebar_speed = 400;
	$('.nav .sidebar_header.selected').next('ul').css('display','block').addClass('open');
	$('.nav .sidebar_header.selected .sidebar-strip').css('background-position','0 -180px');
	$('.nav .sidebar_header a').click(function() {
		if ($(this).parent().next('ul').is('.open')) {
			$(this).parent().next('ul').slideUp(sidebar_speed).removeClass('open');
			$(this).next('.sidebar-strip').frameUp(sidebar_speed,20,10);
		} else {
			$('.nav ul.open').slideUp(sidebar_speed).removeClass('open').parent().find('.sidebar-strip').frameUp(sidebar_speed,20,10);
			$(this).addClass('open').parent().next('ul').slideDown(sidebar_speed).addClass('open');
			$(this).next('.sidebar-strip').frameDown(sidebar_speed,20,10);
		}
		return false;
	});
});
