// PrettyPhoto (lightbox)
jQuery(document).ready(function($){
	$("a[rel^='prettyPhoto']").prettyPhoto();
});

// Portfolio thumbnail hover effect
jQuery(document).ready(function () {
	jQuery('#portfolio .block img, .email-templates img').mouseover(function() {
		jQuery(this).stop().fadeTo(300, 0.4);
	});
	jQuery('#portfolio .block img, .email-templates img').mouseout(function() {
		jQuery(this).stop().fadeTo(400, 1.0);
	});
});

// Home Featured hover effect
jQuery(document).ready(function () {
    jQuery('.featured-image').bind('mouseenter',function(){
      	jQuery('.featured-image a.feat-overlay-button').animate({opacity:1})
    }).bind('mouseleave',function(){
        jQuery('.featured-image a.feat-overlay-button').animate({opacity:0.3})
    });
}); 

// Portfolio tag sorting
jQuery(document).ready(function(){
								
	jQuery('.port-cat a').click(function(evt){
		var clicked_cat = jQuery(this).attr('rel');
		if(clicked_cat == 'all'){
			jQuery('#portfolio .post').hide().fadeIn(200);
		} else {
			jQuery('#portfolio .post').hide()
			jQuery('#portfolio .' + clicked_cat).fadeIn(400);
		 }
		//eq_heights();
		evt.preventDefault();
	})	

	// Thanks @johnturner, I owe you a beer!
	var postMaxHeight = 0;
	jQuery("#portfolio .post").each(function (i) {
		 var elHeight = jQuery(this).height();
		 if(parseInt(elHeight) > postMaxHeight){
			 postMaxHeight = parseInt(elHeight);
		 }
	});
	jQuery("#portfolio .post").each(function (i) {
		jQuery(this).css('height',postMaxHeight+'px');
	});
														
});

// Back to top
$(function () {
    $(window).scroll(function () {
        if ($(this).scrollTop() != 0) {
            $('#toTop').fadeIn();
        } else {
            $('#toTop').fadeOut();
        }
    });
    $('#toTop').click(function () {
        $('body,html').animate({
            scrollTop: 0
        },
        800);
    });
});

// Categories Sidebar Ease
jQuery(document).ready(function(){
jQuery(".inner li a").bind("mouseenter",function(){ 
          jQuery(this).stop().animate({backgroundColor: "#ffffff", paddingLeft:25 }, 400, "swing");
          jQuery(this).children('.count').fadeIn(); 
        }).bind("mouseleave",function(){
            jQuery(this).stop().animate({backgroundColor: "#ffffff", paddingLeft:15 }, 600, "swing");
            jQuery(this).children('.count').fadeOut();
       });
 });

// Login
$(document).ready(function() {
    $("li.sign-in a").click(function(e) {          
		e.preventDefault();
        $("fieldset#signin_menu").toggle();
		$("li.sign-in a").toggleClass("menu-open");
    });
	
	$("fieldset#signin_menu").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {
		if($(e.target).parent("li.sign-in a").length==0) {
			$("li.sign-in a").removeClass("menu-open");
			$("fieldset#signin_menu").hide();
		}
	});			
});

// Input
(function ($) {
  styleSelect = {
    init: function () {
      $('.styled-select').each(function () {
        $(this).prepend('<span>' + $(this).find('.gfield_select option:selected').text() + '</span>');
      });
      $('select.gfield_select').live('change', function () {
        $(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>');
      });
      $('select.gfield_select').bind($.browser.msie ? 'click' : 'change', function(event) {
        $(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>');
      }); 
    }
  };
})(jQuery);

jQuery(document).ready(function() { 
styleSelect.init();
});

