function moveButtoncontainer()
{
	jQuery('.addreactionblock .formholder, .mailafriendblock .formholder').each(
		function()
		{
			var t = this;
			var buttonContainer = jQuery('.button-container', t);
			
			jQuery(t).after(buttonContainer);
		}
	);
}

function makeButton()
{
	jQuery('.searchresultsblock .pages .previous, .searchresultsblock .pages .next, .jobreactionblock a, .button-container input, .button-container a, .buttons input, .quickorder input, .checkout a, .button-container ul li a, .categorybutton, .mailafriendblock a, .mailagentblock a, .clearbasket a, .basketaddblock a, .objectbasketblock .remove a, .button-container .button').each(function()
	{
		var button = this;
		if(button.type != 'hidden') 
		{
		    jQuery(button).wrap('<span class="candywrapper"></span>');
		} else {
		jQuery(button).css('display','none');
		}
	});
}

function changeForm()
{
	jQuery('.surveycontainer .q_multipleresponse').each(
		function() 
		{
			
			var t = this;
			var newDiv = jQuery('<div class="checkboxes">');
			var spanText = jQuery('.question-text',t);
			var getTables = jQuery('table',t);
			var getSelect = jQuery('select',t);
			var breakIt  = jQuery('br',t);             
			var element = new Array;
			var type = new Array;
			var aantalChilds;
			
			if ((getTables.length+getSelect.length)==0)
			{
				breakIt.remove();
				aantalChilds = t.childNodes.length;
				
				for (var x = 0; x<aantalChilds;x++)
				{
					if (t.childNodes[x].tagName=='INPUT')
					{    
						element[x] = t.childNodes[x];
						type[x] = t.childNodes[x].tagName;
					}
					
					if (t.childNodes[x].tagName=="LABEL")
					{
						element[x] = t.childNodes[x];
						type[x] = t.childNodes[x].tagName;
					}
				}
				
				for (var x = 0; x<aantalChilds;x++)
				{
					if(element[x] =='object');                        
					{
						newDiv.append(element[x]);
					}
					if(type[x] == 'LABEL')
					{
						newDiv.append(jQuery('<br>'));
					}
				}
					
				spanText.after(newDiv);
			}
		}
	);
}

function changeFormButton()
{
    jQuery('.surveycontainer').each( function() 
	{
        var t=this;
        var formQuestions = jQuery('.surveyquestion',t);
        if (formQuestions.length==0) 
		{
            var plainText = jQuery('.plain-text', t);
            if(plainText)
            {
                jQuery('.button-container', t).addClass("firstbox");
            }
        }
    });
}

function hideBlocks()
{
    if(jQuery('.mm_wysiwyg_container').length == 0) 
	{
		jQuery('#p_o, #l_m, #to').each(function()
		{
			var t=this;
			
			var aantal = jQuery('.block-output', t).length;
			if(aantal==0) 
			{
				jQuery(t).hide();
			}
		});
	} 
}

function DisableButton()
{
	jQuery('.candywrapper a, .candywrapper input').not(jQuery('#header_nav .candywrapper a, #header_nav .candywrapper input')).mouseover(function()
	{
		var disabled = this.getAttribute('disabled');
		if(!disabled)
		{
			jQuery(this).addClass('linkhover')
		}
	}).mouseout(function()
	{
		jQuery(this).removeClass('linkhover')
	});
	jQuery('.candywrapper').not(jQuery('#header_nav .candywrapper')).mouseover(function()
	{
		var disabled = this.firstChild != null ? this.firstChild.getAttribute('disabled') : false;
		if(!disabled)
		{
			jQuery(this).addClass('hover')
		}
	}).mouseout(function()
	{
		jQuery(this).removeClass('hover')
	});
}

function setHeight()
{
	var heightTotal = jQuery('#training_overzicht').height();
	var po = jQuery('#p_o').height();
	var lm = jQuery('#l_m').height();
	var to = jQuery('#to').height();
	
	if(heightTotal > po)
	{
		jQuery('#po_con').height((heightTotal - 5));
	}
	
	if(heightTotal > lm)
	{
		jQuery('#l_m').height((heightTotal - 5));
	}
	
	if(heightTotal > to)
	{
		jQuery('#to_con').height((heightTotal - 5));
	}
}

function toggleTraining()
{
    if(jQuery('.mm_wysiwyg_container').length == 1) 
	{
		jQuery('#main_training').css('display', 'block');
	}
	else
	{
		jQuery('#mt_training').each(
			function(){
				var t = jQuery(this);
				var header = jQuery(t);
				var list = jQuery('#main_training');
				header.click(function(){
					list.toggle();
			});
		});	
	}
}

var min= 9;
var max= 16;
function increaseFontSize() {
   var p = jQuery('.block-output').not(jQuery('#header .block-output'));
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function decreaseFontSize() {
   var p = jQuery('.block-output').not(jQuery('#header .block-output'));
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function defaultFontSize()
{
   var p = jQuery('.block-output').not(jQuery('#header .block-output'));
	for(i=0;i<p.length;i++) 
	{
	  p[i].style.fontSize = "12px"
	}   
}

/** Customer Specific **/
function moveBlock()
{
	jQuery('#sub_content').each(function()
	{
		var t = jQuery(this);
		var steps = jQuery('.registrationblock div.steps', t);
		var menu = jQuery('#subc_menu .blocks-blockholder', t);
		menu.append(steps);
	});
}

jQuery(function(){
	moveBlock();
	toggleTraining();
	hideBlocks();
	makeButton();
	moveButtoncontainer();
	changeForm();
	changeFormButton();
	setHeight();
	jQuery('.surveycontainer div:eq(1)').addClass('firstDiv');
	jQuery('#sub_content_left .block-output div:eq(0)').addClass('firstDiv');
	jQuery('#sub_content_left .block-output ul:eq(0)').addClass('firstUl');
	DisableButton();
    jQuery('.coursedisplayblock li.tab').mouseover(function(){jQuery(this).addClass('hover')}).mouseout(function(){jQuery(this).removeClass('hover')});
});