// CONFIGURABLE CONSTANTS

var menuID = 'menu-new';			// the ID of the UL menu
var M2mp = 20;						// optional - the padding or margin of the 2nd menu items

var isIE = $.browser.msie && $.browser.version < 7;

// INITIALIZE MENU
// set the events (onmouseover, onmouseout) on the menu
// set the width of the menu items (LI) by the width of its wrap (UL)

function ieHomeFix (imgObj)
{
	if (imgObj.height > 0)
	{
		$('#header #hotel_logo a').attr ("src", "fileadmin/tmpl/css/blank.gif");
		$('#header #hotel_logo a').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="'+image+'")' } );
	}
}

function docReady () 
{
		
	// 1st Menu
	$('#' + menuID + ' > li').each(
	function() 
	{
		// Set the mouse events if the 2nd UL submenu exists
		if (this.getElementsByTagName('UL')[0] && this.getElementsByTagName('UL')[0].tagName == 'UL') 
		{
			this.onmouseover = function() 
			{
				/* stay parent menu rollover */
				this.className = 'stayrollover';
				over(this.getElementsByTagName('IMG')[0].name);
				this.getElementsByTagName('UL')[0].style.visibility = "visible";
			}
			this.onmouseout = function() 
			{
				/* unstay parent menu rollover */
				this.className = '';
				out(this.getElementsByTagName('IMG')[0].name);
				this.getElementsByTagName('UL')[0].style.visibility = "hidden";
			}
		}

		// 2nd Menu
		var M2AwG = 0;
		$("> ul > li", this).each(
			function() 
			{

				// Set the mouse events if the 3rd UL submenu exists
				if (this.getElementsByTagName('UL')[0] && this.getElementsByTagName('UL')[0].tagName == 'UL') 
				{
					this.onmouseover = function() 
					{
						this.getElementsByTagName('UL')[0].style.visibility = "visible";
					}
					this.onmouseout = function() 
					{
						this.getElementsByTagName('UL')[0].style.visibility = "hidden";
					}
				}

				// Get the A width
				var M2Aw = $('> a', this).width();
				if (M2Aw > M2AwG)
				{
					M2AwG = M2Aw;
				}
			}
		);

		// 2nd Menu - Apply width of the greater A to UL and its A tags
		//		and checkout the 3rd Menu
		$("> ul > li", this).each(
			function() 
			{
				$("> a", this).css( {display: 'block', width: M2AwG+'px'} );
				$(this).parent().css( {width: (M2AwG+M2mp)+'px'} );

				// 3nd Menu
				var M3AwG = 0;
				$("> ul > li", this).each(
					function() 
					{
						// Get the A width
						var M3Aw = $('> a', this).width();
						if (M3Aw > M3AwG)
						{
							M3AwG = M3Aw;
						}
					}
				);

			// 3rd Menu - Apply width of the greater A to UL and its A tags
			$("> ul > li", this).each(
				function() 
				{
					$("> a", this).css( {display: 'block', width: M3AwG+'px'} );
					$(this).parent().css( {width: (M3AwG+M2mp)+'px', left: (M2AwG+M2mp)+'px'} );
				}
			);

		});

		// Returns the CSS styles back for the IE7 fixing
		$(this).css( { 'float': 'left', clear: 'none' } );
		// MSIE 6 fix
		$(this).css( { paddingRight: '1px' } );
	});

	// MSIE 6 fix back
	$('#' + menuID + ' > li').css( { paddingRight: '0px' } );
	// Returns the CSS styles back for the IE7 fixing
	$('#header #' + menuID).css( { visibility: 'visible', overflow: 'visible' } );


	
	try
	{
		//alert ("l: " + $('#flashcontent').length);
		if (typeof(SWFObject) != 'undefined' && $('#flashcontent').length > 0)
		{
			//var so = new SWFObject('fileadmin/tmpl/flash/heilbad-header.swf', "mymovie", '930', '288', '6', '#ffffff');
			var so = new SWFObject('fileadmin/tmpl/flash/heilbad-header.swf', "mymovie", '930', '280', '0', '#ffffff');
			so.addParam('quality', 'high');
			so.addParam('scale', 'noScale');
			//so.addParam('wmode', 'transparent');
			so.write("flashcontent");
		}
	} 
	catch (e)
	{}
	
	

	
	if (isIE)
	{

		// FIX msie6 of the broken header png hotel icons
		$('#header #hotellinks li:eq(0)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_neydharting.png")' } );
		$('#header #hotellinks li:eq(1)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_heilbrunn.png")' } );
		$('#header #hotellinks li:eq(2)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_weissenbach.png")' } );
		$('#header #hotellinks li:eq(3)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_weissbriach.png")' } );
		$('#header #hotellinks li:eq(4)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_agatenhof.png")' } );
		$('#header #hotellinks li:eq(5)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_stjosef.png")' } );
		$('#header #hotellinks li:eq(6)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_oberzeiring.png")' } );
		//$('#header #hotellinks li:eq(7)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_raxblick.png")' } );
		$('#header #hotellinks li:eq(7)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_salzerbad.png")' } );
		$('#header #hotellinks li:eq(8)').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="fileadmin/tmpl/imgs/hotel_icon_bsl.png")' } );
		
		var bookingSrc = $('.graphic img[@title=Buchungsanfrage]').attr('src');
		$('.graphic img[@title=Buchungsanfrage]').attr ("src", "fileadmin/tmpl/css/blank.gif");
		$('.graphic img[@title=Buchungsanfrage]').css( { 'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src="'+bookingSrc+'")' } );
	/*
		// Home link FIX for msie6
		var hotel = $('link');
		if (hotel.length >= 7)
		{
			hotel = hotel[6];
			hotel = hotel.href.split('/');
			hotel = hotel[hotel.length-1];
			hotel = hotel.split('.');
			hotel = hotel[0];
			var image = 'fileadmin/tmpl/imgs/' + hotel + '_home.png';
			var imgObj = new Image(); 
			imgObj.complete = ieHomeFix (imgObj);
			imgObj.src = image;
			
			
		}

		*/
	}

	
	
}

if (!isIE)
{
	$(document).ready(docReady);
}
else
{
	window.onload = function()
	{
		$(document).ready(docReady);
	}
}