/**
 * @author maikelpl@myopera.com
 */

$(document).ready(function(){
	
	preLoadImages('/images/2012/groepenmenu_aH.jpg','/images/2012/groepenmenu_spanH.jpg');
	
	/*headerimages*/
	if($('#headerpictures li').length > 1){
		$('#headerpictures').innerfade({
			animationtype: 'fade',
			speed: 2000,
			timeout: 5000,
			type: 'random',
			containerheight: '268px'
		});
	}
	
	/*groepen menu*/
	addSpansToGroepenMenuLinks();
	setGroepenMenus();
	setGroepenMenusPositions();
	setGroepenMenusSelectedItems();
	fixFooterZindex();
	
	setContentHeights();
	
});//end document ready

$(window).load(function(){

	

});//end window load

/*** functions ***/
function setContentHeights(){
	$('#tekstcontent').attr('style','');
	$('#actionframe').attr('style','');
	var tekstheight = $('#tekstcontent').height()+35;
	var actionheight = $('#actionframe').height()+35;
	if(tekstheight > actionheight){
		$('#actionframe').css('min-height',tekstheight + 'px');
		$('#tekstcontent').css('min-height',tekstheight + 'px');
	}
	else {
		$('#tekstcontent').css('min-height',actionheight + 'px');
		$('#actionframe').css('min-height',actionheight + 'px');
	}
}
/*groepen menu*/
function setGroepenMenusSelectedItems(){
	if($('.controlsubsubmenuitemselected').length > 0){
		$('.controlsubsubmenuitemselected').parent().parent().addClass('controlsubmenuitemselected');
	}
	if($('.controlsubmenuitemselected').length > 0){
		$('.controlsubmenuitemselected').parent().parent().addClass('artikelmenuitemselected');
	}
}

function fixFooterZindex(){
	$('.artikelmenu').mouseenter(function(){
		$('#footer').css('z-index','15');
	});
	$('.artikelmenu').mouseleave(function(){
		$('#footer').css('z-index','30');
	});
}
function addSpansToGroepenMenuLinks(){
	$('#controlmenu > li > a').each(function(){
		var thishtml = $(this).html();
		$(this).html('<span>' + thishtml + '</span>');
	});
}
function setGroepenMenus(){
	var cam_length = $('#groepenmenu_box_buffer #controlmenu > li').length;
	var menutop_length = Math.floor(cam_length/2);
	var menubottom_length = cam_length - menutop_length;
	var ctr = 0;
	
	var content_top = '';
	var content_bottom = '';
	
	content_top += '<ul class="artikelmenu">';
	content_bottom += '<ul class="artikelmenu">';
	
	$('#groepenmenu_box_buffer #controlmenu > li').each(function(){
		if($(this).hasClass("controlmenuitem") || $(this).hasClass("controlmenuitemselected")){
			if(ctr < menutop_length){
				if($(this).hasClass('controlmenuitemselected')){
					content_top += '<li class="artikelmenuitemselected">' + $(this).html() + '</li>';
				}
				else {
					content_top += '<li class="artikelmenuitem">' + $(this).html() + '</li>';
				}
			}
			else {
				if($(this).hasClass('controlmenuitemselected')){
					content_bottom += '<li class="artikelmenuitemselected">' + $(this).html() + '</li>';
				}
				else {
					content_bottom += '<li class="artikelmenuitem">' + $(this).html() + '</li>';
				}
			}
			ctr+=1;
		}
	});
	$('#groepenmenu_box_top').append(content_top);
	$('#groepenmenu_box_bottom').append(content_bottom);
	$('#groepenmenu_box_buffer').remove();
}
function setGroepenMenusPositions(){
	var menutop_width = $('#groepenmenu_box_top ul.artikelmenu').width();
	var menubottom_width = $('#groepenmenu_box_bottom ul.artikelmenu').width();
	$('#groepenmenu_box_top ul.artikelmenu').css('left',((984 - menutop_width)/2) + 'px');
	$('#groepenmenu_box_bottom ul.artikelmenu').css('left',((984 - menubottom_width)/2) + 'px');
}

//preload images
function preLoadImages(arg){$.preLoadImages(arg);}
(function($){var cache=[];$.preLoadImages=function(){var args_len=arguments.length;for(var i=args_len;i--;){var cacheImage=document.createElement('img');cacheImage.src=arguments[i];cache.push(cacheImage);}}})(jQuery)

