function showPopup (page,width,height,resizeable,scrollbars) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open('"+page+"', '" + id + "', 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizeable+',width="+width+",height="+height+"');");
};

function checkIE6 () {
	var Browser = {
	  Version: function() {
	    var version = 999; // we assume a sane browser
	    if (navigator.appVersion.indexOf("MSIE") != -1)
	      // bah, IE again, lets downgrade version number
	      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	    return version;
	  }
	}
	if (Browser.Version() < 7) {
	  document.getElementById('warning_ie6').style.display='block';
	}
}

function setSIFRFonts () {
	if(typeof sIFR == "function") {
		sIFR.replaceElement(named({sSelector:"h1.page_headline", sFlashSrc:"/images/ancona-ex-regular.swf", sColor:"#003366", sWmode : "transparent", sFlashVars: "textalign=left"}));
		sIFR.replaceElement(named({sSelector:".menu_item2", sFlashSrc:"/images/ancona-ex-regular.swf", sColor:"#003366", sLinkColor:"#003366", sHoverColor:"#666666", sWmode : "transparent", sFlashVars: "textalign=left"}));

	};
}


/* Object img */
toggleFlag = true;
currObjectImgIdx = 0;
function showObjectImg (idx, max) {
	if (idx==currObjectImgIdx)
		return;

	var frame = document.getElementById ('object_popup_img');
	var img   = document.getElementById ('object_img_'+idx);
	if (frame && img) {
		currObjectImgIdx = idx;


		jQuery ('.object_img_preview_frame a').removeClass ('marked');
		jQuery ('.object_img_preview_frame a:eq('+idx+')').addClass ('marked');

		jQuery ('#object_img_nav_text').html ("Bild "+(currObjectImgIdx+1)+" von "+max);
		
		
		var idName = 'object_popup_img_overlay';
		var idName2 = 'object_popup_img';
		toggleFlag^=true;
		if (toggleFlag) {
			idName = 'object_popup_img';
			idName2 = 'object_popup_img_overlay';
		}
	
		$('#'+idName).hide ().html ($('#object_img_'+idx).html());
		$('#'+idName2).fadeOut ('800', function(){ });
		$('#'+idName).fadeIn   ('800', function(){ });

	
		$('#object_img_img'+idx).one("load",function(){
			//do something
			$('#'+idName2).fadeOut ('800', function(){ });
			$('#'+idName).fadeIn   ('800', function(){ });
		})
		.each(function(){
			if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6))
			$(this).trigger("load");
		}); 		

		if (idx>0)
			jQuery ('#object_img_nav_prev').show ();
		else
			jQuery ('#object_img_nav_prev').hide ();
		if ((idx+1)==max)
			jQuery ('#object_img_nav_next').hide ();			
		else
			jQuery ('#object_img_nav_next').show ();			
			
		if (idx>=3)
		{
			if ((idx+1)<max)
				jQuery ('.object_img_preview_frame_in').css ('margin-left', (-79*(idx-2))+'px');
		}
		else {
			jQuery ('.object_img_preview_frame_in').css ('margin-left', '0px');
		}
		$('#object_img_resize_'+idx).show ();
		for (var i=0;i<=max;i++) {
			if (i!=idx)	
				$('#object_img_resize_'+i).hide ();
		}
		
		return true;
	}
	return false;
}

function showObjectImgNext (max) {
	if (currObjectImgIdx>=max)
		return;
	
	
	showObjectImg (currObjectImgIdx+1, max);
	
}

function showObjectImgPrev (max) {
	if (currObjectImgIdx<=0)
		return;
	showObjectImg (currObjectImgIdx-1, max);
}



/* Ajax popup window stuff */
popupWindowId = '';
popupWindowId2 = '';

function showPopupWindowFilter () {
	var wndDim = WSystem.getWindowDim ();
	var filterWidth   = wndDim.documentWidth;
	var filterHeight  = wndDim.documentHeight;
	if (WSystem.ieVersion<7)
		$('#popupWindowFilter').attr('style', 'display:block;width:100%;height:'+wndDim.windowHeight+'px;');	
	else
		$('#popupWindowFilter').attr('style', 'display:block;min-width:'+filterWidth+'px;min-height:'+filterHeight+'px;');
	$('#popupWindowFilter').hide();	
/*
	if (WSystem.isIE)
		$('#popupWindowFilter').css('filter', 'alpha(opacity=40)');


	$('#popupWindowFilter').fadeIn('1000', function() {
    // Animation complete
  });
*/
	$('#popupWindowFilter').show();	
}

function hidePopupWindowFilter () {
	$('#popupWindowFilter').hide();	
}

function closePopupWindow (id)
{

	if (id==popupWindowId2)
	{
	
		var obj = document.getElementById (popupWindowId2);
		obj.style.display="none";
		obj.style.visibility = "hidden";
		popupWindowId2 = '';
		return;
	}
	var obj = document.getElementById (popupWindowId);
	if (obj) {

		
		obj.style.display="none";
		obj.style.visibility = "hidden";

		hidePopupWindowFilter ();	
		WSystem.removeEvent (document,'keyup', onDocumentKeyPress);
		WSystem.removeEvent (document,'mousedown', onDocumentMouseClick);
	}
}

function onDocumentKeyPress (evt) {
	var keyCode = evt.which;
	if (navigator.appName.indexOf("Microsoft")!=-1)
		keyCode = window.event.keyCode;
	if (keyCode==27) { // ESC
		closePopupWindow ();
	}
	return true;
}

