var currentUrlPath = window.location.pathname;



$(window).resize(function(){
    centerDocument();
    menuVerticalAlign();
    headerWidth();
    footerWidth();
    widthControl();
});


$(window).load(function(){

//    if(currentUrlPath.length > 1){
//        $.unblockUI();
//    }

    centerDocument();
    menuVerticalAlign();
    headerWidth();
    footerWidth();
    widthControl();


    $('.splash-cat-block-left, .splash-cat-block-right').hover(
        function()
        {
            $('h3.cat-link a', this).css('color','#FFF');
        },
        function()
        {
            $('h3.cat-link a', this).css('color','#C4B7B1');
        }
    );

    equalHeight($('.post-gallery-image'));


    if(currentUrlPath.indexOf('staff') != -1)
    {
        equalHeight($('.staff-entry > div'));
    }

    else if ( currentUrlPath.indexOf('articles') != -1 )
    {
        equalHeight($('.subcat-post-format'));
    }

})


$(function(){



    if(currentUrlPath.length > 1)
    {

//         $('#post-gallery img').lazyload({
//             //placeholder : "img/grey.gif",
//             effect      : "fadeIn",
//             threshold : 200
//         });


         //will work only on gallery pages
        if($('#post-gallery').length > 0){

            
//            $.blockUI({
//                css: {
//                    border: '1px solid #CCC',
//                    padding: '15px',
//                    backgroundColor: '#000',
//                    '-webkit-border-radius': '10px',
//                    '-moz-border-radius': '10px',
//                    opacity: .7,
//                    color: '#fff'
//                },
//                message: '<h1>אנא המתן ...</h1>'
//            });


            var _nav = $('#pagi a');
            var _tabs = $('#post-gallery tab');
            var _images = new Array();
            
            $(_nav).live('click', function(){
                var _goTo = $(this).attr('href');
                var _aT = $(''+_goTo+'');
                $(this).parent('li').addClass('current').siblings().removeClass('current');
                $(_aT).siblings('.tab').removeClass('active').addClass('hide');
                $(_aT).addClass('active').removeClass('hide');
                $('img', _aT).each(function(){
                    var _cIMGSRC = $(this).attr('relsrc');
                    $(this).attr('src', _cIMGSRC);
                });
                window.location.hash = '#post-nav-title';
                return false;
            });
            

        }


        $('a.img-click').fancybox({
            'zoomSpeedIn': 200,
            'zoomSpeedOut': 200,
            'overlayShow': true,
            'imageScale' : true,
            'hideOnContentClick' : true,
            'centerOnScroll' : true
        });
    }

});


function menuVerticalAlign()
{
    var splashOverall = $('#splash-middle').height();
    var splashMenu = $('#splash-menu').height();
    var top = (splashOverall - splashMenu)/2;
    $('#splash-menu').css({'margin-top':top});
}

function centerDocument()
{
    var SizeS = getSize();
    var windowHeight = SizeS[0];
    var containerHeight = $('div#splash').height();
    var dif = windowHeight - containerHeight;
    if(dif > 0) {
        var margin = dif/2;
        $('div#splash').css({'margin-top':margin});
    } else {
        $('div#splash').css({'margin-top':'0'});
    }
}

function widthControl()
{
    var totalWidth = $(window).width();
    if(totalWidth < 960) {
        $('body').css('width','960px');
    } else {
        $('body').css('width','100%');
    }
}

function headerWidth()
{
    var totalWidth = $(window).width();
    var headerLeftWidth = totalWidth - 50;
    if(totalWidth < 960){
        $('#header-left').css('width','910px');
    } else {
        $('#header-left').css('width',headerLeftWidth);
    }
}

function footerWidth()
{
    var totalWidth = $(window).width();
    var footerRightWidth = totalWidth - 50;
    if(totalWidth < 960){
        $('#footer-right').css('width','910px');
    } else {
        $('#footer-right').css('width',footerRightWidth);
    }
}

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function getSize() {
    var sizeS = new Array();
    sizeS[0] = $(window).height();
    sizeS[1] = $(document).height();
    return sizeS;
}
