var LikeTool = (function(){
	function constructor(){
		this.count = 0;
		//this.countURL = "http://webwas6stage.baxter.com/galaxy/likeThis.jspa";//staging URL
		//this.countURL = "http://www.cosmod.com/LikeThis.php";//temporary URL
		this.countURL = "https://webforms.baxterbioscience.com/galaxy/likeThis.jspa";
		//this.incrementURL = "http://webwas6stage.baxter.com/galaxy/likeThisToo.jspa";//staging URL
		this.incrementURL = "https://webforms.baxterbioscience.com/galaxy/likeThisToo.jspa";//staging URL
		this.category = "patient";
		
		var crumb = document.documentElement.lastChild.className.split(" ");
		if(/-story$|site-map|tertiary|^home$/.test(crumb[crumb.length-1])){crumb.pop();}
		this.label = crumb[crumb.length-1];
		
		if($('meta[name="page"]').length){
			this.id = $('meta[name="page"]').attr("content");
		} else {
			return;
		}
		
		if($('meta[name="label"]').length){
			this.label = $('meta[name="label"]').attr("content");
		}
		
		$("#like-tool span").hide();
		
		$("#like-tool a").click((function(e){return function(data){
			e.category = $(this).attr('class'); 
							
			e.setCount(e.count+1);
			$.getJSON(e.incrementURL+"?id="+e.id+"&label="+e.label+"&category="+e.category+"&callback=?",function(e){/*alert('success');*/});
			$(this).unbind('click');
			
			//set cookie to prevent ballot stuffing? not that it matters much...
			
			//track this event in webtrends
			if('dcsMultiTrack' in window){
				dcsMultiTrack('DCS.dcssip',document.location.hostname,'DCS.dcsuri',document.location.pathname,'DCS.dcsqry',"?id="+e.id+"&label="+e.label+"&category="+e.category+"&callback=?",'WT.ti',"I did too",'WT.dl','26');
			}
			
			$("#like-tool").unbind("mouseenter mouseleave");
			$("#like-tool ul").removeClass('hover');
			$("#like-tool span").fadeOut(300);
			return false;
		}})(this));
		this.getCount();
	}
	constructor.prototype.getCount = function(){
		$.getJSON(this.countURL+"?id="+this.id+"&label="+this.label+"&callback=?",(function(e){return function(data){e.setCount(data);}})(this));
	}
	constructor.prototype.setCount = function(num){
		this.count = num;
		$("#like-tool span").show();
		
		if($('meta[name="lang"][content="es"]').length > 0){
			$("#like-tool p").text("A "+this.count+ " personas les gusta esto");
		} else {
			$("#like-tool p").text(this.count+ " people recommended this page");
		}
		if(!/MSIE 6|MSIE 7/.test(navigator.userAgent)){
			$('#like-tool ul').css("margin-left",Math.round($('#like-tool span').position().left+5)+"px");
		} else {
				
		}
		$("#like-tool").bind("mouseenter mouseleave",function(){	
			$(this).parent().find('ul').toggleClass('hover');
		});
		
		
	}
	return constructor;
})();
