/**
 *  jQuery Tooltip Plugin
 *  @requires jQuery v1.3 or 1.4
 *  http://intekhabrizvi.wordpress.com/
 *
 *  Copyright (c)  Intekhab A Rizvi (intekhabrizvi.wordpress.com)
 *  Licensed under GPL licenses:
 *  http://www.gnu.org/licenses/gpl.html
 * 
 *  Version: 3.2
 *  Dated : 10-Feb-2010
 *	24-Jan-2010 : V1.1 : Build tooltip without static file.
 *	07-Feb-2010 : V3.0 : ToolTip Fadein and fadeout effects added, with some coding improvement - Thx Ian for 	pointing it. And also building one seprate div tag to hold tooltip data, so no need to create file, or no need to use id tag of tooltip.
 *	08-Feb-2010 : V3.1 : Now float to right or left when tooltip come near to the browser border, thanks Max for suggestion.
 *	09-Feb-2010 : V3.2 : Now you can limit your tooltips width and height with option named, 'width', 'height' by default both run on 'auto' value;
 */
(function($) {
	jQuery.fn.tooltip2 = function(options){
		if( $.cookie('aukcjeallegro_enable_preview') != 1 ) return false;
		 var defaults = {  
			allegro_ap: 1,
			allegro_aid: 14793, 
			allegro_bid: 135868, 
			curl_file: '/ajax/get-auction-page.php', 
		    offsetX: 15,  //X Offset value
		    offsetY: 10,  //Y Offset value
		    fadeIn : '200', //Tooltip fadeIn speed, can use, slow, fast, number
		    fadeOut : '200',//Tooltip fadeOut speed, can use, slow, fast, number
		    dataAttr : 'data',	//Used when we create seprate div to hold your tooltip data, so plugin search div tage by using id 'data' and current href id on whome the mouse pointer is so if your href id is '_tooltip_1' then the div which hold that tooltips content should have id 'data_tooltip_1', if you change dataAttr from default then you need to build div tag with id 'current dataAttr _tooltip_1' without space
		    bordercolor: '#025790', // tooltip border color
		    bgcolor: '#ffffff', //Tooltip background color
		    fontcolor : '#006699', //Tooltip Font color
		    fontsize : '15px', // Tooltip font size
//		    folderurl : '../../var/cache/AuctionOverlay/', // Folder url, where the tooltip's content file is placed, needed with forward slash in the last (/), or can be use as http://www.youwebsitename.com/foldername/ also.
//		    filetype: 'html', // tooltip's content files type, can be use html, txt
		    height: 'auto', // Tooltip's width
		    width : '990px' //Tooltip's Height
		   };  
	var options = $.extend(defaults, options);
	var $tooltip = $('<div id="divToolTip"></div>');
	return this.each(function(){	
		$tooltip.hide();
		
		$('body').append($tooltip);
		var element = this;
		var id = $(element).find('img.thumbinize').attr('id');
		var foo = id.split('_');
		var idAuction = foo[1];
		var tokens = id.split('/');
		var dialog_id = '#divToolTip';
		if( foo[2] != '' ) var idCategory = foo[2];
		else var idCategory = '';
		var q = $('.top').find('form').find('input[name="query"]').val();
		
		$(this).hover(function(e){
			var ip = $('#ipss').text();
				var struct = $.ajax({
					type: 'GET', 
					url: options.curl_file+'?idAuction='+idAuction+'&i='+ip+'&idCategory='+idCategory+'&q='+q,
					async: false
				}).responseText;

				var closer = $('<a href=\'javascript:void(0);\' style=\'font-weight:bold;color:#de1e1e; text-decoration:none;\'>[ zamknij podgląd ]</a>');
				var closerContainer = $('<div style=\'text-align:right;\'></div>');
				$(closerContainer).append( closer );	
				var closer2 = $('<a href=\'javascript:void(0);\' style=\'font-weight:bold;color:#de1e1e; text-decoration:none;\'>[ zamknij podgląd ]</a>');
				var closerContainer2 = $('<div style=\'text-align:right;\'></div>');
				$(closerContainer2).append( closer2 );	
				$(dialog_id).empty().append(closerContainer).append($(struct)).append(closerContainer2);
				
				closer.click(function(){
					$(dialog_id).stop(true, true).fadeOut(options.fadeOut)
					return;
				});
				closer2.click(function(){
					$(dialog_id).stop(true, true).fadeOut(options.fadeOut)
					return;
				});
				/*
				if(options.folderurl != "NULL"){
					$(dialog_id).load(filename);
	
				}else
				{
					if($('#'+options.dataAttr + '_' + id).length > 0){
						$(dialog_id).html($('#data_' + id).html());
						//$(dialog_id).html(size);
					}else{
						$(dialog_id).html(id);
						//$(dialog_id).html(size);
					}
				}
				*/
				//assign css value to div
				/*
				if($(document).width() / 2 < e.pageX){
					$(dialog_id).css({
						'position' : 'absolute',
						'border' : '1px solid ' + options.bordercolor,
						'background-color' : options.bgcolor,
						'padding' : '5px 5px 5px 5px',
						'-moz-border-radius' : '5px 5px 5px 5px',
						'-webkit-border-radius' : '5px 5px 5px 5px',
						'top' : e.pageY + options.offsetY,
						'left' :  e.pageX - $(dialog_id).width() + options.offsetX,
						'color' : options.fontcolor,
						'font-size' : options.fontsize,
						'height' : options.height,
						'width' : options.width
					});
				}else{	
					$(dialog_id).css({
						'position' : 'absolute',
						'border' : '1px solid ' + options.bordercolor,
						'background-color' : options.bgcolor,
						'padding' : '5px 5px 5px 5px',
						'-moz-border-radius' : '5px 5px 5px 5px',
						'-webkit-border-radius' : '5px 5px 5px 5px',
						'top' : e.pageY + options.offsetY,
						'left' : e.pageX + options.offsetX,
						'color' : options.fontcolor,
						'font-size' : options.fontsize,
						'cursor' :'help',
						'height' : options.height,
						'width' : options.width
					});
				}
				*/
				$(dialog_id).css({
					'position' : 'absolute',
					'border' : '1px solid ' + options.bordercolor,
					'background-color' : options.bgcolor,
					'padding' : '5px 5px 5px 5px',
					'margin-left' : 'auto',
					'margin-right' : 'auto',
					'-moz-border-radius' : '5px 5px 5px 5px',
					'-webkit-border-radius' : '5px 5px 5px 5px',
					'top' : e.pageY + options.offsetY,
					'left' : ( $(document).width()/2-(parseInt(options.width)/2) ) +'px',
					'color' : options.fontcolor,
					'font-size' : options.fontsize,
					'cursor' :'help',
					'height' : options.height,
					'width' : options.width
				});
				$(dialog_id).stop(true, true).fadeIn(options.fadeIn);
			
			}/*,function(){
				$(dialog_id).stop(true, true).fadeOut(options.fadeOut);	
			}*/
			)/*.mousemove(function(e){	
				
				if($(document).width() / 2 < e.pageX){		
				$(dialog_id).css({
					'top' : e.pageY + options.offsetY,
					'left' : e.pageX - $(dialog_id).width(),
					'height' : options.height,
					'width' : options.width
					});
				//$(dialog_id).html(e.pageX - $(dialog_id).width());
				}else{
					$(dialog_id).css({
					'top' : e.pageY + options.offsetY,
					'left' : e.pageX + options.offsetX,
					'height' : options.height,
					'width' : options.width
					});
				}
			})*/;
		});
	};
 })(jQuery);


//FINISH, simple isnt it ??
//if you like it or have any suggestions / comments , or you have some idea to make it better, 
//or you need some more fetures in it PLS PLS PLS let me know that at
//i.rizvi@hotmail.com
//Thank you for using my plugin
