$(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'
    });

	$("#bottom-boxes img").before("<span/>");
	
	$("#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;
			});
			
	var slidecounter = 0;
	
	$('#slider').before('<ul id="slide_nav"></ul>');
	
	$('ul#slider li').each(function(){
		$('ul#slide_nav').append('<li class="slide_'+slidecounter+'"></li>');
		slidecounter++;
	});
	
	$('ul#slider').innerfade({
		speed: 600,
		timeout: 4000,
		type: 'sequence',
		containerheight: 	'450px',
		slide_timer_on: 	'yes',
		slide_ui_parent: 	'slider',
		slide_nav_id:		'slide_nav'
	});
	$.setOptionsButtonEvent();
});
