$(document).ready(function() {
    $(document).pngFix();

	$('ul.drop-down').hide();
	$('nav li.drop').hoverIntent(function() {
		$(this).find("ul.drop-down").slideToggle();
		$(this).children(":first").toggleClass('open');
	}, function(){
		$(this).find("ul.drop-down").slideToggle();
		$(this).children(":first").toggleClass('open');
	});

	$('#local').hoverIntent(function(){
		$('#hello').fadeIn();
	}, function(){
		$('#hello').fadeOut();
	});

	$('#featured').hoverIntent(function(){
		$(this).find('#project-more').slideDown();
	}, function() {
		$(this).find('#project-more').slideUp();
	});

	$('.project').hoverIntent(function(){
		$(this).addClass('p-over');
		$(this).find('.details').animate({'bottom':'+=50'},'fast');
	}, function() {
		$(this).removeClass('p-over');
		$(this).find('.details').animate({'bottom':'-=50'},'fast');
	});

	$('#login').toggle(function(){
		$('#client-login').animate({'left':'+=300'},'slow');
	}, function(){
		$('#client-login').animate({'left':'-=300'},'slow');
	});

	$('a#forgotPassword').toggle(function(){
		$('form#forgotPassword input#username').focus();
		$('#forgot-password').animate({'left':'+=60%'},'fast');
	}, function(){
		$('#forgot-password').animate({'left':'-=60%'},'fast');
		$('form#forgotPassword input#username').val('');
		$('div#forgot-password #error').hide();
	});
	
	$('#forgot-password #cancel').click(function(event) {
		$('a#forgotPassword').click();
		return false;
	});
	
	$('form#forgotPassword').submit(function() {
		$.post('/clients/auth/forgot-password.php', $('form#forgotPassword').serialize(), function(data) {
			if (data.success) {
				$('a#forgotPassword').click();
				alert('Your password has been resent to your email address');
			} else {
				$('div#forgot-password #error').show();
			}
        }, 'json');
		return false;
	});
	

	if ($(".project img").length > 0) {
		$(".project img").lazyload({
			effect : 'fadeIn',
	    	placeholder : "/images/imgplaceholder.png"
		});
	}

	$('#more').hide();
	$('#expand').click(function(){
		$('#more').slideToggle();
		$(this).hide();
	});

	$('.checkForm').submit(function(){
		if ($('#firstname').val() == '' ||  $('#email').val() == '') {
			$('#error').html('Sorry, but a valid <strong>name</strong> and <strong>email</strong> address are required to send.').fadeIn();
			return false;
		}
		return true;
	});

	$('form#domainSearch').submit(function() {
		location.href = $('form#domainSearch').attr('action') + $('form#domainSearch #domain').val();
		return false;
	});

	$('#tools #logout').live('click', function(event) {
		$.getJSON('/clients/auth/logout.php', function(data) {
            $('#tools #loginContainer').html('');
        });
        event.preventDefault();
		return false;
	});
	
	// Yell at people using IE6
	if($.browser.msie && parseInt($.browser.version) < 7){
		$("<div id='browserWarning'>We noticed you are running a very old, outdated and generally lame browser. We recommend downloading <a href='http://getfirefox.com'>FireFox</a> or <a href='http://www.google.com/chrome'>Chrome</a> to enhance your experience! [<a id='warningClose' href='#'>X</a>]</div>")
		  .css({
			'backgroundColor': '#e71111',
			'width': '100%',
			'border-top': 'solid 1px #000',
			'border-bottom': 'solid 1px #000',
			'padding':'5px 0px 5px 0px',
			'color':'white',
			'text-align':'center'
		  })
		.prependTo("body");
	}

	$('#warningClose').live('click', function(event) {
		$('#browserWarning').remove();
	});
	
	// Modal Window for About Page
	$('.chrisstone').click(function (e) { $('#chrisstone').modal(); return false;});
	$('.mattpramschufer').click(function (e) { $('#mattpramschufer').modal(); return false;});
	$('.amygangi').click(function (e) { $('#amygangi').modal(); return false;});
	$('.ginamabry').click(function (e) { $('#ginamabry').modal(); return false;});
	$('.carlolsen').click(function (e) { $('#carlolsen').modal(); return false;});
	$('.shawngrimes').click(function (e) { $('#shawngrimes').modal(); return false;});
	$('.paulbutcher').click(function (e) { $('#paulbutcher').modal(); return false;});
	$('.mattstone').click(function (e) { $('#mattstone').modal(); return false;});
	$('.scottsteele').click(function (e) { $('#scottsteele').modal(); return false;});
	$('.markbroomell').click(function (e) { $('#markbroomell').modal(); return false;});
	
	
	
});
