var modalPopupFactory = {

"ids":"",
"exists":function(src){return (this.ids.indexOf(";"+src.id)>-1)},
"popups" : [],

"create" : function(src) {
if (!this.exists(src)){
this.popups.push(new Popup(src, false));
} else {
this.ids+=";" + src.id;
}

 this.show(this.popups.length-1) 

},
"createSmall" : function(src) {
if (!this.exists(src)){
this.popups.push(new Popup(src, true));
} else {
this.ids+=";" + src.id;
}

 this.show(this.popups.length-1) 

},

"show" : function(i){


this.popups[i].show();


},

"hide" : function(i){
this.popups[i].hide();
}

}


var connectPredefinedPopupLinks = {
	
	"load" : function(){
	var elements = getElementsByTagAndClassName("A", "popup");
	
		for(var i=0; i<elements.length; i++){
			elements[i].href+=(elements[i].href.indexOf("?")>-1) ? "&style=minimal&redirect=close" : "?style=minimal&redirect=close";
			connect(elements[i], "onclick", function(e){
			e.stop();
			modalPopupFactory.create(e.src());
			});
		}
		
		
	elements = getElementsByTagAndClassName("A", "newWindow");
	
		for(var i=0; i<elements.length; i++){
			elements[i].href+=(elements[i].href.indexOf("?")>-1) ? "&style=minimal&redirect=close" : "?style=minimal&redirect=close";
			connect(elements[i], "onclick", function(e){
			e.stop();
			
			window.open(e.src().href, 'window' + i , 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=400');
			
			
			});
		}
	}

}
var popup_id=1;
var Popup = function(src, small){
this.id=popup_id;
popup_id++;
this.DOM = null;
this.href = src.href + "&popup_id=" + this.id;
this.title = (src.title!="")? src.title: ((src.textContent) ? src.textContent : src.innerText);
this.small=small;
this.urls=[];
this.width=520;
this.height=520;

var className = src.className;
if(src.className && src.className!="") {
var classes = src.className.split(" ");

for(var i=0; i<classes.length; i++) {

if(classes[i].indexOf("width")>-1) {
this.width = classes[i].replace("width","");
}
if(classes[i].indexOf("height")>-1) {
this.height = classes[i].replace("height","");
}
}
}

}
Popup.prototype.hide = function(e){
e.stop();
if (this.DOM){
swapDOM(this.DOM, null);

modalClosed();


}
}
Popup.prototype.show = function(){


var container = document;
if(window["is_popup"]){
container=parent.document;
}
	
var title =  H2({"class":"close_header"},this.title+"... loading");
var back = A({"href":"#", "class":"back", "display":"none"},IMG({"src":"/images/back.png"}));
var iframe_loader = DIV({"class":"iframe_loader"}, IMG({"src":"/images/loading_circle.gif"}));

var close = A({"href":"#"},IMG({"src":"/images/fileclose.png"}));
connect(close, "onclick", this, this.hide);
connect(back, "onclick", function(e){
e.stop();
iframe_loader.style.display="block";
back.style.display="none";
me.urls=me.urls.splice(me.urls.length-1,1);
iframe.src=me.urls[me.urls.length-1];

});

var closeme = DIV({"class":"close"},back, title, close);



var me = this;
var iframe = container.createElement("iframe");

	connect(iframe, "onload", function(e){
		if(title.textContent) {
			title.textContent=me.title;
		} else {
			title.innerText=me.title;
		}
		iframe_loader.style.display="none";
		me.urls.push(iframe.src);
		if(me.urls.length>1) {
			back.style.display="block";
		}
		
	});

	
	
	iframe.src = this.href;
	iframe.style.border="1px solid #369";
	iframe.frameborder=0;
	iframe.style.width=(this.width-22)+"px";
	iframe.style.height=(this.height-42)+"px";
	closeme.style.width=(this.width-20)+"px";
	closeme.style.height="20px";
	
	
	
	if(BrowserDetect.version<=7 && BrowserDetect.browser=="Explorer") {
	iframe.style.position = "relative";
	iframe.style.left="0px";
	iframe.style.top="10px";
	iframe.style.display = "block";
	closeme.style.position="relative";
	closeme.style.top="10px";
	closeme.style.left="0px";
	} else {
	iframe.style.position = "relative";
	iframe.style.left="10px";
	iframe.style.top="10px";
	iframe.style.display = "block";
	closeme.style.position="relative";
	closeme.style.top="10px";
	closeme.style.left="10px";
	}
	
	iframe.style.clear="left";
	iframe.style.zIndex=11;
	
	iframe_loader.style.position = "absolute";
	iframe_loader.style.left = iframe.style.left;
	iframe_loader.style.top = iframe.style.top;
	iframe_loader.style.width = iframe.style.width;
	iframe_loader.style.height = iframe.style.height;
	iframe_loader.style.zIndex = 12;
	iframe_loader.style.clear = "left";
	iframe_loader.style.display="block";
	
	
	var dialog = DIV({"class":"dialog"});
	dialog.style.zIndex=10;
	dialog.style.position="absolute";

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( container.documentElement &&
      ( container.documentElement.clientWidth || container.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = container.documentElement.clientWidth;
    myHeight = container.documentElement.clientHeight;
  } else if( container.body && ( container.body.clientWidth || container.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = container.body.clientWidth;
    myHeight = container.body.clientHeight;
  }


	var scrollTop = 0;
	
	if (container.documentElement && container.documentElement.scrollTop) {
		scrollTop = container.documentElement.scrollTop;
	} else if (container.body && container.body.scrollTop) {
		scrollTop = container.body.scrollTop;
	}

	dialog.style.left = ((myWidth / 2) - (252) ) + "px";
	dialog.style.top = (((myHeight / 2) - (252)) + scrollTop) + "px"; 
	dialog.style.width=this.width+"px";
	dialog.style.height=this.height+"px";
	
	var bgImage = IMG({"src":"/images/popup_tl.png", "width":this.width, "height":this.height});

	var dialogcontainer1 = DIV({"class":"dialogcontainer1"}, bgImage);
	dialogcontainer1.style.position="absolute";
	dialogcontainer1.style.left="0px";
	dialogcontainer1.style.top="0px";
	dialogcontainer1.style.width=(this.width) + "px";
	dialogcontainer1.style.height=(this.height) + "px";

	new Draggable(dialog, {"starteffect":null,"endeffect":null});
	appendChildNodes(dialog, dialogcontainer1);


	appendChildNodes(dialog, closeme, iframe, iframe_loader);
	appendChildNodes(container.body, dialog);
	this.DOM=dialog;
}


addLoadEvent(function(){connectPredefinedPopupLinks.load();});



		