jQuery("document").ready(function() {

	// LOGIN FORM DROPDOWN
		
	jQuery(".nav .login a.dropdown").click(function() {
		jQuery(this).toggleClass("hover");
		jQuery(".nav .login .login-form").slideToggle(500);
		
		return false;
	});
	
	
	// PRETTYPHOTO
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto();
	

	// SLIDING DROPDOWNS
		
	jQuery(".nav li").each(function() {	
		
		var $sublist = jQuery(this).find("ul:first");
		
		jQuery(this).hover(function() {	
			jQuery(this).addClass("hover");
			$sublist.stop().css( {height:"auto", overflow:"hidden", display:"none"} ).slideDown(500, function() {
				jQuery(this).css( {height:"auto", overflow:"visible"} );
			});	
		},
		function() {	
			jQuery(this).removeClass("hover");
			$sublist.stop().slideUp(200, function()	{	
				jQuery(this).css( {display:"none", overflow:"hidden"} );
			});
		});	
	});
	
	
	// CONTENT TABS

    jQuery(function () {
        var tabContainers = jQuery('div.content-tab > div');
        tabContainers.hide().filter(':first').show();
        
        jQuery('div.content-tab ul.tabNavigation a').click(function () {
                tabContainers.hide();
                tabContainers.filter(this.hash).show();
                jQuery('div.content-tab ul.tabNavigation a').removeClass('selected');
                jQuery(this).addClass('selected');
                return false;
        }).filter(':first').click();
    });
 
 
	// CONTENT TOGGLE            
	
	jQuery('#toggle-view li').click(function () {

		var text = jQuery(this).children('p');

		if (text.is(':hidden')) {
			text.slideDown('200');
			jQuery(this).children('span').addClass('collapse');		
		} else {
			text.slideUp('200');
			jQuery(this).children('span').removeClass('collapse');		
		}
		
	});

	
	// FEATURED SLIDER 
	
	jQuery('.featured-nav').show();
	
	jQuery('.featured .slider').cycle({ 
	    fx:     'scrollHorz', 
	    speed:  '800', 
	    timeout: 5000, 
	    pager:  '.featured-nav ul',
	     
	    // callback fn that creates a thumbnail to use as pager anchor 
	    pagerAnchorBuilder: function(idx, slide) {
	        var img = jQuery(slide).children().eq(0).attr("src");
	        return '<li><a href="#"><img src="' + img + '" /></a></li>';
	    } 
	});
	
	
	// TABS NAVIGATION HOVERS 
	
	jQuery(".tab-nav ul li a").hover(function() { 
		jQuery(this).parent().addClass("hover")}, function() {
		jQuery(this).parent().removeClass("hover")
	});
	
	
	// SORTABLE PORTFOLIO

	jQuery('ul#filter a').click(function() {
		jQuery(this).css('outline','none');
		jQuery('ul#filter .current').removeClass('current');
		jQuery(this).parent().addClass('current');
		
		var filterVal = jQuery(this).text().toLowerCase().replace(' ','-');
				
		if(filterVal == 'all') {
			jQuery('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			jQuery('ul#portfolio li').each(function() {
				if(!jQuery(this).hasClass(filterVal)) {
					jQuery(this).fadeOut('slow').addClass('hidden');
				} else {
					jQuery(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});
	

	// PORTFOLIO SLIDER
	
	jQuery('#portfolio-slider .cover').cycle({ 
	    fx:     'scrollHorz', 
	    speed:  '800', 
	    pager:  '#button'
	});


	// TABS SWITCHING
	
	jQuery(function() {
		var contentWrapper = jQuery("#container .tabs .tab");
		// only show the first item, hide the rest
		contentWrapper.hide().filter(":first").show();
		
		jQuery("div.tab-nav ul li a").click(function () {
		
		    // check if this item doesn"t have class "current"
		    // if it has class "current" it must not execute the script again
		    if (this.className.indexOf("current") == -1){
		    	contentWrapper.hide();
		    	contentWrapper.filter(this.hash).show();
		    	jQuery("div.tab-nav ul li a").removeClass("current");
		    	jQuery(this).addClass("current");
		    }
		    return false;
		});
	});
	
	
	// CONTACT FORM VALIDATION
	
	jQuery("#commentForm").validate();
	
	
	// TOOLTIPS
	
	jQuery("a[tooltip]").colorTip({ color: "yellow" });
	
});
