jQuery(document).ready(function($) 
{
	var container = $('div.formwrapper');	
	var validator = $("#the_form").validate({
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate"
	});
	
	jQuery.validator.addMethod("postalcode", function(postalcode, element) {
		return this.optional(element) || postalcode.match(/(^\d{4}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
	}, "Please specify a valid postal/zip code");
	
	jQuery.validator.addMethod("postalcode2", function(postalcode, element) {
		return this.optional(element) || postalcode.match(/(^[A-Za-z]{2}(-[A-Za-z]{2})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
	}, "Please specify a valid postal/zip code");

	$("#myform").validate({
		rules: {
			postalcode: {
				postalcode: true
			},
			postalcode2: {
				postalcode2: true
			}
		}
	});

	left	= 0;
	right	= 0;
	
	$('.post-float').each(function(box)
	{
		side = left <= right ? "left" : "right";
		$(this).css('float', side);
		window[side] += $(this).outerHeight(false);
	});
	
	
	var divWrapper 		= $('div#tags div'),
		ulSlider 		= $('ul.list-tags'),
		btnNext 		= $('a.btn-next'),
		btnPrev 		= $('a.btn-prev'),
		lastLi 			= ulSlider.find('li:last-child'),
		wrapperWidth 	= $('#tags').outerWidth(),
		intervalId,
		intervalIdRight;

	tagSlider();
	
	function tagSlider()
	{
		divWrapper.css(
		{
			overflow: 'hidden'
		});
		
		btnNext.mouseover(function(e)
		{
			intervalId = setInterval(slideLeft, 1);
		});
		
		btnNext.mouseout(function(e)
		{
			clearInterval(intervalId);
		});
		
		btnPrev.mouseover(function(e)
		{
			intervalIdRight = setInterval(slideRight, 1);
		});
		
		btnPrev.mouseout(function(e)
		{
			clearInterval(intervalIdRight);
		});
	}
	
	function slideLeft()
	{		
		if(lastLi.position().left - divWrapper.scrollLeft() > wrapperWidth)
		{	
			divWrapper.scrollLeft((divWrapper.scrollLeft() + 3));
		}
		else
		{
			clearInterval(intervalId);
		}
	}
	
	function slideRight()
	{
		if(lastLi.position().left + divWrapper.scrollLeft() > wrapperWidth)
		{	
			divWrapper.scrollLeft((divWrapper.scrollLeft() - 3));
		}
		else
		{
			clearInterval(intervalIdRight);
		}
	}
	
});
