	// needs editing

$(document).ready(function(){

	$('#rh-menu a').each(function(){
		if ($(this).attr('xhref') !== undefined) {
			$(this).attr('href', $(this).attr('xhref'))
			$(this).removeAttr('xhref');
		}
	});
		
	destroyInlineWindow = function() {
		$('#rh-inlinewindow-content, #rh-inlinewindow-overlay, #rh-inlinewindow-shadow').remove();
	}

	$(document).keydown(function(e){
		if (e.which == 27) {
			destroyInlineWindow();
		}
	})

	jQuery.fn.displayInlineWindow = function() {    
		
		var o = $(this[0]) 
		var a = arguments[0] || {}; 
		
		var overlayWidth = a.width;
		var overlayHeight = a.height;
	    var overlayIframeId = a.id; if (overlayIframeId != "") overlayIframeId = ' id=\"' + overlayIframeId + '\" ';

		// where does the content come from
		var overlayContent;

		if (o.html() != null) {
			overlayContent = o.html();
		}
		else if (a.content != undefined) {
			overlayContent = a.content;
		}
		else if (a.url != undefined) {
			overlayContent = "<iframe scrolling=\"no\" frameborder=\"0\" " + overlayIframeId + " style=\"border:0px;width:" + overlayWidth + "px;height:" + overlayHeight + "px\" src=\"" + a.url + "\"></iframe>";
			//overlayContent = '<iframe scrolling="no" frameborder="0" style="border:0px;width:'+ overlayWidth +'px;height:'+ overlayHeight +'px" src="' + a.url + '"></iframe>';
			//$.get(a.url, function(data){
			//	overlayContent = data;
			//})
		}
		
		//console.log((overlayWidth=='undefined'));

		if (overlayWidth == undefined && overlayHeight == undefined) {

			$('body').append('<div id="overlayDimensions" style="visibility:hidden;position:absolute;">'+ overlayContent +'</div>');

			overlayWidth	= $('#overlayDimensions').width();
			overlayHeight	= $('#overlayDimensions').height();
			
			//console.log(overlayWidth)

			// destroy
			$('#overlayDimensions').remove();

		}

		var top = ($(window).height()-overlayHeight )/2+$(window).scrollTop();
		if (top < 20) top = 20

		$('body').append( 
			
			$('<div/>', {id: 'rh-inlinewindow-content'})
				.html(overlayContent)	
				.css({
					'position':			'absolute',
					'top':				'0px',
					'left':				'0px',
					'background-color':	'#FFF',
					'background-image':	'url(/images/2011/inlinewindow/dialog-bg.png)',
					'background-repeat':'repeat-x',
					'z-index':			'120',
					'width':			overlayWidth+'px',
					'height':			overlayHeight+'px',
					'left':				( $(document).width()-overlayWidth )/2+'px',
					'top':				top+'px'								
				})
			
					
			
		);	

		$('body').append( 
			
			$('<div/>', {id: 'rh-inlinewindow-shadow'})
				.css({
					'position':			'absolute',
					'top':				'0px',
					'left':				'0px',
					'z-index':			'119',
					'width':			overlayWidth+26+'px',
					'height':			overlayHeight+26+'px',
					'left':				( $(document).width()-overlayWidth )/2-13+'px',
					'top':				top-13+'px'	
				})
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'top':				'0px',
							'left':				'0px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-north-west-corner.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'top':				'0px',
							'right':			'0px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-north-east-corner.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'bottom':			'0px',
							'left':				'0px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-south-west-corner.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'bottom':			'0px',
							'right':			'0px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-south-east-corner.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'top':				'0px',
							'left':				'0px',
							'margin-top':		'23px',
							'height':			overlayHeight-20+'px',
							'width':			'13px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-west.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'top':				'0px',
							'right':			'0px',
							'margin-top':		'23px',
							'height':			overlayHeight-20+'px',
							'width':			'13px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-east.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'top':				'0px',
							'left':				'0px',
							'margin-left':		'23px',
							'height':			'13px',
							'width':			overlayWidth-20+'px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-north.png')
				)
				.append(
					$('<img/>')
						.css({
							'position':			'absolute',
							'bottom':			'0px',
							'left':				'0px',
							'margin-left':		'23px',
							'height':			'13px',
							'width':			overlayWidth-20+'px'
						})
						.attr('src', '/images/2011/inlinewindow/Dialog-shadow-south.png')
				)							
		);	

		// opacity
		$('body').append(
			
			$('<div/>', {id: 'rh-inlinewindow-overlay'})
			.css({
				'display':			'none',
				'position':			'absolute',
				'top':				'0px',
				'left':				'0px',
				'z-index':			'48',
				'width':			$(document).width()+'px',
				'height':			$(document).height()+'px'

			})
			.css('background-color', '#000')
			.fadeTo(
				'slow',
				'0.4',
				function(){
					$('#rh-inlinewindow-content, #rh-inlinewindow-shadow').show()
				}
			)
		);
	
		if (a.closeonblur != undefined) {
			if (a.closeonblur == true)
			{
				$('#rh-inlinewindow-overlay').click(
				function(){destroyInlineWindow()}
				)
			}
		} else {
			$('#rh-inlinewindow-overlay').click(
				function(){destroyInlineWindow()}
			)
		}

	} 
			



	// pngfix
	//$(document).pngFix();
	
	// find the highlighted menu
	/*$('#rh-menu .menu-item a').each(function(){
		
		if (location.pathname == $(this).attr('href'))
		{
			$(this).parents('.menu-item').attr('selected', 'true').css('background-color', '#C83333');
			//$(this).parents('.menu-item').find('h3 a').css('color', '#000000');
		}

	});*/

	// menuhover
	$('#rh-menu .menu-item').hover(
		
		function() { 
			
			if (!($.browser.msie == true && ($.browser.version == '6.0' ||$.browser.version == '7.0') )  ) {

				// 
				var intOverlayH3Width		= $('em', this).width();		
				var intOverlayPositionTop	= $('em', this).offset().top-11;
				var intOverlayPositionLeft	= $('em', this).offset().left-12;

				if ($(this).find('ul').children().length > 0) {
					var intOverlayWidth		= $('ul', this).width()+14;
					var intOverlayHeight	= $('ul', this).height()+58;
				
				} else if ($(this).find('div').children().length > 0) {
					var intOverlayWidth		= $('div', this).width()+34;	
					var intOverlayHeight	= $('div', this).height()+66;	
				
				} else {
					var intOverlayWidth		= $(this).width()+14;
					var intOverlayHeight	= $(this).height()+13;		

				}

				if (typeof(intAdditionPixels) + "" == "undefined") intAdditionPixels = -25;
				
				// append an overlay in order to place shadows
				$('body').append( $('<div/>', {id: 'rh-menu-overlay'})
					.css({
						'z-index'	: '98',
						'position'	: 'absolute',
						'top'		: intOverlayPositionTop + 'px',
						'left'		: intOverlayPositionLeft + 'px',
						'width'		: intOverlayWidth + 'px',
						'height'	: intOverlayHeight + 'px'
					})
				);						


				// h3 shadow

					// top
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-x').css({'position':'absolute', 'top':'0px', 'left':'4px', 'background-position':'0 -1252px', 'background-repeat':'repeat-x', 'height':'2px', 'width':(intOverlayH3Width+16)+'px', 'z-index':'99'}) )

					// corner
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'top':'0px', 'left':(intOverlayH3Width+20)+'px', 'background-position':'0 -128px', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'top':'0px', 'left':'0px', 'background-position':'0 -192px', 'height':'4px', 'width':'4px', 'z-index':'99'}) )


				// right
				if ($(this).is('.float-right')) {
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'14px', 'right':(intOverlayH3Width+38+intAdditionPixels)+'px', 'background-position':'0 0', 'background-repeat':'repeat-y', 'height':(intOverlayHeight-28)+'px', 'width':'13px', 'z-index':'99'}) )
					// corner, bottom right
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'bottom':'0px', 'right':(intOverlayH3Width+39+intAdditionPixels)+'px', 'background-position':'0 0', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-x').css({'position':'absolute', 'bottom':'-1px', 'right':(intOverlayWidth-20-intOverlayH3Width)+'px', 'background-repeat':'repeat-x', 'background-position':'0 -1189px', 'height':'13px', 'width':(intOverlayWidth-28)+'px', 'z-index':'99'}) )

					// corner, bottom left
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'bottom':'0px', 'right':(intOverlayWidth+25+intAdditionPixels+intOverlayH3Width)+'px', 'background-position':'0 -64px', 'height':'14px', 'width':'14px', 'z-index':'99'}) )

					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'37px', 'right':(intOverlayWidth+37+intAdditionPixels+intOverlayH3Width)+'px', 'background-position':'-63px 0','background-repeat':'repeat-y', 'height':(intOverlayHeight-51)+'px', 'width':'2px', 'z-index':'99'}) )

					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'top':'33px', 'right':(intOverlayWidth+35+intAdditionPixels+intOverlayH3Width)+'px', 'background-position':'0 -192px', 'height':'4px', 'width':'4px', 'z-index':'99'}) )

					
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-x').css({'position':'absolute', 'top':'33px', 'right':(intOverlayWidth-2)+'px', 'background-repeat':'repeat-x', 'background-position':'0 -1252px', 'height':'2px', 'width':(intOverlayWidth-intOverlayH3Width-36)+'px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'4px', 'right':(intOverlayWidth-2)+'px', 'background-position':'-63px 0', 'background-repeat':'repeat-y', 'height':(intOverlayHeight-18)+'px', 'width':'2px', 'z-index':'99'}) )


				// left
				} else if ($(this).find('ul').children().length > 0) { 
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'top':'33px', 'right':'0px', 'background-position':'0 -128px', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'bottom':'0px', 'right':'0px', 'background-position':'0 0', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'bottom':'0px', 'left':'0px', 'background-position':'0 -64px', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-x').css({'position':'absolute', 'top':'33px', 'left':(intOverlayH3Width+22)+'px', 'background-repeat':'repeat-x', 'background-position':'0 -1252px', 'height':'2px', 'width':(intOverlayWidth-intOverlayH3Width-36)+'px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-x').css({'position':'absolute', 'bottom':'-1px', 'left':'14px', 'background-repeat':'repeat-x', 'background-position':'0 -1189px', 'height':'13px', 'width':(intOverlayWidth-28)+'px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'47px', 'right':'-1px', 'background-position':'0 0', 'background-repeat':'repeat-y','height':(intOverlayHeight-35-26)+'px', 'width':'13px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'14px', 'left':(intOverlayH3Width+22)+'px', 'background-position':'0 0','background-repeat':'repeat-y', 'height':'19px', 'width':'13px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'4px', 'left':'0px', 'background-position':'-63px 0', 'background-repeat':'repeat-y','height':(intOverlayHeight-18)+'px', 'width':'2px', 'z-index':'99'}) )

				// none
				} else {
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'bottom':'0px', 'left':'0px', 'background-position':'0 -64px', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-icon').css({'position':'absolute', 'bottom':'0px', 'right':'0px', 'background-position':'0 0', 'height':'14px', 'width':'14px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-x').css({'position':'absolute', 'bottom':'-1px', 'left':'14px', 'background-repeat':'repeat-x', 'background-position':'0 -1189px', 'height':'13px', 'width':(intOverlayWidth-28)+'px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'14px', 'right':'-1px', 'background-position':'0 0', 'background-repeat':'repeat-y','height':(intOverlayHeight-28)+'px', 'width':'13px', 'z-index':'99'}) )
					$('#rh-menu-overlay').append( $('<div/>').addClass('sprite-y').css({'position':'absolute', 'top':'4px', 'left':'0px', 'background-position':'-63px 0', 'background-repeat':'repeat-y','height':(intOverlayHeight-18)+'px', 'width':'2px', 'z-index':'99'}) )
				}
				
				$('#rh-menu-overlay').show();

			}
			else {
	
				$('#rh-top').css('z-index', '99')


			}

			$(this).css('background-color', '#F4F3F3');
			$('em a', this).css('color', '#000000');

			if ($(this).is('.float-right')) {

				$('ul', this).css( { 'display':'block', 'position':'absolute', 'right':'0px' } ); 
				$('div', this).css( { 'display':'block', 'position':'absolute', 'right':'0px' } ); 
			
			} else {
				
				$('ul', this).css( { 'display':'block', 'position':'absolute' } ); 
				$('div', this).css( { 'display':'block', 'position':'absolute' } ); 
			
			}

		},
		
		function() { 
			
			$('#rh-menu-overlay').remove();
			
			if ($(this).attr('selected') == 'true') {
				$(this).css('background-color', '#C83333');
			} else {
				$(this).css('background-color', 'transparent')
			}
			$('em a', this).css('color', '#ffffff');
			/* moussa */
			$('ul', this).css('display', 'none'); 
			$('div', this).css('display', 'none'); 
			/* /moussa */

		}

	);

	// OK

	// make li hover clickable
	$('#rh-menu .menu-item li').click(function(){ location.href = $(this).find('a').attr('href') });

	// sets onclick handler on floating search button text
	$('.search-button-text').click(function(){ $(this).parent().find('form').submit() });

	// sets focus on input field when clicking magnifying glass
	$('form img.search-img').click(function(){ $(this).parent().find('.search-input').focus() });
	
	// changes the lock icon when hovering mit rorbinhus
	$('#rh-menu .menu-item').hover(
		function(){	$('#rh-icon-lock', this).attr('src', '/images/2011/menu/open-lock_hover.png') },
		function(){	$('#rh-icon-lock', this).attr('src', '/images/2011/menu/open-lock.png') }					
	);

});
