// All popup calls goes here
//	
function popup(url, w, h, f, n, l, t){
	if(navigator.userAgent.indexOf("Safari") != -1){
		//w = w - 46;
		//h = h - 25;
	}
	var day = new Date();
	var id = day.getTime();
	if(n == null){
		n = "raketen_" + id;
	}
	if(l == null){
		l = (screen.availWidth-w)/2;
	}
	if(t == null){
		t = (screen.availHeight-h)/2;
	}
	var features = "width="+w+",height="+h+",left="+l+",top="+t+",screenX="+l+",screenY="+t;

	if(f != null){
		features += "," + f;
	}
	

	eval("var win"+id+" = window.open('"+url+"', '"+n+"', '"+features+"');");
	eval("win"+id+".moveTo((screen.availWidth-"+w+")/2,(screen.availHeight-"+h+")/2);");
	eval("win"+id+".focus();");	
	return eval("win"+id+";");	
}

// Some globals to see if a popup is open or not
// Dont change this shit, ok?
//
WinRaketen = null;
WinRadio = null;
WinGallery = null;
GalleryID = null;

// Resize current main window. if you leave out w or h
// the window makes itself fullscrenen.
// if you want fullscreen call like this: ResizeWindow();
// otherwise ex: ResizeWindow(680,400); if you want it in that size.
//
function ResizeWindow(w, h){
	if(w == null || h == null){
		w = screen.availWidth;
		h = screen.availHeight;
		self.resizeTo(w, h);
		self.moveTo(0,0);	
	}else{
		self.resizeTo(w, h);
		self.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
	}
}

// This function opens the raketen main popup and
// resizes the main window to whatever you want
//
function OpenRaketen(){
	if(WinRaketen != null && !WinRaketen.closed){
		WinRaketen.focus();
	}else{
		WinRaketen = popup('raketen.php?w=680&h=400',680,400,'scrollbars=0,resizable=0');
	}
	ResizeWindow(680, 400);
}

// This function is called from the flash menu to open the radio
//
function OpenRadio(){
	if(WinRadio != null && !WinRadio.closed){
		WinRadio.focus();
	}else{
		WinRadio = popup('radio.php?w=250&h=140',250,140,'scrollbars=0,resizable=0');
	}
}

// Another popup function called from the menu, to open, yes you 
//guessed right; the gallery!
//
function OpenGallery(id){
	if(id == GalleryID && (WinGallery != null && !WinGallery.closed)){
		WinGallery.focus();
	}else{
		GalleryID = id;
		WinGallery = popup('gallery.php?item_id='+id+'&w=680&h=400',680,400,'scrollbars=0,resizable=0');
	}
}


s_maxw=0;
s_maxh=0;
s_h=0;
s_w=0;


// Resize popup window to fit current swf. called from main menu. 
//
function ResizeFrameset(w,h) {
	var curWidth = screen.availWidth;
	var curHeight = screen.availHeight;
	var difx = 0;
	var dify = 0;
	
	
	//Safari ignores resizeTo, must use resizeBy
	//if(navigator.userAgent.indexOf("Safari") != -1){
	if(parent.window.self.innerWidth){
	// ---> Safari, Camino, Netscape 7, Netscape 4, Mozilla
			difx = w - parent.window.self.innerWidth;
			dify = h - parent.window.self.innerHeight;
			
			s_maxw = difx;
			s_maxh = dify;
			s_w = 0;
			s_h = 0;
			//ScaleWindow();
			parent.window.resizeBy(difx, dify);
			parent.window.moveTo((curWidth - w)/2,(curHeight - h)/2);
		//}
	}else if (parent.window.document.body && parent.window.document.body.clientWidth){
	// ---> IE 6 PC, IE5 OSX, IE5 OS9
			//alert("2: " + document.body.clientHeight);
			// stupid fix for IE5 OS9 in the help
			if(navigator.platform.indexOf("Mac") != -1 && h > 450){
				//h = h + 20;
			}
			difx = w - parent.window.document.body.clientWidth;
			dify = h - parent.window.document.body.clientHeight;

			parent.window.resizeBy(difx, dify);
			parent.window.moveTo((curWidth - w)/2,(curHeight - h)/2);
	}else {
	// ---> Others
			//alert("nada");
			parent.window.resizeTo(w, h);
			parent.window.moveTo((curWidth - w)/2,(curHeight - h)/2);	
	}
	
	// resize the opener
	//parent.window.opener.resizeTo(w,h);
	//parent.window.opener.moveTo((curWidth - w)/2,(curHeight - h)/2);
}

function ScaleWindow(){
	if(s_w == s_maxw && s_h == s_maxh){
		return;
	}
	
	if(s_maxw < 0){
		s_w -= 1;
		if(s_w <= s_maxw){
			s_w = s_maxw;
		}		
	}else{
		s_w += 1;
		if(s_w >= s_maxw){
			s_w = s_maxw;
		}	
	}
	
	if(s_maxh < 0){
		s_h -= 1;
		if(s_h <= s_maxh){
			s_h = s_maxh;
		}		
	}else{
		s_h += 1;
		if(s_h >= s_maxh){
			s_h = s_maxh;
		}	
	}

	var curWidth = screen.availWidth;
	var curHeight = screen.availHeight;
		
	parent.window.resizeBy(s_w, s_h);
	parent.window.moveTo((curWidth - (parent.window.self.innerWidth+s_maxw))/2,(curHeight - (parent.window.self.innerHeighth+s_maxh))/2);
	
	setTimeout("ScaleWindow()", 50);

}

// Load new swf. 
// USED WHEN WE HAVE A FRAMESET ONLY
//
function LoadMovie(swf, w, h){
	h = h + 40;
	parent.frames['raketen_bot'].location.href = '/raketen.php?swf='+swf+'&w='+w+'&h='+h;
	ResizeFrameset(w,h);
}
	

