/**
 * Sean-Nieuwoudt.com Control Script
 *
 * @copyright (c) 2009
 * @version 1.0
 */

$(document).ready(function(){

   	var intOverallDelta = 0;
   	var state 			='hi';
	var adjustSpeed 	= 14;

    $.preloadCssImages();
    
	$('#hi').ready(function(){
	
    	intOverallDelta = parseInt($('#hi').css('margin-top').replace('px', ''));
	
	});
    
	$(document).mousewheel(function(evt, delta){
	
		if(delta > 0){
		
			if(intOverallDelta > 0) {
			
				return false;
				
			}
			
			intOverallDelta += adjustSpeed;
			
			$('#hi').css("margin-top", intOverallDelta + 'px');
			
		} else if(delta < 0) {
			
			intOverallDelta -= adjustSpeed;
			
			$('#hi').css("margin-top", intOverallDelta + "px");
		
		}
	
	});
	
	$(document).bind('keypress', function(e){
	
		var key = (e.keyCode ?  e.keyCode : e.charCode);
		
		if(key == 38) {
		
			if(intOverallDelta > 0) {
			
				return false;
				
			}
		
			intOverallDelta += adjustSpeed;
			
			$('#hi').css('margin-top', intOverallDelta + 'px');
		
		} else if (key == 40) {
		
			intOverallDelta -= adjustSpeed;
			
			$('#hi').css('margin-top', intOverallDelta + 'px');
		
		}
	
	});
    
    $('#body').show();

    $('#footer').show();

    $('div.up img').bind('click', function(){
        
        $('#footer a').removeClass('active');
        
    });

    $('a.navigation').bind('click', function(){

       $('#footer a').removeClass('active');

       return false;

    });

    $('.mnu-hi, div#upAbout img').bind('click', function(){

        $('.mnu-hi').addClass('active');

        $('#hi').animate( { marginTop:"0px" }, { duration: 1200, easing: 'easeOutElastic' });
        
        intOverallDelta = 0;

        state = 'hi';

    });

    $('.mnu-about, div#upContact img').bind('click', function(){

        $('.mnu-about').addClass('active');

        $('#hi').animate( { marginTop:"-1200px" }, { duration: 1200, easing: 'easeOutElastic' });
        
        intOverallDelta = -1200;

        state = 'about';

    });

    $('.mnu-contact').bind('click', function(){

        $('.mnu-contact').addClass('active');

        $('#hi').animate( { marginTop:"-2200px" }, { duration: 1200, easing: 'easeOutElastic' });
        
        intOverallDelta = -2200;

        state = 'contact';

    });

    $('a#send').bind('click', function(){

        var email   = $('#email').val();
        var subject = $('#subject').val();
        var message = $('#message').val();

        $('p#email-error').hide();

        $.post("do/contact", { email: email, subject: subject, message: message },
           function(data) {

             eval('data = ' + data);

             if(data.success) {

                $('#frmContact').fadeOut('slow',function(){
                    $('#thanks').show('fast', function(){
                        $('#copyright').animate( { top:"1285px" }, { duration: 1200, easing: 'easeOutElastic' });
                    });
                });

             } else {

                $('p#email-error').html(data.message);
                $('p#email-error').show();
                $('#copyright').animate( { top:"1575px" }, { duration: 1200, easing: 'easeOutElastic' });

             }
             
        });

        return false;

    });

    $('div#shadow').fadeOut('slow');

});