$(document).ready(function() {
    	
	swapValue = [];
	$("form input,form textarea").each(function(i){
	   swapValue[i] = $(this).val();
	   $(this).focus(function(){
	      if ($(this).val() == swapValue[i]) {
	         $(this).val("");
	      }
	      $(this).addClass("focus");
	   }).blur(function(){
	      if ($.trim($(this).val()) == "") {
	         $(this).val(swapValue[i]);
		 $(this).removeClass("focus");
	      }
	   });
	});
	
	$(function() {
		$(".newsticker-jcarousellite").jCarouselLite({
			vertical: true,
			hoverPause:false,
			visible: 2,
			auto:4000,
			speed:1000
		});
	});
	
	
	
	
	// applying margins to floated images correctly, used little extra code for IE's bugs.
	if($.browser.msie){
		$('img').each(function(){
		    obj = $(this);
		    if (obj.attr('style').indexOf('left') > 0) {
		        obj.addClass('img-left');
		    }
				if (obj.attr('style').indexOf('right') > 0) {
		        obj.addClass('img-right');
		    }
		});
	}else{
		$('img[style*="left"]').each(function(){
			$(this).addClass('img-left');
		});
		$('img[style*="right"]').each(function(){
			$(this).addClass('img-right');
		});
	}
	
	
	


	
	
			// initialize validator with the new effect
			$("#postcard_form").validator({
			   effect: 'wall', 
			   container: '#errors',

			   // do not validate inputs when they are edited
			   errorInputEvent: null

			// custom form submission logic  
			}).submit(function(e)  { 

			   // when data is valid 
			   if (!e.isDefaultPrevented()) {

			      // tell user that everything is OK
			      $("#errors").html("<h1>Sending...</h1>");

			      // prevent the form data being submitted to the server
			      // e.preventDefault();
			   } 

			});
	
	
	
			// adds an effect called "wall" to the validator
			$.tools.validator.addEffect("wall", function(errors, event) {

				// get the message wall
				var wall = $(this.getConf().container).fadeIn();

				// remove all existing messages
				wall.find("p").remove();
				wall.find("ul").remove();
				
				wall.append("<p class='title'>Please fix the following errors</p>");
				
				wall.append("<ul></ul>");

				// add new ones
				$.each(errors, function(index, error) {
					wall.find("ul").append(
						"<li><strong>" +error.input.attr("title")+ ":</strong> " +error.messages[0]+ "</li>"
					);		
					error.input.addClass('error');
				});
				
		

			// the effect does nothing when all inputs are valid	
			}, function(inputs)  {
				
				$(this.error).removeClass("error");

			});
	

});





