jQuery.noConflict();  //This will let you to replace the $ with the word jQuery in order to resolve conflicts with the prototype library

jQuery(document).ready(function() {
	// Hide sub items initialy
	jQuery('.sub-menu').hide();
	
	// Show submenu on main menu item hover
	jQuery('.mi').hover(function() {
		jQuery(this).find('.sub-menu').show();		
	}, function() {
		jQuery(this).find('.sub-menu').hide();
	});
	
	// Indicator page menu - wordt geplaatst naast list item met class "active"
	if ( jQuery('.page-menu li.active').length > 0 ) {
		y = jQuery('.page-menu li.active').offset().top;
		jQuery('#page-menu-indicator').css('top', y - 20);
	} else {
		jQuery('#page-menu-indicator').hide();
	}	
	
	// Equalize columns
	jQuery("#content-left, #content-right").equalHeights();
	
	//initFaq();
	
	// Home page button hover images
	initButtonRollovers();	
	
	initDownloadIcons();
    
    if(urlParam('posted') == 'true'){
        jQuery('.newsDiv').show();
    }
    
	
	// Ghost text
	jQuery("div.news-letter #news-letter-form #email").ghosttext("Vul hier uw emailadres in");
	           
});

 function urlParam(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) { return 0; }
    return results[1] || 0;
 }

function initButtonRollovers() {	
    jQuery('.btn-hover').hover(
        function() {
           	var newSrc = jQuery(this).attr("src").replace(/\.png$/,"_hover.png");
			jQuery(this).attr("src",newSrc);
        },
        function () {
			var oldSrc = jQuery(this).attr("src").replace(/_hover\.png$/,".png");
			jQuery(this).attr("src",oldSrc)
        }
    ); 
}

function initDownloadIcons() {
	var filename = jQuery('.download-list .item').each(function (i) {
		var href = jQuery(this).find('.link a').attr('href');
		var ext = getExtension(href);
		var icon = jQuery(this).find('.icon');
		
		//if (ext != 'pdf')
		//	icon.removeClass('pdf');
			
		if (ext == 'ppt' || ext == 'pptx' ) {	
			icon.removeClass('pdf');		
			icon.addClass('ppt');
		}
		
	});	
}

function getExtension(filename) {
	return filename.split('.').pop();
}

/*
function initFaq() {
	// Make all of the answer sections hide when the DOM is ready
	jQuery('div.faq > div').hide();  
	// Toggle answer section click event
    jQuery('div.faq > h3').click(function() {
		// Icons
		 if (jQuery(this).next('div').is(':hidden')) 
			jQuery(this).find('img').attr('src', 'images/faq_close.png');
		else
			jQuery(this).find('img').attr('src', 'images/faq_open.png'); 									  
		 // Slide effect							 
		 jQuery(this).next('div').slideToggle('fast')
		 .siblings('div:visible').slideUp('fast');		 	
		 
		 jQuery(this).siblings('.open').find('img').attr('src', 'images/faq_open.png');		 		 
		 // Color of H3
		 jQuery(this).addClass('open')
		 .siblings('.open').removeClass('open');
    });
}
*/

// JQuery ghosttext implementation
// (placeholder text in textbox which is removed when the textbox is given focus)
//
// Usage: $(selector).ghosttext("This text appears in textbox");
jQuery.fn.ghosttext = function(text) { 

  jQuery(this).val(text);
  jQuery(this).addClass("ghosttext");

  jQuery(this).focus(function(){ 
    if(jQuery(this).val() == text)
    {
      jQuery(this).val('');	  
	  jQuery(this).removeClass("ghosttext");
    }
  });
  
  jQuery(this).blur(function(){
    if(jQuery(this).val() == '')
    {
      jQuery(this).val(text);
	  jQuery(this).addClass("ghosttext");
    } 
  });
}

jQuery.fn.equalHeights=function() {
	var maxHeight=0;
	this.each(function(){
		if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
	});
	this.each(function(){
	 jQuery(this).height(maxHeight + "px");
	 if (this.offsetHeight>maxHeight) {
		jQuery(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
	 }
	});
};
