jQuery(document).ready(function(){



	// Hides the arrow on navigation items w/o a dropdown
	
	jQuery('#navigation li').not(':has(ul)').hover().css('background-image', 'none');
	

	
	// Wraps dropdowns in a div tag
	
	jQuery('#navigation li ul').wrap('<div />');

	
	
	// Arranges the footer widgets with Masonry
	
	jQuery('#footer .sidebar').masonry({ columnWidth: 330 });
	

	
	// Clears fields on focus, resets value on blur
	
	jQuery.fn.clear_field = function() {
		return this.focus( function() {
			if ( this.value == this.defaultValue ) this.value = "";
		}).blur( function() {
			if ( !this.value.length ) this.value = this.defaultValue;
		});
	};
	jQuery('input[name=s]').clear_field();
	

	
	// Enables the tabbed widget
	
	jQuery('.wct-tabs a').click(function(){
		jQuery('.create_tabbed a').removeClass('current');
		jQuery(this).addClass('current');
		jQuery('.create_tabbed ul:not(.wct-tabs)').hide();
		jQuery('.wct-' + jQuery(this).html().toLowerCase()).fadeIn();
		return false;
	});
	
	
	
	// Fades store/portfolio link overlays
	
	jQuery('.thumbnails .post-thumbnail').hover( function () {
		jQuery(this).find('ul').css('display','inline').animate({opacity: 0}, 0).stop().animate({opacity: 1}, 300);
	}, function () {
		jQuery(this).find('ul').stop().animate({opacity: 0}, 300);
	});
	
	
	
	// Filters
	
	jQuery('#create-filters a').click(function(){
		jQuery('#create-filters a').removeClass('active');
		jQuery(this).addClass('active');
		var tag = jQuery(this).html().toLowerCase();
		jQuery('.thumbnails > li').each(function(){
			if ( jQuery(this).hasClass(tag) ) {
				jQuery(this).removeClass('hidden').show();
			} else {
				jQuery(this).addClass('hidden').hide();
			}
		});
		if (tag == 'all') jQuery('.thumbnails > li').removeClass('hidden').show();
		return false;
	});
	
	
	
	// Portfolio Galleries

	jQuery('.gallery-link').each(function(index){
		var rel = jQuery(this).attr('rel');
		jQuery(this).removeAttr('rel');
		jQuery('a[rel=' + rel + ']').fancybox();
		jQuery(this).click(function() {
			jQuery('.post-thumbnail ul').stop().animate({opacity: 0}, 0);
			jQuery('a[rel=' + rel + ']:eq(0)').trigger('click');
			return false;
		});
	});
	

	
});
