var popwin;

// PopUps aufrufen
function PopUp(src,w,h)
{
	oversize = 0;
	if(popwin) popwin.close();

	if(w > screen.width-100)
	{
		oversize = 1;
		// h = Math.round((screen.width-100)/w*h); // Verhältnis
		h = parseInt(h)+20; // Scrollbars
		w = (screen.width-100);
	}
	if(h > screen.height-150)
	{
		oversize = 1;
	    // w = Math.round((screen.height-150)/h*w); // Verhältnis
	    w = parseInt(w)+20; // Scrollbars
		h = (screen.height-150);
	}

	breite = Math.round((screen.width - w) / 2);
	hoehe = Math.round((screen.height - h) / 2);

	if(oversize == 1)
		popwin = window.open(src,"popwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h+",top="+hoehe+",left="+breite);
	else
		popwin = window.open(src,"popwin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+w+",height="+h+",top="+hoehe+",left="+breite);
}

// Formulare leeren
function ClearForm(Formular)
{
	document.forms[Formular].reset(); // Zuerst reset!
	var x = 0;
	while(document.forms[Formular].elements[x])
	{
		if(document.forms[Formular].elements[x].type == "checkbox" || document.forms[Formular].elements[x].type == "radio")
		{
			// Checkboxen + Radiobuttons werden nicht angehakt
			document.forms[Formular].elements[x].checked = false;
		}
		else if(document.forms[Formular].elements[x].type != "hidden" && document.forms[Formular].elements[x].type != "submit" && document.forms[Formular].elements[x].type != "reset" && document.forms[Formular].elements[x].type != "button")
		{
			// Alle, ausser versteckte Felder, dürfen geleert werden
			document.forms[Formular].elements[x].value = "";
		}
		x++;
	}
}

// Liefert ein Object anhand ID oder Name
function gObj(id)
{
	if(typeof document.getElementById(id) == 'object' && document.getElementById(id) != null)
	{
		return document.getElementById(id);
	}
	else if(document.getElementsByName)
	{
		var namedObjects = document.getElementsByName(id);
		if(typeof namedObjects != 'undefined' && namedObjects.length)
		{
		    return namedObjects[0];
		}
	}
}

// PNG-Bilder werden im IE 5.5 oder IE 6 halbtransparent dargestellt, ohne extra Klassen benutzen zu müssen
// vor </body> muss noch folgendes eingebunden werden:
// <script type="text/javascript">
// fixAllPNGs();
// </script>
function fixAllPNGs()
{
	ie = navigator.appVersion.split("MSIE");
	version = parseFloat(ie[1]);

    if((version >= 5.5) && (version < 7) && (document.body.filters))
    {
		for(i=0; i<document.getElementsByTagName('img').length; i++)
		{
			myImage = document.getElementsByTagName('img')[i];

			if(myImage.src.match(/\.png$/) != null)
			{
				var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
				var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
				var imgTitle = (myImage.title) ?
				             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
				var imgStyle = "display:inline-block;" + myImage.style.cssText
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				          + " style=\"" + "width:" + myImage.width
				          + "px; height:" + myImage.height
				          + "px;" + imgStyle + ";"
				          + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				          + "(src=\'" + myImage.src + "\', sizingMethod='image');\"></span>"
				myImage.outerHTML = strNewHTML;
				i--;
			}
		}
	}
}

function scrollImages()
{
	$('.bodyText .scrollImages').each(function(){
		var scrollImages = this;
	    if($(this).find('.imageTable:first').width() > $(this).width()){

	        $(this).before('<div class="scroll-butts"><a href="#" class="scroll-butt-left" style="height:'+$(this).find('.imageTable:first').height()+'px;"></a><a href="#" class="scroll-butt-right" style="height:'+$(this).find('.imageTable:first').height()+'px;"></a></div>');
	        var scrollAction = $(this).prev();
	        $(this).prev().find('.scroll-butt-left').click(function(){
	            $(scrollImages).scrollTo('-='+($(scrollImages).find('img:first').width()+$(scrollImages).find('.imageSpace:first').width())+'px', 0, {duration:400});
				return false;
			});
	        $(this).prev().find('.scroll-butt-right').click(function(){
	            $(scrollImages).scrollTo('+='+($(scrollImages).find('img:first').width()+$(scrollImages).find('.imageSpace:first').width())+'px', 0, {duration:400});
				return false;
			});
			
			$(this).parent().mouseover(function(){
			    $(scrollAction).show();
			});
			$(this).parent().mouseout(function(){
			    $(scrollAction).hide();
			});

	    } else {
			$(scrollImages).removeClass('scrollImages');
	    }
	});
	fixAllPNGs(); // Diese Funktion darf erst zuletzt ausgeführt werden!
}


// Für Navigation - Drop-Down
var TimeAktiv;

// Wenn Maus ausserhalb vom Menü, alle Layer nach 0,5 Sekunde ausblenden
function CheckMouseOut()
{
	if(TimeAktiv) window.clearTimeout(TimeAktiv);
	TimeAktiv = window.setTimeout('HideSubmenus()',500);
}

// Untermenü ausblenden
function HideSubmenus()
{
	if(TimeAktiv) window.clearTimeout(TimeAktiv);
	$('#menu ul.submenu:visible').slideUp();
}

$(document).ready(function(){
	$('.zoombox').zoombox();

	$('#menu > ul > li > a').mouseover(function(){
      	HideSubmenus();
	    $(this).parent().find('ul.submenu').show();
	    $(this).parent().find('ul.submenu').width($(this).parent().find('ul.submenu').width()); // IE Bug beheben und Breite eintragen
	});
	$('#menu ul.submenu').mouseover(function(){
		window.clearTimeout(TimeAktiv);
	});
	$('#menu > ul > li, #menu ul.submenu').mouseout(function(){
	    CheckMouseOut();
	});

});

window.onload = scrollImages;

