$(function(){
	if ($('div.itemlist h3').length > 0) {
		$('div.itemlist h3').hide();
		$('h4.subhead').after('<ul id="tabs"></ul>');
		$('div.itemlist').each(function(){
			$('#tabs').append('<li><a href="'+pageUrl[0]+'#'+this.id.replace('tab','')+'">'+this.title+'</a></li>');
		});
		if ($('#tabs li').length > 1) {
			// add a view all link
			$('h2.category').append('<a href="'+pageUrl[0]+'#all" class="view-all">see all</a>');
		}
		if (!(jQuery.browser.safari == true && jQuery.browser.version <= 418.8)) {
			// safari 2 has buggy layout when these are removed
			$('div.itemlist a.anchor').remove();
		}
		// assign action to tab links
		$('#tabs a, #nav a.subcat, a.view-all').click(function(){
			$(window).scrollTop(0);
			$('div.itemlist').hide();
			$('div.itemlist h3').hide();
			$('#tabs a, #nav a.subcat').removeClass('active');
			var hash = this.href.split('#', 2)[1];
			if (hash) {
				if (hash == 'all') {
					// show all
					$('div.itemlist h3').show();
					$('div.itemlist').slideDown('normal');
				} else {
					$('div#tab'+hash).slideDown("normal", function(){
						if (jQuery.browser.msie == true && jQuery.browser.version <= 6.0) {
							// fix behavior on short thumbnail lists in IE6
							// ridiculous but it seems to work
							$("ul#tabs a").focus().blur();
						}
					});
					$("#tabs a[href$='#"+hash+"'], #nav a.subcat[href$='#"+hash+"']").addClass('active');
				}
				$('#nav a.subcat').blur();
			}
			return true;
		});
		// trigger action on either first tab or tab set in url hash
		if (pageUrl[1]) {
			$("#nav a.subcat[href$='#"+pageUrl[1]+"']").eq(0).click();
		} else {
			$('#tabs a').eq(0).click();
		}
	}
	// ie6 fixes
	if (jQuery.browser.msie == true && jQuery.browser.version <= 6.0) {
		$('div.itemlist div.row').append('<div class="clear"></div>');
	}
});

