/* ==UserScript==
   @name           Photobucket Direct Photo Link
   @description    Adds a direct link to original photo in album thumbnail view.
   @include        http://*.photobucket.com/*
   @include        http://photobucket.com/*
   ==/UserScript==
  
   Done By: Samuel Liew [http://www.samliew.com]
   Version: 1.0
   Last Modified: 10/11/2007
  
*/


// Routine, declare variables
//alert("Script started");
var errorMsg = "";
var num = 0, num1 = 0, name="";

// Get elements with classname 'panelCode'
name = "panelCode";
var e1 = new Array();
alltags=document.all? document.all : document.getElementsByTagName("*");
for (i=0; i<alltags.length; i++) { if (alltags[i].className==name) num1++; }
for (i=alltags.length; i>0; i--) {
	try { if (alltags[i].className==name) { e1.push(alltags[i]); }} catch(e){errorMsg+="1:"+e+" i="+i+"\n";continue;}
}

// Get elements with classname 'txtCode'
name = "txtCode";
var e2 = new Array();
alltags=document.all? document.all : document.getElementsByTagName("*");
for (i=0; i<alltags.length; i++) { if (alltags[i].className==name) num1++; }
for (i=alltags.length; i>0; i--) {
	try { if (alltags[i].className==name) { e2.push(alltags[i].value); }} catch(e){errorMsg+="2:"+e+" i="+i+"\n";continue;}
}

// Replace URL with direct link to image
for(i=0;i<e1.length;i++) {
try {
	var j=e2[i].length, temp="";
	do {
		if(e2[i].charAt(j)=="?"||e2[i].charAt(j)=="&"||e2[i].charAt(j)=="=") e2[i] = e2[i].substring(0,j) + e2[i].substring(j+1,e2[i].length);
	} while(j-->0);
	e2[i] = e2[i].replace(/actionviewcurrent/i,"");

	var href = "<a href='"+e2[i]+"' target='_blank'>View Original</a>";
	e1[i].innerHTML = href;
} catch(e){errorMsg+="3:"+e+" i="+i+"\n";}
}

// Routine, end code
//if(errorMsg!="") { alert(errorMsg); } // for debugging
//alert("Script end");