var vwr={
enableTitle:true,
enableAnimation:true,
defineLoading:'<img src="/i/loading.gif" /> LOADING... ',
scrollbarwidth:16,
opacitystring:'filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity: 0.1; opacity: 0.1',
targetlinks:[],
createthbox:function(){
document.write('<div id="thbox" onclick="vwr.closeit()" onmouseover="vwr.toggleclass(\'thfo\')" onmouseout="vwr.toggleclass(\'\')"><div id="thf" class="">&nbsp;</div><div id="thimg"></div></div>');
document.write('<div id="thld">'+this.defineLoading+'</div>');this.thbox=document.getElementById("thbox");
this.thimg=document.getElementById("thimg");
this.thld=document.getElementById("thld");
this.standardbody=(document.compatMode=="CSS1Compat")?document.documentElement:document.body;},


toggleclass:function(classn) {
idname=document.getElementById("thf");
if (idname) {
	//alert(idname.id);
idname.className = classn;
//alert(idname.className);
}
},

centerDiv:function(divobj,is_lg_img){
	if(is_lg_img==1){

	var caption=document.getElementById("caption");
		
if(caption){var i=divobj.getElementsByTagName("img")[0];caption.style.width=(i.width)+"px";}
	} 
var ie=document.all&&!window.opera;var dom=document.getElementById;
var scroll_top=(ie)?this.standardbody.scrollTop:window.pageYOffset;
var scroll_left=(ie)?this.standardbody.scrollLeft:window.pageXOffset;
var docwidth=(ie)?this.standardbody.clientWidth:window.innerWidth-this.scrollbarwidth;
var docheight=(ie)?this.standardbody.clientHeight:window.innerHeight;
var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)?this.standardbody.offsetHeight:this.standardbody.scrollHeight;var objwidth=divobj.offsetWidth;
var objheight=divobj.offsetHeight;
var topposition=(docheight>objheight)?scroll_top+docheight/2-objheight/2+"px":scroll_top+10+"px";divobj.style.left=docwidth/2-objwidth/2+"px";divobj.style.top=Math.floor(parseInt(topposition))+"px";divobj.style.visibility="visible";
},

showthbox:function(){
this.centerDiv(this.thbox,1);
if(this.enableAnimation){
this.curopac=0.1;this.opacitytimer=setInterval(function() {vwr.opacityanimation();},20);}
},

loadimage:function(link){
if(this.thbox.style.visibility=="visible"){
	this.closeit();
}

var imageHTML='<img src="'+link.getAttribute("href")+'" style="'+this.opacitystring+'" />';

if(this.enableTitle&&link.firstChild.getAttribute("title")) {
	//alert(link.firstChild.getAttribute("title"));
imageHTML+='<div id="caption">';

imageHTML+='<div>'+link.firstChild.getAttribute("title")+'</div>';

description = link.getAttribute("description");


if (description) {

imageHTML+='<div id="description"><div>'+description+'</div>';
}

imageHTML+='</div>';

	
	
//imageHTML+='<div id="caption"><div></div></div>';
}

this.centerDiv(this.thld,0);
this.thimg.innerHTML=imageHTML;
this.ftrimg=this.thimg.getElementsByTagName("img")[0];
this.ftrimg.onload=function(){
vwr.thld.style.visibility="hidden";
vwr.showthbox();
};

if(document.all&&!window.createPopup){
this.ftrimg.src=link.getAttribute("href");
}

this.ftrimg.onerror=function(){
vwr.thld.style.visibility="hidden";
};
}, 

setimgopacity:function(value){
var targobj=this.ftrimg;
if(targobj.filters&&targobj.filters[0]){
	if(typeof targobj.filters[0].opacity=="number"){targobj.filters[0].opacity=value*100;
	}
else{
targobj.style.filter="alpha(opacity="+value*100+")";
}
}
else if(typeof targobj.style.MozOpacity!="undefined"){
	targobj.style.MozOpacity=value;
}
else if(typeof targobj.style.opacity!="undefined"){
targobj.style.opacity=value;
}
else{
this.stopanimation();
}
},

opacityanimation:function(){
this.setimgopacity(this.curopac);
this.curopac+=0.1;if(this.curopac>1){
this.stopanimation();}
},

stopanimation:function(){
if(typeof this.opacitytimer!="undefined"){
clearInterval(this.opacitytimer);}
},

closeit:function(){
this.stopanimation();
this.toggleclass();
this.thbox.style.visibility="hidden";
this.thimg.innerHTML="";
this.thbox.style.left="-2000px";
this.thbox.style.top="-2000px";
},

cleanup:function(){this.thld=null;if(this.ftrimg){
		this.ftrimg.onload=null;
}
this.ftrimg=null;this.thimg=null;for(var i=0;i<this.targetlinks.length;i++){
this.targetlinks[i].onclick=null;
}

this.thbox=null;
},

dotask:function(target,functionref,tasktype){
	var ttype=(window.addEventListener)?tasktype:"on"+tasktype;if(target.addEventListener){
		target.addEventListener(ttype,functionref,false);
	}
	else if(target.attachEvent){
		target.attachEvent(ttype,functionref);
	}
},

init:function(){
	if(!this.enableAnimation){
	this.opacitystring="";
	}
var pagelinks=document.getElementsByTagName("a");
for(var i=0;i<pagelinks.length;i++){
	if(pagelinks[i].getAttribute("rel")&&pagelinks[i].getAttribute("rel")=="thumbnail"){
		pagelinks[i].onclick=function(){
		vwr.stopanimation();vwr.loadimage(this);return false;
		};
this.targetlinks[this.targetlinks.length]=pagelinks[i];
	}
}

this.dotask(window,function(){
	if(vwr.thbox.style.visibility=="visible"){
		vwr.centerDiv(vwr.thbox,1);
	}
},"resize")
;}
};

vwr.createthbox();
vwr.dotask(window,function(){vwr.init();},"load");
vwr.dotask(window,function(){vwr.cleanup();},"unload");
