
$(document).ready(function () {

    // Set listener Box
    setListernerBox();

    // Set Menu
    setMenu();

    // Set Layer No Result
    setLayerNoResult();

    // Set Job
    setJob();

    //
    initIsotope();
});

$(window).resize(
    function () {
        // Set Menu
        setMenu();
    });

    function initIsotope() {
        // Isotope
        var $boxContainer = $('#boxContainer');

        $boxContainer.isotope({
            itemSelector: '.element',
            masonry: { columnWidth: 226 }
        });

        $boxContainer.infinitescroll({
            navSelector: '#page_nav',    // selector for the paged navigation 
            nextSelector: '#page_nav a',  // selector for the NEXT link (to page 2)
            itemSelector: '.element',     // selector for all items you'll retrieve
            donetext: 'No more pages to load.',
            loadingImg: 'http://i.imgur.com/qkKy8.gif',
            debug: false,
            errorCallback: function () {
                //alert('error');
                // fade out the error message after 2 seconds
                //$('#infscr-loading').animate({ opacity: .8 }, 2000).fadeOut('normal');
            }
        },
        // call Isotope as a callback
        function (newElements) {

            //alert(0);
            $boxContainer.isotope('appended', $(newElements));

            // Set listener Box
            setListernerBox();
        }
    );}

    function setListernerBox() {
        var objBoxArray = $('.content').find('.boxCnt');
        for (i = 0; i < objBoxArray.length; i++) {
            var currentObjBox = objBoxArray.eq(i);
            $(currentObjBox).bind("click", function () {
                var sUrl = $(this).find('td > h2 > a').attr('href');
                if (sUrl != undefined)
                    document.location.href = sUrl;
            });
        }
    }

function setMenu() {
    if ($('.navigationCnt').length > 0) {
        var nWidth = $(window).width();
        var nHeight = $(window).height();

        if (nHeight < 565)
            nHeight = 565;

        $('.navigationCnt').css({ 'height': nHeight + 'px' });
        $('.navigationCnt').show();
    }
}

function setLayerNoResult() {
    if ($('#Panel_NoResult').length > 0) {
        var nWidth = $(window).width();
        var nHeight = $(window).height();

        $('#Panel_NoResult').css({ 'width': nWidth + 'px' });
        $('#Panel_NoResult').css({ 'height': nHeight + 'px' });
    }
}


function setJob() {
    if ($('.job').length > 0) {
        var nHeight = $('.detailJob').height();
        nHeight = nHeight + 133;
        $('.job').css({ 'height': nHeight + 'px' });
    }
}

