(function($){
  $.fn.simplestSlideShow = function(settings){
    var config = {
      'timeOut': 3000,
      'speed': 'normal'
    };
    if (settings) $.extend(config, settings);
    this.each(function(){
      var $elem = $(this);
      $elem.children(':gt(0)').hide();
      setInterval(function(){
        $elem.children().eq(0).fadeOut(config['speed'])
        .next().fadeIn(config['speed'])
        .end().appendTo($elem);
      }, config['timeOut']);
    });
    return this;
  };
})(jQuery);

/*Contact Form - Borrowed code*/
$(document).ready(function(){
            $(".fadein").simplestSlideShow({'timeOut': 2500, 'speed': 1000});
            
			$(".contactbox").colorbox({width:"410px", initialWidth:"50px", initialHeight: "50px", inline:true, opacity: .8, transition:"elastic", speed:300, href:"#contact_us"});
		
			var Messages = {
			  loader: jQuery('<div class="loading"><img src="../images/layout/loadingForm.gif" /></div>'),
			  thanks: jQuery('<div class="success">Thanks for your message!</div>'),
			  error: jQuery('<div class="errorm">There seems to be a problem with the form, please try again.</div>'),
			};
			var contact_form = jQuery('#contact_form');
			var colorBox = jQuery.fn.colorbox;

			$('#contactform').validate({
              rules: {
                 email: {
                   required: true,
                   email: true
                 },
                 name: {
                   required: true
                 },
                 message: {
                   required: true
                 }
              },
              messages: {
                 name: "What's your name?",
                 email: "Use a valid email address.",
                 message: "What do you want to say?"
              },
              errorElement: "label",
              errorPlacement: function(error, element) {
                    error.insertBefore(element)
              },
			  submitHandler: function(form) {
			    var $this = jQuery(form);
			    $this.hide(); //this hides the form
                colorBox.resize();
                
			    if (contact_form.find('.loading').length <= 0) {
			      contact_form.prepend(Messages.loader); 
			    } else {
			      contact_form.find('.loading').show();
			    }

			    jQuery.ajax({
			      type: "POST",
			      url: $this.attr("action"),
			      data: $this.serialize(),
			      success: function(data, status) {
			        contact_form.find('.loading').hide();

			        if (contact_form.find('.success').length <= 0) {
			          contact_form.append(Messages.thanks);
			        } else {
			          contact_form.find('.success').show();
			        }
			        colorBox.resize();
			      },
			      error: function(xhr, status, error) {
                    
			        contact_form.find('.loading').hide();

			        if (contact_form.find('.errorm').length <= 0) {
			          contact_form.prepend(Messages.error); 
			        } else {
			          contact_form.find('.errorm').show();
			        }
			        $this.show();
			        colorBox.resize();
			      }
			    });
			  }
			});
  		});