jQuery(document).ready(function(){

	if((jQuery('body').attr('class')).indexOf('browserSafar') < 0){
			//Only check if css is disabled for other browsers accept safari, if CSS is disabled, stop all javascript executions
       	if(jQuery('#wrap').css('fontSize') == '16px'){
       		return;
       	}       	
	}
	
	jQuery("ul.fcbNav").superfish({ 
		animation: {height:'show'},   // slide-down effect without fade-in 
		delay:     500               // .52 second delay on mouseout 
	}); 
	jQuery("ul.fcbNav").find('ul').bgIframe({opacity:false}); 
	    
	jQuery("img.imgNormal").parent().addClass("linkedimage");
	jQuery("img.imgLeft").parent().addClass("linkedimage");
	jQuery("img.imgRight").parent().addClass("linkedimage");
	
    jQuery('#breadcrumbs').prepend('<a href="#" class="printThisPage">Print page<\/a>');
    jQuery('.printThisPage').click(function (){
   		window.print();
   		return false;
    });	
	 
	assignTeaserHover('#featured .teaser');
	assignTeaserHover('#contentSecondary .teaser');
	assignTeaserHover('#indexPageContent .teaser');
	assignTeaserHover('.searchResults li');
	assignTeaserHover('#teasers li.teaser');
	
	jQuery('#mainContactForm').validate({
		rules: {
			yourName : "required",
			email : {required: true, email: true},
			comment : "required",
			phone : {required: true, number : true}
								
		},
		messages: {
			yourName : 'Pleaser enter your name.',
			email : 'Please enter a valid email address',
			comment: 'Please enter a comment',
			phone : 'Please enter your phone number in digits with no spaces between them.'
		},		
        errorElement: "p"

	});
	
	setInputPlaceHolder();
	
	insertYoutubeVideo('.youtube');
	
});


function insertYoutubeVideo (sClassName){
          jQuery(sClassName).each(function (){
            var iVideoWidth = jQuery(this).children('img').attr("width");
            var iVideoHeight = jQuery(this).children('img').attr("height");

            var sLink = jQuery(this).attr("href");
            var equalPosition = sLink.split("v=");
            var iVideoCode = equalPosition[1];
			if(iVideoCode === undefined){
				equalPosition = sLink.split(".be/");
	            iVideoCode = equalPosition[1];
			}

            var sFloat = '';
            if(jQuery(this).hasClass('floatLeft'))
               sFloat = 'floatLeft';   
            else if(jQuery(this).hasClass('floatRight'))
               sFloat = 'floatRight';
            else
               sFloat ='floatNone';   

            var sVideoCode = '<div class="' + sFloat + '"><iframe class="youtube-player" type="text/html" width="' + iVideoWidth + '" height="' + iVideoHeight + '" src="http://www.youtube.com/embed/' + iVideoCode + '" frameborder="0"></iframe></div>';

            jQuery(this).replaceWith(sVideoCode);                        
          });
}

function replaceInput(inputClass,anchorClass){   

    if(inputClass == ''){
        inputClass = 'inputButton';
    }
    
    jQuery('form').each(function () {         	    	
        jQuery(this).find('input.'+inputClass).each(function (){    	                       
            jQuery(this).hide();
            jQuery(this).after('<a href="#" class="'+anchorClass+'"><span>'+jQuery(this).val()+'<\/span><\/a>');                                
        });    
    });
    
    jQuery("."+anchorClass).click(function (){
		var sFormName = jQuery(this).parents('form').attr("id");
		jQuery("#"+sFormName).submit();
		return false;
	});
}

function assignTeaserHover(className){		
			
	jQuery(className).click(function(){
		var sHref = jQuery(this).find("a").attr("href");
		
		if(jQuery(this).find("a").attr("target") == '_blank')
			window.open(sHref);			
		else
		   	window.location= sHref;
		   	
		return false;			
	});
	
    jQuery(className).hover(
   		function() { jQuery(this).addClass('teaserHover');}, 
        function() { jQuery(this).removeClass('teaserHover');
    });
}

function addEventTracking(category, action, label){
	try{
		pageTracker._trackEvent(category, action, label);	
	}
	catch(err){}
}

function trim(str) {
    return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

function setInputPlaceHolder(){	
	jQuery('[placeholder]').focus(function() {
		  var input = jQuery(this);
		  if (input.val() == input.attr('placeholder')) {
		    input.val('');
		    input.removeClass('placeholder');
		  }
		}).blur(function() {
		  var input = jQuery(this);
		  if (input.val() == '' || input.val() == input.attr('placeholder')) {
		    input.addClass('placeholder');
		    input.val(input.attr('placeholder'));
		  }
		}).blur().parents('form').submit(function() {
		  jQuery(this).find('[placeholder]').each(function() {
		    var input = jQuery(this);
		    if (input.val() == input.attr('placeholder')) {
		      input.val('');
		    }
		  })
	});
}

