window.arivis = window.arivis || {};
window.arivis.website = window.arivis.website || {};

/**
 * @constructor Popup init
 */
arivis.website.Popup = function() {

	this.init = function(){
		var elem = $$('a.popup');
		var instance = this;
		for (var i=0; i < elem.length; i++){
			Event.observe(elem[i], "click", function(e){ instance.popup(e); });
		}
	};

	this.popup = function(e){
		var elem = Event.findElement(e, "a");
		if (!elem) return;
		var href = elem.readAttribute('href');
		this.win(href, 1000, 800, "arivis.gallery", "max");
		Event.stop(e);
	};

	this.win = function (url, w, h, name, modus) {
		if(!name) name = "_winOnFly";
		if (document.images){
			if(modus == 'max' || modus == 'maxWidth' || modus == 'maxHeight') aInnerWidthHeight = this.innerWidthHeight();
			if(modus == 'max' || modus == 'maxWidth') w = (w > aInnerWidthHeight[x]-20) ? aInnerWidthHeight[x]-20 : w;
			if(modus == 'max' || modus == 'maxHeight') h = (h > aInnerWidthHeight[y]-20) ? aInnerWidthHeight[y]-20 : h;
			winOnFly=window.open(url, name ,'width=' + w + ',height=' + h + ',screenX=10,screenY=10,status=yes,menubar=yes,resizable=yes,locationbar=no,scrollbars=yes');
			setTimeout("winOnFly.focus()", 300);
			return false;
		}
		return true;
	};

	this.innerWidthHeight = function (){
		if (self.innerHeight) // all except Explorer
		{
			x = self.innerWidth;
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}
		return new Array(x,y);
	};

};

// init Popup
arivis.website.popup = new arivis.website.Popup();
Event.observe(window, 'load', function(){ arivis.website.popup.init(); });
