$(document).ready(function(){initSelect();catFilter();sortFilter()});function initSelect(){$('div.select span').each(function(i){var curRel=$(this).parents('div.select').find('ul li a:first').text();$(this).html(curRel)});$('div.select span').click(function(){closeAll($(this));var curPosition=$(this).parents('div.select').css('position');$(this).parents('div.select').css('position',(curPosition=='static')?'relative':'static');$(this).parents('div.select').find('ul').toggle()});$("div.select ul li").hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});$('div.select ul li a').click(function(e){e.preventDefault();var curText=$(this).text();var curValue=$(this).attr('rel');$(this).parents('div.select').css('position','static');$(this).parents('div.select').find('input').attr('value',curValue);$(this).parents('div.select').find('span').html(curText);$(this).parents('div.select').find('ul').hide()});$(document).click(function(e){var trgt=$(e.target);if(!trgt.parents().hasClass('select')){$('div.select ul').hide();$('div.select').css('position','static')}})}function closeAll(obj){var els=$('div.select span').not(obj);els.parents('div.select').css({'position':'static'}).find('ul').hide()}function catFilter(){$("div.select ul.cat li").click(function(){window.location.assign($(this).children().attr('href'));return false});$('div.cat span').each(function(i){var curRel=$(this).parents('div.cat').find('ul li.active a:first').text();$(this).html(curRel)})}function sortFilter(){$("div.select ul.sortby li").click(function(){window.location.assign($(this).children().attr('href'));return false});$('div.sortby span').each(function(i){var curRel=$(this).parents('div.sortby').find('ul li.active a:first').text();$(this).html(curRel)})}


(function($){ 
     $.fn.extend({  
         tabify: function( callback ) {
         	
			function getHref(el){
				hash = $(el).find('a').attr('href');
				hash = hash.substring(0,hash.length-4);
				return hash;
			}
			
		 	function setActive(el){
		 		
				$(el).addClass('active');
				$(getHref(el)).show();
				$(el).siblings('li').each(function(){
					$(this).removeClass('active');
					$(getHref(this)).hide();
				});
			}
			
			return this.each(function() {
			
				var self = this;
				var	callbackArguments 	=	{'ul':$(self)};
					
				$(this).find('li a').each(function(){
					$(this).attr('href',$(this).attr('href') + '-tab');
				});
				
				function handleHash(){
					
					if(location.hash && $(self).find('a[href=' + location.hash + ']').length > 0){				
						setActive($(self).find('a[href=' + location.hash + ']').parent());
					}
				}
				
				if(location.hash){
					handleHash();
				}
					
				setInterval(handleHash,100);
				
				$(this).find('li').each(function(){
					if($(this).hasClass('active')){
						$(getHref(this)).show();
					} else {
						$(getHref(this)).hide();
					}
				});
				
				if(callback){
					callback(callbackArguments);
				}	
				
            }); 
        } 
    }); 
})(jQuery);

$().ready(function() {
	$(".tabsd").tabify();
});


