$(document).ready(function () {

    $("#homei, #abouti, #contacti, #corpi, #cani, #searchi, .menu").css({ "visibility": "hidden" });
    var h = $(window).height() / 2;
    var leftH = h - 80;
    $("#main-content .left").css({ "height": leftH });
    $('#main-content .left').jScrollPane();

    var feedH = h - 430;
    $("#bio-wrapper .feed").css({ "height": feedH });

    $('.links').jScrollPane();
    $('.feed').jScrollPane();

    QueryLoader.init();


    $("a.home").click(function () {

        var w = $(window).width() / 2;
        var h = $(window).height() / 2;

        $("#zoomMe").animate({ 'width': '100%', 'top': '0px', 'left': '0px' }, { duration: 1000, easing: 'easeInOutQuint' });


        var leftH = h - 20;


        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(500, function () {
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
            $("#home").fadeIn(100);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });

    });

    $("a.about").click(function () {
        var w = $(window).width() / 2;
        var h = $(window).height() / 2;

        if (h < 300) {
            var bg = h - 2100;
        }

        if (h > 300 && h < 400) {
            var bg = h - 2170;
        }

        if (h > 400 && h < 500) {
            var bg = h - 2100;
        }

        if (h > 500 && h < 570) {
            var bg = h - 2600;
        }

        if (h > 570) {
            var bg = h - 2700;
        }

        $("#zoomMe").animate({ 'width': '400%', 'top': bg, 'left': -w }, { duration: 1000, easing: 'easeInOutQuint' });


        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(500, function () {

            $("#about").fadeIn(100);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();



        });


    });

    $("a.corp").click(function () {
        var w = $(window).width();
        var h = $(window).height() / 2;

        if (h < 300) {
            var bg = h - 2100;
        }

        if (h > 300 && h < 400) {
            var bg = h - 2170;
        }

        if (h > 400 && h < 500) {
            var bg = h - 2100;
        }

        if (h > 500 && h < 570) {
            var bg = h - 2600;
        }

        if (h > 570) {
            var bg = h - 2700;
        }

        $("#zoomMe").animate({ 'width': '300%', 'top': bg, 'left': -w }, { duration: 1000, easing: 'easeInOutQuint' });

        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(500, function () {
            $("#corp").fadeIn(100);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });


    });

    $("a.search").click(function () {
        var w = $(window).width();
        var h = $(window).height() / 2;

        if (h < 300) {
            var bg = h - 1100;
        }

        if (h > 300 && h < 400) {
            var bg = h - 1170;
        }

        if (h > 400 && h < 500) {
            var bg = h - 1100;
        }

        if (h > 500 && h < 570) {
            var bg = h - 1600;
        }

        if (h > 570) {
            var bg = h - 1700;
        }

        $("#zoomMe").animate({ 'width': '200%', 'top': bg, 'left': -w }, { duration: 1000, easing: 'easeInOutQuint' });

        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(500, function () {
            $("#search").fadeIn(100);
            var h = $(window).height() / 2;
            var leftH = h - 120;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });

    });

    $("a.can").click(function () {
        var w = $(window).width() * 3;
        var h = $(window).height() / 2;

        if (h < 300) {
            var bg = h - 2100;
        }

        if (h > 300 && h < 400) {
            var bg = h - 2170;
        }

        if (h > 400 && h < 500) {
            var bg = h - 2100;
        }

        if (h > 500 && h < 570) {
            var bg = h - 2600;
        }

        if (h > 570) {
            var bg = h - 2700;
        }

        $("#zoomMe").animate({ 'width': '400%', 'top': bg, 'left': -w }, { duration: 1000, easing: 'easeInOutQuint' });

        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(500, function () {
            $("#can").fadeIn(100);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });

    });

    $("a.contact").click(function () {
        var w = $(window).width() / 3;
        var h = $(window).height() / 2;

        if (h < 300) {
            var bg = h - 1100;
        }

        if (h > 300 && h < 400) {
            var bg = h - 1170;
        }

        if (h > 400 && h < 500) {
            var bg = h - 1100;
        }

        if (h > 500 && h < 570) {
            var bg = h - 1600;
        }

        if (h > 570) {
            var bg = h - 1700;
        }

        $("#zoomMe").animate({ 'width': '180%', 'top': bg, 'left': -w }, { duration: 1000, easing: 'easeInOutQuint' });

        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(500, function () {
            $("#contact").fadeIn(100);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });
    });


    //adds highlight class
    $('div.menu a').click(function () {
        $('div.menu a').removeClass("highlight");
        $(this).addClass('highlight');

    });

    //Adds class to current selection onload
    var pound = window.location.href.slice(window.location.href.indexOf('#'));




    if (pound == '/') {
        $('.home').addClass("highlight");

        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(1, function () {
            $("#home").fadeIn(1);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });
    }

    else if (pound == '#home') {
        $('.home').addClass("highlight");
        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(1, function () {
            $("#home").fadeIn(1);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });
    }

    else if (pound == '#about-us') {
        $('.about').addClass("highlight");
        $('.about').click();
    }

    else if (pound == '#corporate-assistance') {
        $('.corp').addClass("highlight");
        $('.corp').click();
    }

    else if (pound == '#recruiter-profiles') {
        $('.can').addClass("highlight");
        $('.can').click();
    }

    else if (pound == '#search-jobs') {
        $('.search').addClass("highlight");
        $('.search').click();
    }

    else if (pound == '#contact-us') {
        $('.contact').addClass("highlight");
        $('.contact').click();
    } else {
        $('.home').addClass("highlight");

        $("#main-content").fadeOut('fast');
        $("#main-content > div").hide();
        $("#main-content").fadeIn(1, function () {
            $("#home").fadeIn(1);
            var h = $(window).height() / 2;
            var leftH = h - 80;
            $("#main-content .left").css({ "height": leftH });
            $('#main-content .left').jScrollPane();
        });
    }

    //Jobs
    $('#main-content .right .button').click(function () {
        $.blockUI({ message: $('#job_pop'), css: { width: '680px', padding: '10px', top: '20px'} });
        $("div.hj-content").jScrollPane();

    });

    $('#exit').click(function () {
        $.unblockUI();
        return false;
    });

    //Scroll Planes

    //Bio Section
    $("div.people a:last").css({ "border-right": "none" });
    $("div.people a:first").addClass('highlight');
    $("#bio-wrapper > div").not(":first").hide();


    $("div.people a").click(function () {

        $("div.people a").removeClass('highlight');
        $(this).addClass('highlight');
        var idToLoad = $(this).attr("id").split('-');
        $("#bio-wrapper").find("div:visible").fadeOut("fast", function () {
            $(this).parent().find("#" + idToLoad[0]).fadeIn();
            $("#" + idToLoad[0]).children().fadeIn();
            $('.right_content').jScrollPane();
            $("#" + idToLoad[0] + " div").show();
            $("#" + idToLoad[0] + " .links").jScrollPane();
            $("#" + idToLoad[0] + " .feed").jScrollPane();


        });

    });


    //Resizes
    var w = $(window).width() / 2;
    var h = $(window).height() / 2;
    var jobs = w - 350;
    $.blockUI.defaults.css.left = jobs;

    var footer = w - 425;
    $("#footer .wrap").css({ "margin-left": footer })

    var feedH = h - 100;
    $("#bio-wrapper .feed").css({ "height": feedH });

    //fixees dotted random border
    $("a").bind("focus", function () {
        if (this.blur) this.blur();
    });

    $(".jScrollPaneContainer").bind("focus", function () {
        if (this.blur) this.blur();
    });

    $("#exit").bind("focus", function () {
        if (this.blur) this.blur();
    });

    var portalH = h + 150;

    if (w <= 720) {
        var portalW = w + 500;
        var portalL = -$(window).width() / 6 + 60;
    } else if (w > 720 && w < 1400) {
        var portalW = w + 500;
        var portalL = -$(window).width() / 5 + 60;
    } else {
        var portalW = w + 700;
        var portalL = -$(window).width() / 4;
    }

    if (h <= 466) {
        var portalH = h;
    }

    $("#jobPortal").css({ "height": portalH });
    $("#jobPortal").css({ "width": portalW });
    $("#jobPortal").css({ "margin-left": portalL });

    var job_popupH = h;
    $("#job_pop").css({ "height": job_popupH });
    $("div.hj-content").css({ "height": job_popupH - 100 });

    $(window).resize(function () {
        var w = $(window).width() / 2;
        var h = $(window).height() / 2;
        var portalH = h + 150;

        if (w <= 720) {
            var portalW = w + 500;
            var portalL = -$(window).width() / 6 + 60;
        } else if (w > 720 && w < 1400) {
            var portalW = w + 500;
            var portalL = -$(window).width() / 5 + 60;
        } else {
            var portalW = w + 700;
            var portalL = -$(window).width() / 4;
        }

        if (h <= 466) {
            var portalH = h;
        }

        $("#jobPortal").css({ "height": portalH });
        $("#jobPortal").css({ "width": portalW });
        $("#jobPortal").css({ "margin-left": portalL });

        var job_popupH = h;
        $("#job_pop").css({ "height": job_popupH });
        $("div.hj-content").css({ "height": job_popupH - 100 });

        var footer = w - 425;
        $("#footer .wrap").css({ "margin-left": footer })

    });



    //Iframe redirects

    $("a.recjobID").click(function () {
        var title = $(this).attr("title");
        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&jid=";
        window.frames["jobPortal"].location.href = url + title;
        $('.search').click();

    });


    $("a.by-jobID").click(function () {
        var title = $(this).attr("title");
        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&jid=";
        window.frames["jobPortal"].location.href = url + title;
        $('.search').click();
        $.unblockUI();

    });

    $("a.by-type").click(function () {
        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&f=by-type";
        window.frames["jobPortal"].location.href = url;
        $('.search').click();
        $.unblockUI();
    });

    $("a.by-region").click(function () {
        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&f=by-region";
        window.frames["jobPortal"].location.href = url;
        $('.search').click();
        $.unblockUI();
    });

    $("a.by-experience").click(function () {
        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&f=by-experience";
        window.frames["jobPortal"].location.href = url;
        $('.search').click();
        $.unblockUI();
    });

    $("a.view_page").click(function () {
        var title = $(this).attr("title");
        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&r=";
        window.frames["jobPortal"].location.href = url + title;
        $('.search').click();

    });


    var jid = window.location.href.slice(window.location.href.indexOf('?'));

    if (jid.length > 4) {
        var newjid = jid.substring(5);

    

        var url = "http://services.skyfirmjobs.net/testapp/default.aspx?d=1003&jid=";
        window.frames["jobPortal"].location.href = url + newjid;
        $('.search').click();

        setTimeout(function () { $("#home").hide(); }, 1000);
    }

});      //End Global Function



