var validation_settings = { 
    rules: { 
        name: "required",
        organisation: "required",
        address: "required",
        postal_code: "required",
        city: "required",
        country: "required",
        firstname: "required",
        lastname: "required",
        sector: "required",
        email: {
            required: true, 
            email: true 
        }, 
        telephone: "required"
    }, 
    errorClass: "validation-error",
    errorElement: "em",
    highlight: function( element, errorClass ) {
        jQuery( element ).addClass( errorClass );
        jQuery( element ).parent('label').addClass( errorClass );
        jQuery( element ).parent('label').parent('fieldset').addClass( errorClass );
    }
}

jQuery(document).ready(function() { 
    jQuery.ajax({
                url: "@@national-campaign-partner-application-form/get_validation_messages",
                cache: false,
                dataType: "json",
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    jQuery("form#national-partner-application-form").validate(validation_settings); 
                },
                success: function(data) {
                    validation_settings['messages'] = data.messages;
                    jQuery("form#national-partner-application-form").validate(validation_settings); 
                }
        });
}); 

jQuery(document).ready(function() {
    var f = function() {
         var frameWidth;
         if (self.innerWidth) {
           frameWidth = self.innerWidth;
         } else if (document.documentElement && document.documentElement.clientWidth) {
           frameWidth = document.documentElement.clientWidth;
         } else if (document.body) {
           frameWidth = document.body.clientWidth;
         } else {
           return;
         }
         if (frameWidth < 1050) {
           jQuery('body').addClass('medium');
           jQuery('body').removeClass('large');
         } else {
           jQuery('body').removeClass('medium');
           jQuery('body').addClass('large');
         }
    };
});

$(document).ready(function() {
    if ($("a[rel=contactSheet]").length>0) {
	$("a[rel=contactSheet]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		    }
		});
    }
	$("legend").each(function() {
	    $(this).replaceWith('<p class="legend">'+$(this).html()+'</p>');
	});    	    
});


jQuery(document).ready(function() {
    if (jQuery(".carousel").length>0){
       jQuery(".carousel").jcarousel();
    }
});

//Schwung
var jump=function(e)
{
       //prevent the "normal" behaviour which would be a "hard" jump
       e.preventDefault();
       //Get the target
       var target = $(this).attr("href");
       //perform animated scrolling
       $('html,body').animate(
       {
               //get top-position of target-element and set it as scroll target
               scrollTop: $(target).offset().top
       //scrolldelay: 2 seconds
       },500,function()
       {
               //attach the hash (#jumptarget) to the pageurl
               location.hash = target;
       });

}

$(document).ready(function()
{
       $('a[href*=#]').bind("click", jump);
       return false;
});

// Needed for the detail view of a synchronised partner
$(document).ready(function() {
  jQuery('.expandableHeader').click(function() {
      jQuery(this).parent().toggleClass('opened');
      jQuery(this).parent().toggleClass('closed');
      jQuery(this).parent().find('.expandableContent').slideToggle();
  });
});

$(document).ready(function() {
    if ($('.abecedaire').length >0) {
        $('.abecedaire').localScroll(800);
    }
});
$(document).ready(function() {
/* first clean any contained spans in h1 */
jQuery('h1 span').replaceWith(jQuery('h1 span').contents());
var h1val = jQuery('h1').html();
h1val = h1val.replace(/^\s*/, "").replace(/\s*$/, "");
if (h1val.length>65) {
  jQuery('h1').html(h1val.substring(0,65)+'&hellip;');
}
});

