$(function () {
    setTimeout(ShowWebsite, 750);
    PreparePlatforms(); 
    BindQtip();
});

function ShowWebsite() {
    //$('body').fadeIn('slow');
    $('body').fadeIn('slow', 'easeOutSine', function () { 
        $('body').css('display', 'block');
    });
}

//Platform functionality
var rightPlatform;
var leftPlatform;
var bodyWidth;
var flagLeft = null;

function PreparePlatforms() { 
    rightPlatform = $('.raise.the-right');
    leftPlatform = $('.raise.the-left');
    bodyWidth = $('html').width();

    $('html').bind('mousemove', function (e) {
        if (e.pageX < bodyWidth / 2 && (flagLeft === null || flagLeft === false)) {

            TogglePlatforms(rightPlatform, leftPlatform);
            flagLeft = (flagLeft == null ? false : true); //browser speed optimization

        } else if (e.pageX > bodyWidth / 2 && (flagLeft === null || flagLeft === true)) {

            TogglePlatforms(leftPlatform, rightPlatform);
            flagLeft = (flagLeft == null ? true : false); //browser speed optimization
        }
    }).bind('mouseleave', function () {
        //reset all platform functionalities
        $(rightPlatform).add(leftPlatform).stop().animate({
            opacity: 0
        }, 700, 'easeOutSine');
        flagLeft = null;
    }).bind('click', function (e) {
        //return;
        if (e.pageX < bodyWidth / 2) {
            window.location = "immigration/";
        } else {
            window.location = "education/";
        }
    });
    
    var a=0;
}

function TogglePlatforms(PlatformToLower, PlatformToRaise) { 

//    $(PlatformToLower).stop().animate({
//        opacity: 0
//    }, _animationSpeed, 'easeOutSine', function () {
//        $(PlatformToRaise).stop().animate({
//            opacity: 0.6
//        }, _animationSpeed, 'easeOutSine');
//    });

    $(PlatformToLower).stop().animate({
        opacity: 0
    }, 3000, 'easeOutExpo');

    $(PlatformToRaise).stop().animate({
        opacity: 0.8
    }, 500, 'easeOutSine');

}
// End Platform functionality

function BindQtip() {
    $('#partners ul.logos li img').qtip({
        content: {
            attr: 'title'
        },
        style: {
            classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-tipsy ui-tooltip-rounded', 
            tip: 'topCenter'
        }, 
        position: {
            my: 'top center',
            at: 'bottom center'
        },
        show: {
            effect: function (offset) {
                $(this).fadeIn(300); 
            }
        },
        hide: {
            effect: function (offset) {
                $(this).fadeOut(100); 
            }
        }
    });
}
