this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};



// open blured window
this.newWindow = function(){	
	 var link = $(this).attr('href');
	 var mer_window = window.open(link, '_blank','toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,menubar=1');

	 if (typeof mer_window === "object")
	{
		  mer_window.blur();
	}
				
};


// pop
this.popUp = function(){	

	//$('.overlay').css('height', window.height());
	$('.overlay').css('position', 'fixed');
	$('.overlay').show();
	$('.popup').show();
	return(false);
				
};

// pop close
this.popClose = function(){	

	$('.overlay').hide();
	$('.popup').hide();
	return(false);
				
};



$(document).ready(function() {
	
		// blank 
		
		$('.new-window').attr('target', '_blank');
		$('a[rel~="external"]').attr('target', '_blank');
		
		// image opacity over
		
		$('#pr_content a').hover(
			function() {
				$(this).children('img').animate({ opacity: "0.8" }, "fast");
			},	
			function() {
				$(this).children('img').animate({ opacity: "1" }, "slow");
			}
		);
				 
		//
		tooltip();
		
		//deactivate link
		
		$('a.deactive').click(function(){
			return false;			
		});
		
		// Fitme

		$.each($("#home_page .small_logos_homepage a img"), function(index, element){$(this).fitme();});
		
		//Search autocomplete
		
		$('#search-bar-input').autocomplete("/media/js/shops.js.php?action=load_shops&callback=?", 
	  		{
	  			multiple : false,
	  			dataType : "json",
	  			scroll	 : false,
	  			width	 : 384,
	  			scrollHeight: 200,
	  			max		 : 3,
	  			parse : function(data) {
	  				return $.map(data, function(row) {
	  					return {
	  						data : row,
	  						value : row.Shop_id,
	  						result : row.Shop_name
	  					};
	  				});
	  			},
	  			formatItem: function(row, i, max) {
	  				return '<div class="item-image ac_item-image"><img src="' + row.Logo + '" onload="$(this).fitme()" style="visibility:hidden" /></div>' + '<div class="item-data">' + row.Shop_name + row.offers + '</div>';
				},
				formatMatch: function(row, i, max) {
					return row.Shop_name;
				}, 
				formatResult: function(row) {
					return row.Shop_name;
				}
	  		}
		).result(function(event, data, formatted) {
			location.href = data.Url;
		});
		
		//Addthis
		var addthis_config = {
				"data_track_clickback":true
		};
});