this.onDocumentMouseClick = function (evt)  {
	var mouseCoords = WSystem.getMouseCoords (evt);
	var obj = document.getElementById (popupWindowId);
	if (obj) {
		popupCoords = WSystem.getAbsoluteCoords (obj);
		var x  = popupCoords.x;
		var y  = popupCoords.y;
		var x2 = popupCoords.x+parseInt (obj.offsetWidth);
		var y2 = popupCoords.y+parseInt (obj.offsetHeight);
		if (!(
				mouseCoords.x>x && 
		    mouseCoords.x<x2 && 
		    mouseCoords.y>y && 
		    mouseCoords.y<y2 )) {
			// closePopupWindow ();
		}				
	}		
}

function showPopupWindow (id, popupURL, fAutoPrint) {
	var obj = document.getElementById (id);
	if (!obj)
		return;
	
	toggleFlag = true;
	currObjectImgIdx = 0;
	popupWindowId = id;
	var scrollPos = WSystem.getScrollPos ();
	var wndDim		= WSystem.getWindowDim ();
	var wndHeight = wndDim.windowHeight;
	var wndWidth  = wndDim.windowWidth;
	
	var x0 = scrollPos.x;			
	var x1 = x0 + wndWidth;
	var y0 = scrollPos.y;	
	var y1 = y0 + wndHeight;
	
  showPopupWindowFilter ();		
	obj.style.display="block";			

	// $('#popup_content').jScrollPane({scrollbarWidth: 0, dragMaxHeight:0});
	// Progress bar
	$('#'+id+'_content').html ('<div style="text-align:center;"><img src="images/progress.gif" /></div>');
	
	var mainFrame = document.getElementById ('main_frame');
	obj.style.left = mainFrame.offsetLeft + ((mainFrame.offsetWidth-obj.offsetWidth)/2) + 'px';
	obj.style.top  = mainFrame.offsetTop + 'px';

	/*
	obj.style.left = (x0+(wndWidth  - parseInt (obj.offsetWidth))  /2)+"px";
	obj.style.top  = (y0+(wndHeight - parseInt (obj.offsetHeight)) /2)+"px";
	*/
	
	obj.style.visibility = "visible";	

	// Esc key functions
	WSystem.addEvent (document,'keyup', onDocumentKeyPress, false);
	WSystem.addEvent (document,'mousedown', onDocumentMouseClick, false);

	// Load ajax content
	$.ajax({ url: popupURL, success: function(data) {
		$('#'+id+'_content').html (data); 								
		if ($('#scroll_frame'))
			$('#scroll_frame').jScrollPane({scrollbarWidth: 8, dragMaxHeight:120, scrollbarMargin:20 });			
		if (fAutoPrint) {
			window.print ();
			closePopup ();
		}
	}});
}


function showPopupWindow2 (id, popupURL, fAutoPrint) {

	var obj = document.getElementById (id);
	if (!obj)
		return;

	toggleFlag = true;
	currObjectImgIdx = 0;
	popupWindowId2 = id;
	var scrollPos = WSystem.getScrollPos ();
	var wndDim		= WSystem.getWindowDim ();
	var wndHeight = wndDim.windowHeight;
	var wndWidth  = wndDim.windowWidth;
	
	var x0 = scrollPos.x;			
	var x1 = x0 + wndWidth;
	var y0 = scrollPos.y;	
	var y1 = y0 + wndHeight;
	
	obj.style.display="block";			

	// Progress bar
	$('#'+id+'_content').html ('<div style="text-align:center;"><img src="images/progress.gif" /></div>');
	
	var mainFrame = document.getElementById ('main_frame');
	obj.style.left = mainFrame.offsetLeft + ((mainFrame.offsetWidth-obj.offsetWidth)/2) + 'px';
	obj.style.top  = mainFrame.offsetTop + 30 + 'px';

	obj.style.visibility = "visible";	

	// Load ajax content
	$.ajax({ url: popupURL, success: function(data) {
		$('#'+id+'_content').html (data); 								
		if ($('#scroll_frame'))
			$('#scroll_frame').jScrollPane({scrollbarWidth: 8, dragMaxHeight:120, scrollbarMargin:20 });			
		if (fAutoPrint) {
			window.print ();
			closePopup ();
		}
	}});
}

function showAreaDetails (check, id) {
	var x = document.getElementById ('area_detail_'+id);

	if (check.checked==1) {
		x.style.visibility = "visible";
		x.style.display = "block";
	}
	else {
		x.style.visibility = "hidden";
		x.style.display = "none";
	}
}

function showAreaDetails2 (check, id) {
	var x = document.getElementById ('area_detail2_'+id);

	if (check.checked==1) {
		x.style.visibility = "visible";
		x.style.display = "block";
	}
	else {
		x.style.visibility = "hidden";
		x.style.display = "none";
	}
}

function initMenu ()
{
	var ulObj = document.getElementById ("menuitems").firstChild;	
	menuItems = createMenuItemsFromULStruct (ulObj);
	menu = new Menu (document.getElementById ("main_menu"), "mainmenu", 0, 0, menuItems, true);
}

// Document loaded

$(document).ready(function() { 

/*
	
	$(window).resize(function () {
			closePopupWindow ();

	});  
*/
});
