jQuery.fn.ImageAutoSize = function(width) {
    $("img",this).each(function()
    {
        var image = $(this);
        if(image.width()>width)
        {
            image.width(width);
            image.height(width/image.width()*image.height());
        }
    });
}
jQuery(document).ready(function(){
	/* Topnav Dropdown menu.	*/
	$('#topnav ul li').each(function(){
		if($(this).children('ul').length > 0) {
			$(this).addClass('withul');
			$(this).children('a').addClass('withula');
		
			$(this).hover(function(){
				$(this).addClass('withul-hover');
				$(this).children('ul').slideDown(200);
			},function(){
				$(this).removeClass('withul-hover');
				$(this).children('ul').slideUp(100);	
			});
		}
	});
	
	/* Slide Category Select */
	$('#category-select').each(function(){
		$(this).hover(function(){
			$('#category-dropdown:hidden').slideDown(200);
		},function(){
			$('#category-dropdown:visible').slideUp(100);	
		});
	});
	$('#category-select-toggle').click(function(){
		return false;
	});
	
	$('#category-select ul li a').wrapInner('<span>');
	
	$('.widget ul ul li:last-child').css({'border-bottom':0,'padding-bottom':0});
	
	jQuery("a[class^='fancybox']").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000000',
		'zoomSpeedIn'		:	500,
		'zoomSpeedOut'		:	500
	});
	var $portfolioItem = jQuery('.item');
	$portfolioItem.find('.item-image').css('background-color','#000000');
	jQuery('.zoom-icon, .more-icon').css('opacity','0');
	
	$portfolioItem.hover(function(){
		jQuery(this).find('.item-image').stop(true, true).animate({top: -10}, 500).find('img.portfolio').stop(true, true).animate({opacity: 0.7},500);
		jQuery(this).find('.zoom-icon').stop(true, true).animate({opacity: 1, left: 23},400);
	}, function(){
		jQuery(this).find('.zoom-icon').stop(true, true).animate({opacity: 0, left: 10},400);
		jQuery(this).find('.item-image').stop(true, true).animate({top: 0}, 500).find('img.portfolio').stop(true, true).animate({opacity: 1},500);
	});

});
