$(document).ready(function(){
	//$("img").lazyload();
	$('.tab').click(function(){
		// hide all other tab boxes
		$(".tabbox").hide(0);
		
		// show the selected tab box
		$(".tab" + $(this).attr('toshow')).show(0);
		
		// remove current class from other tabs
		$('.tab').removeClass("current");
		
		// add current class to this tab
		$(this).addClass("current");
	});
	
	function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
	}
	
	$('#keywordsearch').keyup(function(e) {
   		if(e.keyCode == 13) {
   			window.location = "?target=productsearch&keywords=" + urlencode($('#keywordsearch').val());
      	}
    });
	
	$('#doKeywordSearch').click( function(){
		window.location = "?target=productsearch&keywords=" + urlencode($('#keywordsearch').val());
	});
	$('#doGroupSearch').click( function(){
		window.location = "?target=productsearch&group=" + urlencode($('#groupsearch').val());
	});
	
	
	// accordion paging
	$('.scroller tr[page!=1]').hide(); // hide everything not on page 1
	$('.scroller h3[page!=1]').hide(); // hide everything not on page 1
	
	// 
	$('.lightboxclosebutton').click( function(){
		$('.lightbox').fadeOut(250);
	});
	
	$('.accordionpagecontrol').hide();
	$('.accordionpagecontrol[page=1]').show();
	$('.accordionpagecontrol[page=1]').addClass('current');
	$('.accordionpagecontrol[page=2]').show();
	$('.accordionpagecontrol[page=3]').show();
	$('.accordionpagecontrol[page=4]').show();
	$('.accordionpagecontrol[page=5]').show();
	$('.alwaysShow').show();
	$('.accordionpagecontrol').click(function(){
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol').hide();
		var showto = parseInt($(this).attr('page'));
		
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol').removeClass('current');
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol[page=' + showto + ']').addClass('current');
		if(showto < 3)
		{
			showto = 3;
		}
		if(showto > $(this).siblings('.accordionpagecontrol').length -3)
		{
			showto =  $(this).siblings('.accordionpagecontrol').length -3; 
		}
		
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol[page=' + (showto - 2) + ']').show();
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol[page=' + (showto - 1) + ']').show();
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol[page=' + (showto + 0) + ']').show();
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol[page=' + (showto + 1) + ']').show();
		$('.scroller' + $(this).attr('domain') + ' .accordionpagecontrol[page=' + (showto + 2) + ']').show();
		$('.scroller' + $(this).attr('domain') + ' .alwaysShow').show();
		$('.scroller' + $(this).attr('domain') + ' tr[page!=' + $(this).attr('page') + ']').hide();
		$('.scroller' + $(this).attr('domain') + ' ul[page!=' + $(this).attr('page') + ']').hide();
		
		$('.scroller' + $(this).attr('domain') + ' *').removeClass('currentPage');
		$(this).addClass('currentPage');
		$('.scroller' + $(this).attr('domain') + ' h3[page!=' + $(this).attr('page') + ']').hide();
		$('.scroller' + $(this).attr('domain') + ' tr[page=' + $(this).attr('page') + ']').show();
		$('.scroller' + $(this).attr('domain') + ' ul[page=' + $(this).attr('page') + ']').show();
		$('.scroller' + $(this).attr('domain') + ' h3[page=' + $(this).attr('page') + ']').show();
	});
});
