var default_margin = 180;
var indicator_scroll = 310;
var scroll_speed = 750;

$(function() {
	if($.browser.msie && $.browser.version.substr(0, 1) < 7) {
		$('.header, .contact, .contact-footer, .selected-work h2, .selected-work a').supersleight();
		$('.selected-work ul li img').css('margin-left', '-7px');
	}

	$('#submit-hold input').remove();	
	$('#submit-hold').html('<a class="submit-message">Submit Message</a>');

	$('.work-with-me, .close, .next a, .footer-content div a').removeAttr('href');

	$('.work-with-me').click(function() {
		$('#contact-container').animate({top : 0}, {duration: 1000, easing: 'easeOutBounce'});
	});

	$('.close').click(function() {
		$('#contact-container').animate({top : '-678px'}, 500);
	});

	$('.footer-content div a').click(function() {
		$('html, body').animate({scrollTop: 0}, 250);
		setTimeout(function(){ $('#contact-container').animate({top : 0}, {duration: 1000, easing: 'easeOutBounce'});}, 500);
	});

	$('.patternmade, a[rel="codebrowser"]').click(function() {
		this.target = '_blank';
	});

	$('a.current, a.selected-thumb').click(function() {
		$('.selected-work li a').removeClass('current');
		$('#wrapper').scrollTo($(this).attr('href'), {duration: scroll_speed, easing: 'easeInOutExpo'});
		return false;
	});

	$('#selected-1').click(function() {	
		$(this).addClass('current');
		$('.indicator').animate({marginLeft: default_margin + 'px'}, {duration: scroll_speed, easing: 'easeInOutExpo'});
	});

	$('#selected-2').click(function() {
		$(this).addClass('current');
		$('.indicator').animate({marginLeft: (default_margin + indicator_scroll) + 'px'}, {duration: scroll_speed, easing: 'easeInOutExpo'});
	});

	$('#selected-3').click(function() {
		$(this).addClass('current');
		$('.indicator').animate({marginLeft: (default_margin + (indicator_scroll * 2)) + 'px'}, {duration: scroll_speed, easing: 'easeInOutExpo'});
	});

	$('#selected-4').click(function() {
		$(this).addClass('current');
		$('.indicator').animate({marginLeft: (default_margin + (indicator_scroll * 3)) + 'px'}, {duration: scroll_speed, easing: 'easeInOutExpo'});
	});

	$('#selected-5').click(function() {
		$(this).addClass('current');
		$('.indicator').animate({marginLeft: (default_margin + (indicator_scroll * 4)) + 'px'}, {duration: scroll_speed, easing: 'easeInOutExpo'});
	});

	$('.submit-message').click(function() {
		$('.contact-status').html('<img src="imgs/loading.gif" alt="" />').show();
		var inputs = $('form').serialize();
		$.ajax({
			type: 'POST',
			url: './handlers/contact.php',
			data: inputs,
			success: function(response) {
				var data = response.split('|');
				$('.contact-status').hide();
				if(data[0] == 1) {
					$('.contact-content').slideUp(500).slideDown(500);
					setTimeout(function() {
						$('form').remove();
						$('.contact-content h2').addClass('thanks');
						$('.contact-content p').html(data[1]);
					}, 500);
					setTimeout(function(){$('#contact-container').animate({top: '-678px'}, 500);}, 5000)
				} else {
					$('.contact-status').html('All fields are required to send me an email.').css('padding', '6px 0 0 0').slideDown(500);
					return false;
				}
			}
		});
	});
});
