// Equal height columns
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

jQuery(document).ready(function() {
// No spam, please
    jQuery('a.emailaddy').each(function(i) {
        var text = $(this).text();
        var address = text.replace(" at ", "@");
        jQuery(this).attr('href', 'mailto:' + address);
            jQuery(this).text(address);
        });

// Main Navigation Drop Down Menu
    jQuery("ul#main_nav li.dropdown").hover(function(){
    
        jQuery(this).addClass("hover");
        jQuery('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        jQuery(this).removeClass("hover");
        jQuery('ul:first',this).css('visibility', 'hidden');
    
    });
    
// Start Project Button Fade
	jQuery('.start_project').append('<span class="hover"></span>').each(function () {
	  var $span = jQuery('> span.hover', this).css('opacity', 0);
	  jQuery(this).hover(function () {
	    $span.stop().fadeTo(300, 1);
	  }, function () {
	    $span.stop().fadeTo(300, 0);
	  });
	});
	
// Our Services Button Fade
	jQuery('.our_services').append('<span class="hover"></span>').each(function () {
	  var $span = jQuery('> span.hover', this).css('opacity', 0);
	  jQuery(this).hover(function () {
	    $span.stop().fadeTo(300, 1);
	  }, function () {
	    $span.stop().fadeTo(300, 0);
	  });
	});
	
	
// Portfolio Thumbnail Fade Effect
	jQuery("ul#filter-portfolio li .thumb").hover(function() { //On hover...

		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		jQuery(this).find("a.fade_thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		jQuery(this).find("span").stop().fadeTo(300, 0 , function() {
			jQuery(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		jQuery(this).find("span").stop().fadeTo(300, 1).show();
	});
	
// Related Thumbnail Fade Effect
	jQuery("ul#related-list li .thumb").hover(function() { //On hover...

		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		jQuery(this).find("a.fade_thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		jQuery(this).find("span").stop().fadeTo(300, 0 , function() {
			jQuery(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		jQuery(this).find("span").stop().fadeTo(300, 1).show();
	});
	
// Initiate Equal Height Columns
    equalHeight($(".project_title"));
    equalHeight($(".excerpt_text"));
    
// Toggle Search Form
	jQuery("#toggle_search").hide();
	jQuery(".show_search").click(function() {
		jQuery("#toggle_search").slideToggle(300);
		jQuery(this).toggleClass("hide_search"); return false;
	});
	
// Toggle Categories
	jQuery("#category_list").hide();
	jQuery(".show_categories").click(function() {
		jQuery("#category_list").slideToggle(300);
		jQuery(this).toggleClass("hide_categories"); return false;
	});
	
// Project Details Page Slideshow
    jQuery('#portfolioitem_slideshow').before('<div id="portfolioslide_nav">').cycle({
        fx:			'fade',
        speed:		400,
        timeout:	5000,
        pager:		'#portfolioslide_nav'
    });
    
// Home Page Slide Show
	jQuery('#home_slides').after('<div id="homeslide_nav">').cycle({
		fx:			'fade',
		speed:		400,
		timeout:	8000,
		pager:		'#homeslide_nav'
	});
	
// Fancybox
	jQuery("a.grande").fancybox();

});

// Animated Scrolling
jQuery(document).ready(function() {
	$("a.scrollit").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 400
	}, settings);	
	
	return this.each(function(){
		var caller = this
		jQuery(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = jQuery(caller).attr("href")
			
			var destination = jQuery(elementClick).offset().top;
			jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}
