$(document).ready(function(){
	$('#portfolio-showcase').innerfade({
		speed: 1500,
		timeout: 5000,
		type: 'sequence',
		containerheight: '196px'
	});

	$('.expanding').autogrow({
		maxHeight: 200,
		minHeight: 80,
		lineHeight: 23
	});

	$('a.anchorLink').click(function(){
		elementClick	= $(this).attr('href')
		destination		= $(elementClick).offset().top;
		$('html:not(:animated),body:not(:animated)').animate({ scrollTop: destination}, 1500 );
		return false;
	})

	//	Open external links in new window. because target=_blank is not xhtml
	$('a[rel="external"]').each(function(){
		$(this).attr('target','_blank');
	});

	//	Add a favicon near external links with jQuery
	$.fn.addFavicon	= function(faviconURL){
		this.css({
			background: 'url('+faviconURL+') no-repeat center left',
/*
			backgroundUrl: 'url('+faviconURL+')',
			backgroundRepeat: 'no-repeat',
			backgroundSize: '16px',
			backgroundPosition: 'center left',
*/
			paddingLeft: '18px'
		});
		this.css('background-size','16px');
	};

	//	Add shadow div
	$.fn.addShadow	= function(options){
		var	$shadow	= $('<div class="shadow"></div>');
		if (!options.width){
			options.width	= $(this).width() + parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right'));
		}
		if (!options.height){
			options.height	= $(this).height() + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom'));
		}
		$shadow.css({
			width: parseInt(options.width)+'px',
			height: parseInt(options.height)+'px',
			left: options.left,
			top: options.top
		});
		$(this).after($shadow);
	};

	//	<span class="mailme" title="Send me a letter!">me at mydomain dot com</span>
	jQuery.fn.mailme = function() {
		var at = / at /;
		var dot = / dot /g;
		this.each( function() {
			var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
			var title = jQuery(this).attr('title')
			$(this)
				.after('<a href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
				.remove();
		});
	};
	$('span.mailme').mailme();

	$('a[href^="http://"]').filter(function(){
		var	dontshow	= (this.rel && this.rel=='nofavicon') || this.favicon;
		return	!dontshow && this.hostname && this.hostname !== location.hostname;
	}).each(function() {
		var link = jQuery(this);
		var faviconURL = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/favicon.ico';
		var extImg = new Image();
		extImg.src = faviconURL;
		if (extImg.complete){
			link.addFavicon(faviconURL);
		} else {
			extImg.onload = function() {
				link.addFavicon(faviconURL);
			};
		}
	});

	$('a[favicon]').each(function(){
		$(this).addFavicon($(this).attr('favicon'));
	});

	$('#sidebar').addShadow({ top: '143px', left: '636px' });

	$('#addtofavorities').click(function(){
		try {
			if (document.all){
				window.external.AddFavorite(location.href, document.title);	//	IE
			} else if (window.sidebar) {
				window.sidebar.addPanel(document.title, location.href, '');	//	FF
			}
		} catch(e) {};
		return false
	});

	/*
	//	Customizing menu
	$('#navigation li.cat-item-4').remove();
	$('#navigation li.cat-item-1').insertAfter('#navigation li.page-item-11');
	$('#navigation li.cat-item-3').insertAfter('#navigation li.page-item-11');

	//	Upgrade menu with slashes
	var	menu_length	= $('#navigation li').length;
	$('#navigation li').each(function(){
		$(this).after('<li class="trenner">/</li>');
	});
	$('#navigation li:last').remove();
	*/
});
