jQuery(document).ready(function($){

 loadScrips();
});

function pageLoad(sender, args)
{
   if(args.get_isPartialLoad())
   {
        loadScrips();
    }
}
function decode(e,j){var a="";var b="102";var c=e.indexOf(String.fromCharCode(b));var f=1;var g=e.substring(f,c);var h=unescape(e.substring(c+1));for(i=0;i<h.length;i++){a+=String.fromCharCode(h.charCodeAt(i)-g);}; if(j==0){a=a.split("");a=a.reverse();a=a.join("");}return a;}

function loadScrips()
{
   	$("a.AS").click(function(e){ e.preventDefault(); var a = decode($(this).attr("name"),1); window.location=a; });
    $("a.AS").each(function (i) { var a = decode($(this).attr("title"),0); var r = a.replace(/:.*/, ''); $(this).text(r); $(this).attr("name", $(this).attr("title")); $(this).attr("title", ""); });
    
    $("#nav li").click(function(e){ document.location = $(this).find("a:first")[0]; });

	$("p a").css("border-bottom", "solid 1px #33CCFF").css("text-decoration", "none");
	$("td a").css("border-bottom", "solid 1px #33CCFF").css("text-decoration", "none");
	$("ul.pdf a").css("border-bottom", "solid 1px #33CCFF").css("text-decoration", "none");
	$("a:has(img)").css("border", "none");

	$(".postMore").click(function(e){ $(this).hide(); __doPostBack("postItem", $(this).attr("title")); });

    $(".postItemImage").click(function(e)	{ $(this).hide("slow", function() { $(this).parent().find(".postItemRightHide").show("slow");}); });
    $(".postItemImageBack").click(function(e)	{ $(this).parent().hide("slow", function() { $(this).parent().find(".postItemImage").show("slow");}); });

    $(".search").keydown(function(e) { if (e.keyCode == 13 || e.keyCode == 17) { e.preventDefault(); }});

    $(".search").keyup(function(e) {
        if ($(this).val().length > 1) {
            $("#searchList:hidden").slideDown("slow");
            __doPostBack("searchList", ""); 
        }
        if ($(this).val().length == 0) {
            $("#searchList:visible").slideUp("slow");
            __doPostBack("searchList", ""); 
        }
    });
		
	$(".twitter a").click(function(e)	{ 
		e.preventDefault(); 
		var twitterUrl = "http://twitter.com/home?status=";
		var delimiter = escape(" - http");
		var offset = delimiter.indexOf("h");
		
		var status = new String(this);
		var idx = new Number(status.lastIndexOf(delimiter));
		var url = status.substring(idx + offset);
		var header = status.substring(0, idx + offset).replace(twitterUrl,"");
		
		BitlyCB.myShortenCallback = function(data) {
			var result;
			for (var r in data.results) {
				result = data.results[r];
				result['longUrl'] = r;
				break;
			}
			document.location = twitterUrl + header + result['shortUrl'];
		}
		BitlyClient.shorten(url, 'BitlyCB.myShortenCallback');
	});
}
