
var scaleHover = function() {
	var items	= $('#socialmedia li');
	
	$.each(items,function(i){
		var el			= $(this),
			anchor 		= $('a',el),
			bg			= el.css('background-image').replace(/url\(|\)/gi,'').replace('small','large').replace(/"/gi,''),
			startWidth	= el.width(),
			startHeight	= el.height(),
			endWidth	= 70,
			endHeight	= 70,
			text		= anchor.text();
		
		// prepare and change html
		anchor.text('');
		$('<span>'+text+'</span>').appendTo(el).fadeTo(0,0).css({marginTop: 55});

		// append image
		$('<img />')
		.fadeTo(0,0)
		.attr('src',bg)
		.css({
			height: startWidth,
			width: startHeight
		})
		.appendTo(anchor);
		
		// add listener to anchors
		el.bind('mouseenter mouseleave',function(e) {
			var eventType = e.type;
			switch(eventType) {
				// over
				case 'mouseenter':
					$('img',this).stop().animate({
						opacity: 1,
						height: endWidth,
						width: endHeight,
						marginLeft: - ( endWidth - startWidth ) / 2,
						marginTop: - ( endHeight - startHeight ) / 2
					} , 300 , 'easeOutExpo' );
					$('span',this).stop().animate({
						opacity: 1,
						marginTop: 70
					} , 300);
				break;
				// out
				case 'mouseleave':
					$('img',this).stop().animate({
						opacity: 0,
						height: startWidth,
						width: startHeight,
						marginLeft: 0,
						marginTop: 0
					} , 300 , 'linear' );
					$('span',this).stop().animate({
						opacity: 0,
						marginTop: 55
					} , 300);
				break;
			}	
		});
	});
}


$(document).ready(function(){
	scaleHover();
	
});
