$(function(){
$('a.newwindow').attr('target','_blank');
	var liList = $($('#who').parent())
		.add($('#which').parent())
		.add($('#where').parent())
		.add($('#what').parent());
	$(liList).css('display','none');

	$('.tweet p a').click( function() {
		window.open(this.href);
		return false;
	});

	//$('#cycle').css('width',$(document).width());

	$('#home #content #cta div').show();

	$('.news #email').labelify();

	function Resize() {
		//$('#cycle').css('width',$(document).width());
	}

	$('.error').hide();
    $("#submit").click(function() {
		$('.error').hide();

		var valid=true;
		var name = $("input#name").val();
		var email = $("input#email").val();
		var company = $("input#company").val();
		var phone = $("input#phone").val();
		var users = $("input#users").val();

  		if (name == "") {
			$("#name_error").css('display','inline');//.show();
			$("input#name").focus();
			valid = false;
		}
		else if (company == "") {
			$("#company").css('display','inline');//.show();
			$("input#company").focus();
			valid = false;
		}
		else if (phone == "") {
			$("#phone").css('display','inline');//.show();
			$("input#phone").focus();
			valid = false;
		}
		else if (users == "") {
			$("#users").css('display','inline');//.show();
			$("input#users").focus();
			valid = false;
		}
		else {
			var email = $("input#email").val();
			if (email == "") {
				$("#email_error").css('display','inline');
				$("input#email").focus();
				valid = false;
			} else {
				var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

				if(pattern.test(email)) {
				} else {
					$("#email_error2").css('display','inline');
					$("input#email").focus();
					valid = false;
				}
			}
		}
		if(valid) $('#btnSubmit').click();
    });
	/*$(window).resize(function(){
		var width = $(document).width();
		$('#static_wrapper').add('.slide').css('width',width);
	}); */

	/*
	function CycleResize() {
		var width = $(document).width();
		//var leftoffset = (width - 1000) / 2;
		//$('.slide').css('left', leftoffset);
		if(width >= 1260){
			$('#cycle_wrapper').add('#static_wrapper').add('.slide').css('width',width);
		} else {
			var width2 = width - 260;
			$('#cycle_wrapper').add('#static_wrapper').add('.slide').css('width',width2);
		}

	}
	*/

	/*
	$('#static_wrapper').cycle({
		fx:     'fade',
		speed:  '800',
		timeout: 20000,
		cleartypeNoBg:  true,
		pause: true,
		height: 315,
		startingSlide: 0,
		pager: '#cycle-nav',
		before: CycleResize,
		containerResize: 1
	}); */
	// chart cycles
	$('#experience-chart .chart').add('#about-chart .chart').add('#services-chart .chart').cycle({
		fx:     'fade',
		speed:  '600',
		timeout: 12000,
		cleartypeNoBg:  true,
		pause: true,
		pager: '#cycle-pager'
	});

	// home Case Study CTA cycle
	$('#home #cta').cycle({
		fx:     'fade',
		speed:  '800',
		timeout: 20000,
		cleartypeNoBg:  true,
		pause: true,
		height: 300,
		startingSlide: 0
	});

	// twitter cycle, duh
	$('#twitter').cycle({
		fx:     'scrollDown',
		speed:  '600',
		timeout: 5000,
		cleartypeNoBg:  true,
		pause: true,
		height: 120
	});

    $('.error').hide();

    $('#submit').click(function() {
		$('#btnSubmit').click();
    });

	// nav dropdowns

    $('#nav li ul').hide();

    $('#nav li').hover(function() {
		$(this).children('ul').stop().css('height','').slideDown(200);
	}, function() {
		$(this).children('ul').stop().slideUp(200);
	});

	// social media icons, footer
	$('#footer #left ul li').hover(function() {
		$(this).stop().animate(
			{backgroundPosition:"(0 " + ($(this).css('background-position')).split(' ')[1] + ")"},
			{duration:300})
	}, function() {
		$(this).stop().animate(
			{backgroundPosition:"(-16 " + ($(this).css('background-position')).split(' ')[1] + ")"},
			{duration:300})
	});

});
