$(document).ready(function()
{
	$('.return_false').click(function() { return false; });
	$('.target_blank').attr('target', '_blank');
	
	$('.readmore_content').hide();
	$('.readmore').click(function() { $($(this).attr('href')).toggle(); return false; });
	
	initMenu();
	initDropdowns();
	convertDlLists();
	initInpageJumps();
	initFaqSelector();
	initSubheader();
	
	if ($.browser.msie && parseInt($.browser.version) > 0 && parseInt($.browser.version) < 7) {
		$(document).pngFix();
	}	
});

function naarTop()
{
	$('html').scrollTop(0); 
}

function initSubheader()
{
	$('#subheader_slider').cycle({
		fx: 'scrollLeft',
		timeout: 8500,
		pause: true,
		pager: '#subheader_slider_nav'
	});
}

function initFaqSelector()
{
	$('#faq_select').change(function() {
		if ($(this).val() == '') {
			$('#faq_select_caption').show();
		} else {
			$('#faq_select_caption').hide();
		}
		
		$('.faq_container').hide();
		$('#faq_' + $(this).val()).show();
	});
}

function initMenu()
{
	var width, parentWidth;
	
	$('#menu').dropDownMenu({timer: 500, parentMO: 'parent-hover', childMO: 'child-hover1'});
	
	$('#menu li ul').each(function() {
		width = $(this).width();
		parentWidth = $(this).parent().width();
		
		if (width < parentWidth) {
			$(this).width(parentWidth);
		}
	});
}

function initInpageJumps()
{
    var urlparts = document.location.href.split('?');
    
    if (urlparts[1] != undefined) {
    	var target = $('#' + urlparts[1]);
    	var targetType = $(target).attr('tagName').toLowerCase();
        
        switch (targetType) {
        	case 'dt':
        		target.click();
        		
        		var targetParts = urlparts[1].split('-');
        		$('#faq_select').val(targetParts[0]);
        		$('#faq_' + targetParts[0]).show();
        		$('#faq_select_caption').hide();
        		break;
        	default:
                $('#content_main_container div').removeClass('highlite');
        		$('#' + urlparts[1]).addClass('highlite');
        }
    	
        $.scrollTo(target, 250);
    }
}

function initDropdowns()
{
	$('.select').each(function() {
		var select = $(this);
		var dropdown = $('#' + $(this).attr('id') + '_dropdown');
		
		$(this).click(function(){
			if ($.browser.msie) {
				$(document).click(function(){ $(dropdown).hide(); });
			} else {
				$(window).click(function(){ $(dropdown).hide(); });
			}
			
			$(dropdown).show();
			return false;
		});
		
		$(dropdown).find('a').click(function(){
			$(select).html($(this).html());
			
			$('.select_target_content').hide();
			$('#' + $(this).attr('class')).show();
			
			$(dropdown).hide();
			$(window).unbind('click');
			return false;
		});
	});
}

function convertDlLists(action)
{
	if (typeof action != 'undefined' && !action)
	{
		$("dt").unbind();
		$("dt").css("background-image", "url(/css/images/bullet-minus.gif)");
		$("dd").show();
	}
	else
	{
		$("dt").css("background-image", "url(/css/images/bullet-plus.gif)");
		$("dd").hide();
		
		$("dl").each(function()
		{
			$(this).children("dt").each(function()
			{
				$(this).click(function()
				{
					$(this).parent().children("dt").removeClass('active_dt');
					
					if ($(this).next().css("display") == "block")
					{
						$(this).next().hide();
						$(this).css("background-image", "url(/css/images/bullet-plus.gif)");
					}
					else
					{
						$(this).parent().children("dt").each(function()
						{
							$(this).css("background-image", "url(/css/images/bullet-plus.gif)");
						});
						
						$(this).parent().children("dd").each(function()
						{
							$(this).hide();
						});
						
						$(this).next().show();
						$(this).css("background-image", "url(/css/images/bullet-minus.gif)");
						$(this).addClass('active_dt');
					}
					
					//$("#page").height('auto');
					//initPageHeight();
				});
			});
		});
	}
}

