$(document).ready(function() {
        
        var cache = new Array();
        
        preloadImages('images/controller-option-over.png', 'images/button-left-over.png', 'images/button-right-over.png');
        
        /*
        * CUFON REPLACEMENT */
        
        Cufon.replace('#root .controller-links li a span, #big-screen .page h2', { fontFamily: "Caviar Dreams"});
        
        /*
        * SCREEN ANIMATION */
        
        screenAnimation();
        
        /*
        * MY WORK */
        
        workInit();
        
        /*
        * LIGHTBOX INITIALIZATION */
        
        lightboxInit();
        
        
        /*
        * CONTACT FORM INITIALIZATION */
        
        contactFormInit();
        
        /*
        * IMAGE PRELOADER */
        
        function preloadImages() {
            var arg = arguments.length, img;
            for ( var i = 0; i < arg ; i++ ) {
                img = document.createElement('img');
                img.src = arguments[i];
                cache.push(img);
            }
        }
        
        
});


function workInit() {
    $("#slider-wrapper").slider({
            slideWidth: 600,
            slideSpeed: 1500,
            autoScrollTimer: 0,
            hasNavBar: true
    });
}

function screenAnimation() {
    /*
	$('#website-controller a').click(function(e) {
            e.preventDefault();
            var selPage = $(this).attr('title');
            
            if(selPage == "login-page") {
                $("#form-register").show();
                $("#account").hide();
                $('#pass-recovery').hide();
            }
			
            openScreen(selPage);
    });
    
    $('#big-screen .close-window').click(function(e) {
            e.preventDefault();
            closeScreen();
    });
    */
}

function contactFormInit() {
    $('#contact-name').focusin(function() {
            if ( $(this).val() == 'Name (required)' ) {
                $(this).val('');
            }
    });
    $('#contact-name').focusout(function() {
            if ( $(this).val().trim() == '' ) {
                $(this).val('Name (required)');
            }
    });
    $('#contact-email').focusin(function() {
            if ( $(this).val() == 'Email (required)' ) {
                $(this).val('');
            }
    });
    $('#contact-email').focusout(function() {
            if ( $(this).val().trim() == '' ) {
                $(this).val('Email (required)');
            }
    });
    $('#contact-subject').focusin(function() {
            if ( $(this).val() == 'Subject (required)' ) {
                $(this).val('');
            }
    });
    $('#contact-subject').focusout(function() {
            if ( $(this).val().trim() == '' ) {
                $(this).val('Subject (required)');
            }
    });
    $('#contact-message').focusin(function() {
            if ( $(this).val() == 'Message (required)' ) {
                $(this).val('');
            }
    });
    $('#contact-message').focusout(function() {
            if ( $(this).val().trim() == '' ) {
                $(this).val('Message (required)');
            }
    });
    
    $('#send-email-button').click(function(e) {
            e.preventDefault();
            $.post('email.php', {
                    name: $('#contact-name').val(),
                    email: $('#contact-email').val(),
                    subject: $('#contact-subject').val(),
                    message: $('#contact-message').val()
            }, function(data) {
                var response = '<div class="output-messages">'+ data +'</div>';
                $('#contact-form div.output-messages').remove();
                $('#contact-form').prepend(response);
                $('#contact-form div.output-messages').hide().fadeIn(500);
            })
    });
}


function lightboxInit() {
    $('a[rel*=lightbox]').lightBox();
}


/*
* TRIM FUNCTION
*/
String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};
