var novumpix =
{
	opacity_str: 'filter:progid:DXImageTransform.Microsoft.alpha(opacity=10); -moz-opacity: 0.1; opacity: 0.1',
	image_links_array:[],

	npconstruct:function()
	{
		document.write('<div id="npwrapper" onclick="novumpix.closeit()"><div id="npheader">X</div><div id="npimg"></div><div id="npfooter"></div></div>')
		document.write('<div id="nploading"><img src="'+novumpix_loading_img+'" />'+novumpix_loading_txt+'</div>')
		this.npwrapper = document.getElementById("npwrapper")
		this.npimg = document.getElementById("npimg")
		this.npfooter = document.getElementById("npfooter")
		this.nploading = document.getElementById("nploading")
		this.standardbody = (document.compatMode=="CSS1Compat")? document.documentElement : document.body
	},

	npcenter:function(div2center)
	{
		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-16
		var docheight = (ie)? this.standardbody.clientHeight: window.innerHeight
		var docheightcomplete = (this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight
		var objwidth = div2center.offsetWidth
		var objheight = div2center.offsetHeight
		var topposition = (docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px"
		div2center.style.left = docwidth/2-objwidth/2+"px"
		div2center.style.top = Math.floor(parseInt(topposition))+"px"
		div2center.style.visibility = "visible"
	},

	npshow:function()
	{
		this.npcenter(this.npwrapper)
		if (novumpix_enable_effects)
		{
			this.currentopacity = 0.1
			this.opacitytimer = setInterval("novumpix.opacityanim()", 20)
		}
	},


	nploadimg:function(link)
	{
		if (this.npwrapper.style.visibility == "visible") this.closeit()
		this.npcenter(this.nploading)
		this.npimg.innerHTML = '<img src="'+link.getAttribute("href")+'" style="'+this.opacity_str+'" />'
		if (novumpix_show_title && link.getAttribute("title")) this.npfooter.innerHTML = link.getAttribute("title")
		this.imgitself = this.npimg.getElementsByTagName("img")[0]

		this.imgitself.onload = function()
		{
			novumpix.nploading.style.visibility = "hidden"
			novumpix.npshow()
		}

		if (document.all && !window.createPopup) this.imgitself.src = link.getAttribute("href")

		this.imgitself.onerror = function()
		{
			novumpix.nploading.style.visibility = "hidden"
		}
	},

	setimgopacity:function(value)
	{
		
		if (this.imgitself.filters && this.imgitself.filters[0])
		{
			if (typeof this.imgitself.filters[0].opacity == "number") this.imgitself.filters[0].opacity = value*100 // IE6
			else this.imgitself.style.filter = "alpha(opacity=" + value * 100 +")" // IE5.5
		}

		else if (typeof this.imgitself.style.MozOpacity != "undefined") this.imgitself.style.MozOpacity = value // Mozilla (old)
		else if (typeof this.imgitself.style.opacity != "undefined") this.imgitself.style.opacity = value // Standard
		else this.stopanim()
	},

	opacityanim:function()
	{
		this.setimgopacity(this.currentopacity)
		this.currentopacity += 0.1
		if (this.currentopacity > 1) this.stopanim()
	},

	stopanim:function()
	{
		if (typeof this.opacitytimer != "undefined") clearInterval(this.opacitytimer)
	},


	closeit:function()
	{
		this.stopanim()
		this.npwrapper.style.visibility = "hidden"
		this.npimg.innerHTML = ""
		this.npwrapper.style.left = "-2000px"
		this.npwrapper.style.top = "-2000px"
	},

	cleanup:function()
	{
		this.nploading = null
		if (this.imgitself) this.imgitself.onload = null
		this.imgitself = null
		this.npimg = null
		for (var i = 0; i < this.image_links_array.length; i++)
		this.image_links_array[i].onclick = null
		this.npwrapper = null
	},

	npdo:function(target, ref, type)
	{
		var type = (window.addEventListener)? type : "on" + type
		if (target.addEventListener) target.addEventListener(type, ref, false)
		else if (target.attachEvent) target.attachEvent(type, ref)
	},

	initialize:function()
	{
		var links2scan = document.getElementsByTagName("a")
		if (!this.novumpix_enable_effects) this.opacity_str = ""
		for (var i = 0; i < links2scan.length; i++)
		{
			if (links2scan[i].getAttribute("rel") && links2scan[i].getAttribute("rel") == "thumb")
			{
				links2scan[i].onclick = function()
				{
					novumpix.stopanim()
					novumpix.nploadimg(this)
					return false
				}
				this.image_links_array[this.image_links_array.length] = links2scan[i]
			}
		}
		this.npdo(window, function() {if (novumpix.npwrapper.style.visibility == "visible") novumpix.npcenter(novumpix.npwrapper)}, "resize")
	}
}

novumpix.npconstruct()
novumpix.npdo(window, function(){novumpix.initialize()}, "load")
novumpix.npdo(window, function(){novumpix.cleanup()}, "unload")
