/*---------------------------------------------------------------------------
 project name:	popup
 filename:	w_popup,js
 author:	wiktor@freemail.hu as always... :)

 started	@ 2004.07.25. 01:22
 last modified	@ 2004.07.25.
---------------------------------------------------------------------------*/

function w_popup_Init() {
	// Ha ezt nem tudja, akkor nincs mit keresnunk...
	if (!document.getElementsByTagName) return; 

	isTHN='thn_';
        
	// minden olyan IMG "ala", aminek az ID-je thn_-nel kezdodik felprogramozzuk
	var images=document.getElementsByTagName("img"); 
//	alert(images.length);
	for (var i=0; i<images.length; i++) { 
		var image=images[i];
                // levizsgaljuk, van-e ID-je. ha nincs akkor firefox leall
//                alert(image.getAttribute("id"));
		if (imageID=image.getAttribute("id")) {
           		imageIDbegin=imageID.substr(0,isTHN.length)
           		if (imageIDbegin==isTHN) {
           			// letiltjuk az A tag-et
       					image.parentNode.onclick=function () {
       					return false;
       				}
           			image.onclick=function () {
           				imageID=this.getAttribute("id");
           				alt=this.getAttribute("alt");
           				size=imageID.split("_");
                                	centeredOpenWin("/popup.php?src="+this.parentNode.href+"&title="+alt,size[1],size[2],imageID,'no');
           			}
           		}
           	}
        }
} // end of w_popup_Init

function centeredOpenWin(linka,win_w,win_h,name,scroll)
 {
//   DetectBrowser();
   var sw=screen.width;
   var sh=screen.height;
   maxw=sw-30;
   maxh=sh-100;
   if (sw==800)  { maxw=780; }		if (sh==600)  { maxh=520; }
   if (sw==1024) { maxw=1000; }		if (sh==768)  { maxh=680; }
   size=new Array(win_w,win_h);
   size=calc(size,maxw,maxh,maxw/maxh);
   win_w=size[0];
   win_h=size[1];
//   alert(win_w);  alert(win_h);

   if (browser=="Internet Explorer")  { win_w=win_w-4; win_h=win_h-3; }
    // nem akkora ablakot nyit meg mint kene
   if (scroll!="yes") { scroll="no"; }
   var settings="scrollbars="+scroll+",width="+win_w+",height="+win_h+",";
   var bal_felso_x=(sw-win_w)/2-5; 
   var bal_felso_y=((sh-60)-win_h)/2;
   if (browser=="Netscape Navigator")
    { settings+="screenX="+bal_felso_x+",screenY="+bal_felso_y; } else
    { settings+="left="+bal_felso_x+",top="+bal_felso_y; } 
/*
   alert(linka);
   alert(settings);
   alert(name);
*/
   x=window.open(linka,name,settings);
 }

function calc(size,MAX_WIDTH,MAX_HEIGHT,MAX_AR) {
	w=size[0]; 
	h=size[1];
	ar=w/h;
	if ( (w>MAX_WIDTH) || (h>MAX_HEIGHT) ) {
		if (ar<MAX_AR) {
			w=Math.round(w*(MAX_HEIGHT/h));
			h=MAX_HEIGHT;
		} else {
        		h=Math.round(h*(MAX_WIDTH/w));
        		w=MAX_WIDTH;
      		}
  	}

	var newsize=new Array();
	newsize[0]=w;
	newsize[1]=h;
	return newsize;
}

