/* Remove unwanted elements
/* ---------------------------------------------- */
function clearUnwanted(){
/*
	$('#nav-el5').parent('li').remove();
	$('#nav-el6').parent('li').remove();
	
	$('#footer .box-nav li:eq(6)').remove();
	$('#footer .box-nav li:eq(5)').remove();
*/
	if ( $("#submenu").length ){

		if ( !$('#submenu').contents().length ){ $('#submenu').remove(); };
		if ( !$('#submenu li.current ul').contents().length ){ $('#submenu li.current ul').remove();	};
	}
	
	if ( !$('.article-listing').contents().length > 1 ){
		$('.article-listing').remove();
	};

};


/* Cases Slideshow for Home and Case page
/* ---------------------------------------------- */
function startSlideshow(){
	var iTotal = $('#slideshow .item').length;
	
	if ( $('.slide-total').length > 0 ) $('.slide-total').text( iTotal );
	$('a#prev').addClass('off');
	
	$('#slideshow').serialScroll({
		items: '.item',
		prev: 'a#prev',
		next: 'a#next',
		cycle: false,
		step: 1,
		onAfter:function( elem ){
		
			// Get the next slide Index (index starts at 0)
			var iIndex = $('#slideshow .item').index( elem ) + 1;

			$('a#prev').removeClass('off');
			$('a#next').removeClass('off');
				
			if ( iIndex > 1 && iIndex < iTotal  ){
				$('a#prev').removeClass('off');
				$('a#next').removeClass('off');
			} else {
				if ( iIndex == 1 ) $('a#prev').addClass('off');
				if ( iIndex == iTotal ) $('a#next').addClass('off');
			}
			
			if ( $('.slide-current').length > 0 ) $('.slide-current').text( iIndex );
		}
	});
}; // end startSlideshow

// CustomDB Slideshow for related objects
// --------------------------------------
function startSlideshow2(){
	var iTotal2 = $('#slideshow2 .item').length;
	
	if ( $('.casenav2').children('.slide-total').length>0 ) $('.casenav2').children('.slide-total').text( iTotal );
	$('.casenav2').children('a#prev2').addClass('off');
	
	$('#slideshow2').serialScroll({
		items: '.item',
		prev: 'a#prev2',
		next: 'a#next2',
		cycle: false,
		step: 1,
		onAfter:function( elem ){
			// Get the next slide Index (index starts at 0)
			var iIndex = $('#slideshow2 .item').index( elem ) + 1;
			
			//if ( iIndex > 1 && iIndex < iTotal2  ){
				$('.casenav2').children('a#prev2').removeClass('off');
				$('.casenav2').children('a#next2').removeClass('off');
			//} else {
				if ( iIndex == 1 ) $('.casenav2').children('a#prev2').addClass('off');
				if ( iIndex == iTotal2 ) $('.casenav2').children('a#next2').addClass('off');
			//}
			
			if ( $('.casenav2').children('.slide-current').length > 0 ) $('.casenav2').children('.slide-current').text( iIndex );
		}
	});
}; // end startSlideshow	

/* Make Accordion of FaqBox
/* ---------------------------------------------- */
function faqBox(){
	$('#sitehelper ul').accordion({
		header: 'li.title a', 
		active: false, 
		alwaysOpen: false, 
		animated: false, 
		autoheight: false
	});
};



/* SendFriend Functions
/* ---------------------------------------------- */
function doModal(){ 
	$("#tellafriend-modal").modal(); 
};

function submitTAF(){
	$('#taf_form').submit(function() {
		
		var $successMsg = '<div style="padding-top:50px;text-align:center"><p><strong>Je bericht is succesvol verzonden!</strong></p><p>Dit venster sluit automatisch.</p></div>';
		
		$.ajax({
		   type: "POST",
		   url: window.location.href,
		   data: $(this).serialize(),
		   success: function(msg){

		   	// Get Modal content
				var $newHtml = $(msg).find("#tellafriend-modal").html();
				var $sError = $(msg).find("p.error:contains('verstuurd')");
		     	
		     	// Success? Show succes text & close the Modal automaticly
		     	// Else show default Modal
					if ( $sError.length > 0 ) {
							$("#tellafriend-modal form").html( $successMsg );
							setTimeout( function(){ $.modal.close(); }, 3000);
					} else {
							$("#tellafriend-modal").html( $newHtml );
					}
		   }
		 });

		return false;
	});
};			



/* DOM Ready
/* ---------------------------------------------- */
$(document).ready(function(){

	clearUnwanted();

	/* Set the Home Page Scroll
	/* ---------------------------------------------- */
	if ( $('a.intro-doen').length > 0 ){
		$('a.intro-doen').click(function(){
			$.scrollTo( $('#getme'), {speed:1500} );
		});
	}

	/* FAQ Accordion
	/* ---------------------------------------------- */
	if ( $('#sitehelper ul').length > 1 ) faqBox();
	
	
	/* Footer Year
	/* ---------------------------------------------- */
	var sDate = new Date()
	var sYear = sDate.getFullYear()

	$('em.year').text( sYear );
	
	if ( $('.home #content-wrapper').length ) $('.home #content-wrapper').fadeIn(1500);
	
	// Vacancies
	if(!$('#vacancies').children().length) {
		$('#vacancies-empty').show();
	};
	
	// Google map
	var map = $('#object-map');
	if(map.length) {
		map.appendTo('#sidebar');
	};
	
});
