$(function(){

    $('#logo').fadeIn(1500, function(){
        $('#motto').animate({
            width: '587px'
        }, 4550, null, function(){
            $('#eye').fadeIn(750, function(){
                $('#menu').fadeIn(500, function(){
                    if (!jQuery.support.scriptEval) 
                        $(this).get(0).style.removeAttribute('filter');
                });
                $('#content').fadeIn(500, function(){
                    if (!jQuery.support.scriptEval) 
                        $(this).get(0).style.removeAttribute('filter');
                    applyAfterLoad();
                });
                $("#loading").fadeOut(250);
            });
        });
        
    });
    
    $("#loading").ajaxStart(function(){
        $(this).fadeIn();
    }).ajaxComplete(function(){
        $(this).fadeOut();
    });
    
    $("#menu a").click(function(){
        if ($(this).attr('href') != '#') {
        
            $("#content").load($(this).attr('href') + ' #content div.wrapper', null, function(){
                applyAfterLoad();
                initLytebox();
            });
        }
        return false;
    }).children('img').hover(function(){
        this.src = this.src.replace('_off', '_on');
    }, function(){
        this.src = this.src.replace('_on', '_off');
    });
    
    $('.btnPort').toggle(function(){
        $('li.hide').fadeIn();
    }, function(){
        $('li.hide').fadeOut();
    });
    
});

function applyAfterLoad(){

    $(".thumbnails").fadeTo(1, 0);
    
    $(".thumbnails").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 5,
        speed: 1500
    }).animate({
        height: '200px'
    }, 250).fadeTo(2500, 1);
    
    
    
    $(".thumbnails img").hover(function(){
        $(this).animate({
            width: '152px',
            height: '152px'
        });
    }, function(){
        $(this).animate({
            width: '142px',
            height: '142px'
        });
    });

    $("form#contactform").submit(function(){
		$("#sndBtn").fadeOut(150);
        $(".formoutput").load("ef_feedback.aspx?language=en #content div.wrapper", {
            firstname: $('#fname').val(),
            lastname: $('#lname').val(),
            email: $('#email').val(),
            subject: $('#subject').val(),
            message: $('#message').val(),
            snbtn: 'send'
        }, function() {
			$("#sndBtn").fadeIn(150);
		}).fadeIn(500);
        
        return false;
    });
    
}
