$(document).ready(function(){
	$("a[href^=http]").each(function(){
      if(this.href.indexOf(location.hostname) == -1) {
        $(this).attr('target', '_blank');
      }
    });
    
    $(".fancybox").fancybox({
    	'transitionIn'	:	'elastic',
    	'transitionOut'	:	'elastic',
    	'titlePosition'	:	'over'
    });
    
    
    
    $("#contact").submit(function(ev){
		var errorcount = 0;
		$("input.text").each(function(){
			if($(this).hasClass('skip'))
			{
			}
			else
			{
			var errortrue = 0;
			var currentvalue = $(this).val();
			if(currentvalue == "")
			{
				errorcount++;
				errortrue++;
			}
			if(errortrue > 0)
			{
				$(this).addClass("error");
				$(this).parent('fieldset').children('legend').addClass('error');
			}
			}
		});
		
		$("textarea").each(function(){
			if($(this).hasClass('skip'))
			{
			}
			else
			{
			var errortrue = 0;
			var currentvalue = $(this).val();
			if(currentvalue == "")
			{
				errorcount++;
				errortrue++;
			}
			if(errortrue > 0)
			{
				$(this).addClass("error");
				$(this).parent('fieldset').children('legend').addClass('error');
			}
			}
		});
		
		if(errorcount > 0)
		{
			$("#contact h3:first").before('<p class="error">Please fill in all fields.</p>');
			$("p.error").delay(3000).fadeOut();
			ev.preventDefault();
		}
	});
	
	$("#contact input, #contact textarea, #contact select").focus(function(){
		$(this).removeClass("error");
		$(this).parent('fieldset').children('legend').removeClass('error');
	});
	

		
	$("a.youtube").click(function() {
				$.fancybox({
				'padding'			: 10,
				'centerOnScroll'	: true,
				'autoScale'			: false,
				'href'                : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/')+'&autoplay=1',
                'type'                : 'swf',
                'swf'                 : {'allowfullscreen':'true'}
				});
				return false;
			});
		$(".vimeo").click(function() {
				$.fancybox({
				'padding'			: 10,
				'centerOnScroll'	: true,
				'autoScale'			: false,
				'href'				: this.href.replace(new RegExp("vimeo.com/", "i"), 'vimeo.com/moogaloop.swf?clip_id=')+'&autoplay=1',
				'type'				: 'swf',
				'swf'                 : {'allowfullscreen':'true'}
				});
				return false;
			});
			
	$('.slideshow').cycle({
		fx:			'fade',
		timeout:     3000, 
    	pager:      '#slideshow-nav', 
    	pagerEvent: 'mouseover', 
    	fastOnEvent: true 
	});	
});
