/* #############################################
	# Module: TextBild-Popup (2Spalten)
*/
function showPopup(file,width,height,maxW)
{	file=file.src;	
	file=file.split("w__");
	file=file[1];
	
	newwidth=width;
	newheight=height;
	
	ratio=maxW/newwidth;
		
	if (newwidth>maxW)
	{	newwidth=maxW;
		newheight=height*ratio;
	}


	var x=window.open('', 'bigPrev', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+(newwidth)+',height='+(newheight));
	
	x.document.write("<html><head><title>Bild</title>");
	x.document.write('<style type="text/css">');
	x.document.write("html,body{margin:0;padding:0;overflow:hidden;}img{cursor:pointer;}");
	x.document.write("</style></head><body>");

	x.document.write('<img src="index.php?rex_resize='+newwidth+'w__'+file+'" alt="" onclick="window.close();">');
	x.document.write("</body></html>");
	x.document.close();
	x.focus();


}	
/*	#############################################*/


Behaviour.addLoadEvent 
(	function()
	{	
	
	
	
		//Hide all sub pages
		var swappers=document.getElementsBySelector('.bildswapper');
		
		for (i=0;i<swappers.length;i++)
		{	swappics=swappers[i].getElementsByTagName('DIV');
			
			//Filter out divs which arent areas.
			var counter=0;
			swappics2=new Array();
			for (j=0;j<swappics.length;j++)
			{	if(swappics[j].className!="bilddesc")
				{	swappics2[counter]=swappics[j];
					counter++;
				}
			}
			swappics=swappics2;
			
			//Loop through subpics
			for (j=0;j<swappics.length;j++)
			{	swapperclass=swappics[j].className;
				swapperclass=swapperclass.split(' ');
				
				desc=swappics[j].getElementsByTagName('DIV')[0];
				desc.style.display="none";
				
				if (swapperclass[0]=="bild")
				{	thepic=swappics[j].getElementsByTagName('IMG')[0];
					var img=document.createElement("IMG");
					img.setAttribute('src',thepic.getAttribute('src'));
					img.style.cursor="pointer";
					img.className="swapthumb s"+j;
					swappers[i].appendChild(img);
				}
			}
			var newDesc=document.createElement("SPAN");
			newDesc.style.display="block";
			newDesc.innerHTML=swappers[i].getElementsByTagName('DIV')[0].getElementsByTagName('DIV')[0].innerHTML;;
			swappers[i].appendChild(newDesc);
			Behaviour.apply();
		}
		
	}
);

var Rules = {
        '.extern' : function(el)
	{	el.onclick = function()
		{    this.setAttribute('target','_blank');
		}
	}
	,
	'.swapthumb' : function(el)
	{	el.onclick = function()
		{	x=this.className;
			x=x.split(' ');x=x[1];
			x=x.split('s');x=x[1];						
			thepics=this.parentNode.getElementsByTagName('DIV');
			var counter=0;
			thepics2=new Array();
			for (i=0;i<thepics.length;i++)
			{	if(thepics[i].className!="bilddesc")
				{	thepics2[counter]=thepics[i];
					counter++;
				}
			}
			thepics=thepics2;
			
			for (i=0;i<thepics.length;i++)
			{	if (i!=x)
				{	thepics[i].style.display="none";
				}
			}
			desc=thepics[x].getElementsByTagName('DIV')[0];
			thepics[x].parentNode.getElementsByTagName('SPAN')[0].innerHTML=desc.innerHTML;
			thepics[x].style.display="block";
		},
		el.onmouseover = function()
		{	this.className=this.className+" bildswaphover";
		},
		el.onmouseout = function()
		{	x=this.className;
			x=x.split(' ');
			this.className=x[0]+" "+x[1];
		}
	}
};

Behaviour.register(Rules);

