$(document).ready(function() 
{
	$("button[wtb]").click(function(){
		var url = $(this).attr('wtb');
		WTBContainer.show(this, url);
	});
});

function WTBContainer() {}
WTBContainer.show = function(caller, url)
{
	var imageheight = $(caller).attr('imagewidth');
	
	if(imageheight)
	{
		if(imageheight == 'auto') {imageheight = 'auto';} else{imageheight = parseInt(imageheight)+'px';}
		var imagestyle = ' style="width: '+imageheight+'"';
	}
	else {imagestyle = '';}
	
	var	layout = '<div class="toolbar"><a href="javascript:WTBContainer.close(this);" class="closebutton"></a></div>';
		layout += '<div class="image" '+imagestyle+'><div class="wtbcontent">'+html_entity_decode(url)+'</div></div>';
	
//$('body').scrollTop(0);
if($.browser.opera){$('html').animate({scrollTop: $('html,body').offset().top}, 10);} else $('html,body').animate({scrollTop: $('html,body').offset().top}, 10);

	$('#viewerblock .container').html(layout);
	$('#viewerblock').show();
	$('body').css('overflow-y','hidden');
	
	
}
WTBContainer.close = function(caller){
	$('#viewerblock').hide();
	$('body').css('overflow-y','auto');
}
function html_entity_decode(str) {
  var ta = document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  toReturn = ta.value;
  ta = null;
  return toReturn
}

