//-------------------------------- start urlencode ----------------------------------------

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});

//-------------------------------- end urlencode ------------------------------------------

// --------------------------------- start screenshot ---------------------------------------
/*
 * Url preview script 
 * written by Alen Grakalic (http://cssglobe.com)
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */
this.screenshotPreview = function(){	
		
		var xOffsetL = 30;
		var xOffsetR = -225
		var yOffsetT = 25;
		var yOffsetB = 120;
		var xOffset, yOffset;
		
	$("a.screenshot").hover(function(e){
		if(e.pageX > screen.width/2)
			xOffset = xOffsetR;
		else
			xOffset = xOffsetL;
		if(e.pageY > screen.width/2)
			yOffset = yOffsetB;
		else
			yOffset = yOffsetT;	

		this.t = this.title;
		this.title = "";
		var c = (this.t != "") ? this.t : "";
		
		var tImg = this.rel;
		//$.ajax({
			//url: 'thumb.php?j='+tImg,
			//async: false
		//});
		var preImg = new Image();
		preImg.src = '/images/thumbs/'+tImg;
		preImg.align = "left";
		$("body").append("<p id='screenshot'>" + c + "</p>");
		$("body p#screenshot").prepend(preImg);

		$("#screenshot")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn(800);
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){

		$("#screenshot")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});
};
// --------------------------------- end screenshot ---------------------------------------

var title = $.URLEncode($('title').text());
var url = $.URLEncode(window.location);

$(document).ready(function(){

	//------------------------------ start social junk ----------------------------------------
	$('a[rel=twitter]').attr('href', 'http://twitter.com/share?url='+url+'&text='+title);
	$('a[rel=facebook]').attr('href', 'http://www.facebook.com/sharer.php?u='+url+'&t='+title);
	$('a[rel=digg]').attr('href', 'http://digg.com/submit?url='+url+'&bodytext='+title);
	//------------------------------ end social junk -------------------------------------------

	screenshotPreview();
});

// --------------------------------- for tweet display ---------------------------------------
getTwitters('thenews', {
        id: 'publicdomainflx',
        timeout: 2,
        onTimeout: function () {
            this.innerHTML = '<a href="http://twitter.com/publicdomainflx">Follow me on Twitter here!</a>';
        },
        onTimeoutCancel: true, // don't allow twitter to finsih the job
        clearContents: false, // leave the original message in place
        count: 5, 
        withFriends: false,
        ignoreReplies: true,
        newwindow: true
});

