$(document).ready(function() {
	
	if($(".infoblock").text().length < 10) {
		$(".infoblock").css("display", "none");
	}
	
  $('ul.subsubnav').each(function(){
    var UlObj = $(this);
    $('li',$(this)).each(function(){
      if($(this).hasClass('current')){
        UlObj.addClass('current-item');
      }
    });
  });
  
  $('.subNavigation li').mouseover(function() {
    $('ul.subsubnav').css('display', 'none');
    $(this).find("ul").css('display', 'block');
  }).mouseout(function(){
    $(this).find("ul").css('display', 'none');
    $('ul.subsubnav.current-item').css('display', 'block');
  });
  
	$("#footer").css("overflow", "visible");		
	init();
});

/**
*
* Functions footer tabs
*
**/
	
function init() 
{
	var aBlocks = new Array("login-block", "newsletter-block");
	
	$(".login-block").attr("style","clip:rect(0px 110px 25px 0px)");
	$(".newsletter-block").attr("style","clip:rect(0px 325px 25px 0px)");
	
	setClickHandler(aBlocks[0], aBlocks);
	setClickHandler(aBlocks[1], aBlocks);
}

function setClickHandler(BlockClassName, aBlocks)
{
	$("." + BlockClassName + " img").click(function () {
		autoHide(BlockClassName, aBlocks);
		
		var elementHeight = parseInt($("." + BlockClassName).css("height"));
		
  	if(elementHeight > 25) {
    	hideBlock(BlockClassName);
  	} else {
    	showBlock(BlockClassName);
    }		
	});
}

function showBlock(BlockClassName) {
	if(BlockClassName == "login-block") {
		var currentClipValue  = "rect(0px 320px 25px 0px)";
		var animatedClipValue = "rect(0px 320px 220px 0px)";
	}

	if(BlockClassName == "newsletter-block") {
		var currentClipValue  = "rect(0px 440px 220px 0px)";
		var animatedClipValue = "rect(0px 440px 220px 0px)";
	}
	
	$("." + BlockClassName).css("z-index","10");
	$("." + BlockClassName).css("overflow","visible");
	$("." + BlockClassName).attr("style","clip:" + currentClipValue);
	 		  		
	$("." + BlockClassName).animate({ 
      bottom: "0px",
      height: "220px",
      width: "320px",
      "clip":animatedClipValue
    }, 1500, function() { 
    	$(this).css("z-index", 2);	
    }); 
}

function hideBlock(BlockClassName) { 		
	var animatedClipValue = "rect(0px 320px 25px 0px)";
	
	if(BlockClassName == "newsletter-block") {
		animatedClipValue = "rect(0px 325px 25px 0px)";
	}

	$("." + BlockClassName).animate({ 
    	bottom: "0px",
    	height: "25px",
      "clip":animatedClipValue
  	}, 1500, function() { 
  		      		
  		if(BlockClassName == "login-block") {
  			$(".login-block").css("width","110px");
  			$(".login-block").css("overflow","hidden");
  			$(".login-block").css("z-index", 5);
  		}
  		
  		if(BlockClassName == "newsletter-block") {
  			$(".newsletter-block").css("width","205px");
  			$(".newsletter-block").css("overflow","hidden");
  			$(".newsletter-block").css("z-index", 4);
  		} 		        		
  	});
}

function autoHide(CurrentBlock, aBlocks)
{
	for(var i = 0; i < aBlocks.length; i++) {
		if(CurrentBlock != aBlocks[i]) {
			hideBlock(aBlocks[i]);	
		}	
	}		
}

/**
*
* Validation function
*
**/

function ValidateForm() {		  
  if (!RequiredTextField(document.getElementById('__d'), "Voornaam is niet ingevuld")) {
    return false;
  }
  
  if (!RequiredTextField(document.getElementById('__e'), "Achternaam is niet ingevuld")) {
    return false;
  }
  
  if (!RequiredTextField(document.getElementById('__f'), "Plaatsnaam is ingevuld")) {
    return false;
  }
  
  if (!ValidateEmail(document.getElementById('__g'), "E-mail is niet (correct) ingevuld")) {
    return false;
  }
	
	document.getElementById("form_subscribe").action = "/IManager/MailingOptIn";
	return true;
}
