function unhack(munged_url) {
  var unhackd_url = munged_url.replace(/\|/g, '/').replace(/~/g, '.');
  return unhackd_url;
}


$('.splink[rel]').click(function(e){
  var unhackd_url = unhack($(this).attr('rel'));
  if ($(this).hasClass('outward')) {
    var newWin = window.open(unhackd_url, '_blank');
    newWin.focus();
  } else if($(this).hasClass('flick_out')) {
    var newWin = window.open("http://www.flickr.com/" + unhackd_url, '_blank');
    newWin.focus();
  } else {
    document.location.href = unhackd_url;
  }
});



function toggle_tab(root,index)
{
	var child;
	var node = document.getElementById(root);
	var children = node.childNodes;
	var counter = 0;
	
	for(var i = 0; i < children.length; i++)
	{
		child = children[i];
		
		if (child.style == null){
		    continue;
		}

		if (counter != index-1){
		    child.style.display = "none";
		    counter++;
		}else{
		    child.style.display = "block";
		    counter++
		}
	}
}



function change_image(src,title,ownername,owner,photonum,elem) { 
	document.getElementById("flickr_photo_showing").innerHTML = "<div style=margin-top:5px><span class=photo_title>" + unescape(title) + "</span></div><div style=clear:both;></div><div><img src=" + src + " onload='ck_img_size(this,true)' onabort='ck_img_size(this,false)'></div><span class=photo_author>Photo by <span onClick=window.open('http://www.flickr.com/photos/" + owner + "/" + photonum + "') style=cursor:pointer;>" + unescape(ownername) + "</span>"; 

	var rows = document.getElementById('haha').getElementsByTagName('li');
	for (i=0; i<rows.length; i++) {
		rows[i].style.backgroundColor = "";
	}
	
	elem.style.backgroundColor = "#02aeef";
}


function change_image_us(src,title,from_src,src_id,img_title,elem) { 
	document.getElementById("localtom_photo_showing").innerHTML = "<div style=margin-top:5px><span class=photo_title>" + unescape(title) + "</span></div><div style=clear:both;></div><div><img src=" + src + " width=220 title='" + img_title + "'></div><div align=right><span class=photo_author2>Source: </span><span onClick=window.open('/redirect/"+src_id+"') style=cursor:pointer; class=photo_author2>" + from_src + "</span></div>"; 

	var rows = document.getElementById('huhu').getElementsByTagName('li');
	for (i=0; i<rows.length; i++) {
		rows[i].style.backgroundColor = "";
	}
	
	elem.style.backgroundColor = "#FF8800";
}