﻿/*
 * Bubbleup - Spicing up menu jQuery plugin
 *
 * Tranform the images inside the list items like Mac Dock effect
 *
 * Homepage: http://aext.net/2010/04/bubbleup-jquery-plugin/
 *
 * Copryright? I don't have any!
 *
 * First written by Lam Nguyen (yah, it's me)
 * Written again by Jonathan Uhlmann http://jonnitto.ch
 * Thanks to Icehawg (Hey, I don't know anything from him, just a name http://aext.net/2010/02/learn-jquery-first-jquery-plugin-bubbleup/#comment-6777)
 *
 */


(function($){
	$.fn.bubbleup = function(settings){
		settings=$.extend({
			tooltip: false,//鏄惁鎻愮ず鏂囨湰
			scale:120,//鏀惧ぇ鍚庣殑鍥剧墖瀹藉害
			fontFamily:'Helvetica, Arial, sans-serif',//鎻愮ず鏂囨湰瀛椾綋
			color:'#333333',//鎻愮ず鏂囨湰瀛椾綋棰滆壊
			fontSize:12,//鎻愮ず鏂囨湰瀛椾綋澶у皬
			fontWeight:'bold',//鎻愮ず鏂囨湰瀛椾綋绮楃粏
			inSpeed:'fast',//榧犳爣鍒掕繃鏀惧ぇ鏃剁殑閫熷害
			outSpeed:'fast'//榧犳爣宸插嚭缂╁皬鏃舵椂鐨勯€熷害
			},settings);
			return this.each(function(){
				$.fn.bubbleup.runing( $( this ), settings );
			})
	};
	$.fn.bubbleup.runing=function($this,settings){
		var smallImgW=$this.width();
                var smallImgH=$this.height();
		$this.mouseover(function(){
			if (settings.tooltip) {
                                $this.parent().parent().parent().css({'z-index':99});
				tip=$('<div>' + $(this).attr('alt') + '</div>').css({
					fontFamily: settings.fontFamily,
					color: settings.color, 
					fontSize: settings.fontSize, 
					fontWeight: settings.fontWeight, 
					position: 'absolute', 
					zIndex: 100000
				}).remove().css({top:0,left: 0,visibility:'hidden',display:'block'}).appendTo(document.body);
				var position=$.extend({},$this.offset(),{width:this.offsetWidth,height:this.offsetHeight});
				var tipWidth = tip[0].offsetWidth;
				var tipHeight = tip[0].offsetHeight;
				tip.stop().css({
						top: position.top - tipHeight, 
						left: position.left + position.width / 2 - tipWidth / 2,
						visibility: 'visible'
					}).animate({top:'-='+(settings.scale/2-smallImgW/2)},settings.inSpeed); 
			}
			$this.closest('li').css({'z-index':100000});
			$this.stop().css({'z-index':100000,'top':0,'left':0,'width':smallImgW}).animate({
				left:-settings.scale/2+smallImgW/2,
				top:-settings.scale/2+smallImgW/2,
				width:settings.scale,
                                height:settings.scale*smallImgH/smallImgW
			},settings.inSpeed)
		}).mouseout(function(){
			$this.closest('li').css({'z-index':100});
			$this.closest('li').next().css({'z-index':0});
			$this.closest('li').next().css({'z-index':0});
			$this.closest('li').next().children('img').css({'z-index':0});
			if(settings.tooltip){tip.remove()}
			$this.stop().animate({left:0,top:0,width:smallImgW,height:smallImgH},settings.outSpeed,function(){
				$this.css({'z-index':0});
                                $this.parent().parent().parent().css({'z-index':51});
			});
		});
		
	}
})(jQuery);
