(function($) {
	
	$.fn.fancyHover = function(options){
		
			$.fn.fancyHover.defaults = {
				contentElement: 'p',
				content : 'true',
				extend : 1.5,
				direction : 'vertical'
			};
			
			var opts = $.extend({}, $.fn.fancyHover.defaults, options);
			
			var direction = opts.direction;
			var extend = opts.extend;
			var contentElement = opts.contentElement;
			var content = opts.content;
			
			if(!$(this).hasClass('fancythumb')){
				$(this).addClass('fancythumb');
			}
			
			if(content == 'true'){
				
				var cssContent = {
					position : 'relative',
					display : 'none',
					fontSize : '14px',
					textAlign: 'center'
				};
				
				
				$(this).find(contentElement).each(function(){
					$(this).css(cssContent);
				});
			}
			
			$(this).children('li').each(function(){
				
				var cssArray;
				
				$(this).hoverIntent({
						over : function(){
							
							
							var div = $(this).children('div');
							
							$(div).siblings('span').css('display' , 'none');
							
							$(div).addClass('c_o');
							
							var position = $(this).position();
							var left = position.left,
								top = position.top,
								right,
								bottom;
								
							right = $('.fancythumb').width() - left;
							bottom = $('.fancythumb').height() - top;
						
							var set = $(div).find('img').add(div);
							cssArray = new Array();
							$(set).each(function(index){
								
								cssArray[index] = new Array();
								cssArray[index]['width'] = $(this).css('width');
								cssArray[index]['height'] = $(this).css('height');
								cssArray[index]['padding'] = $(this).css('padding');
								
								var v_top = 0;
								var v_left = 0;
								
								var extend_w = $(this).width() * extend;
								var extend_h = $(this).height() * extend;
								
								v_left = ($(this).parent('div').width()*extend * 1.2 - extend_w)/2;
								
								if($(this).hasClass('c_o')){ 
									
									extend_h = (( $(this).height() * extend )) * 1.2;
									extend_w = extend_w * 1.2;
									
									v_top =   -((extend_h + 10) - $(this).height()) / 2;
									v_left =  -((extend_w + 10) - $(this).width()) / 2;	
									
									if(top < -v_top){
										v_top = -top * 2;
									}
									
									
									if(left < -v_left){
										v_left = -left * 3;
									}
									
									if(bottom - $(this).height() < -v_top){
										v_top = v_top + (v_top + (bottom - $(this).height()));
									}
									
									
									if(right -$(this).width() < -v_left ){
										v_left = v_left - (right - $(this).width());			
								
									}
								}
								
								$(this).css({'z-index' : '10'}).stop().
									animate({
										top: v_top + 'px',
										left: v_left + 'px',
										width: extend_w + 'px',
										height: extend_h + 'px',
										padding: '10px'
									}, 100 , function(){
										if($(this).hasClass('c_o')){
											
											$(this).find(contentElement).each(function(){
												$(this).css({
													top : 183 + 'px',
													display : 'block'
												});				
											});
										}
										
									}); 					
							});
							
							
							
							
						},
						out : function(){
							var div = $(this).children('div');
							$(div).siblings('span').css('display' , 'block');
							$(this).find('p').each(function(){
								$(this).css({
									display : 'none'
								});
							});
							
							var set = $(div).children('img').add(div);
							
							$(set).each(function(index){
								
								var ll = 0;
								var tt = 0;
								if(index == 1){
									ll = '5px';
								}
								
								var narrow_w = $(this).width() / 2;
								var narrow_h = $(this).height() / 2;
								
								$(this).css({
									'z-index' : '0'
								}).stop()  
									.animate({
										top: tt,
										left: ll,
										width:   cssArray[index]['width'], 
										height:  cssArray[index]['height'],
										padding: '5px'
									}, 0);
							});
							
							$(div).removeClass('c_o');
							
						},
						interval : 10,
						timeout : 0
				});
			
			});
	};

})(jQuery);
