// JavaScript Document

PLIKE = {
	buttonimg : "http://penest.no/js/widget/like_this.png",
	url : "http://penest.no/js/widget/request.php",
	init : function(){
		document.write('<div onmouseover="document.getElementById(\'penestlikebutton\').style.backgroundPosition=\'-137px\'"  onmouseout="document.getElementById(\'penestlikebutton\').style.backgroundPosition=\'0px\'" id="penestlikebutton" onclick="jsonp(\''+this.url+'\',\'callbackname\',\'id='+this.id+'&key='+this.key+'&f='+encodeURIComponent(window.location.href)+'&update='+this.update+'\');" style="background:url('+this.buttonimg+');cursor:pointer;height:58px;width:136px;padding:0px;margin:0px;">');
		document.write('</div>');
		document.write('<div id="penest_response"></div>');
		//document.write('<form method="get" action="" target="_blank" id="penestopen" name="penestopen"><input type="hidden" name="no" value="block"></form>');
		document.write('');
		
		}
};

function callbackname(r){
	
	
	if (r.message){
		
		document.getElementById('penest_response').innerHTML=r.message;
	
	}else{
		//fireføx fix for history entry
		window.location.replace(window.location.href);
		document.write('Loading..');
		// redirect
		window.location.href=r.url;
	}
	
}

function jsonp(url, name, query){                
	if (url.indexOf("?") > -1)
		url += "&jsonp=" 
	else
		url += "?jsonp=" 
	url += name + "&";
	if (query)
		url += query + "&";   
	url += new Date().getTime().toString(); // prevent caching        
	
	var script = document.createElement("script");        
	script.setAttribute("src",url);
	script.setAttribute("type","text/javascript");                
	document.body.appendChild(script);
}
