﻿$(document).ready(function() {
    var wheight = $(window).height();
    var allheight = $('.footerContainer').height() + $('.headerContainer').height() + $('.preHeaderContainer').height() + 26;
    var central = $('.centralContainer');
    central.css('min-height', wheight - allheight - 32);
    var contentLeft = $('#contentLeft');
    if (contentLeft.length > 0) {
        contentLeft.css('min-height', wheight - allheight - 32);
        if (contentLeft.height() < central.height())
            contentLeft.css('min-height', central.height());
    }

    AddImageZoom();
    SetMainMenu();
});

$(window).resize(function() {
    var wheight = $(window).height();
    var allheight = $('.footerContainer').height() + $('.headerContainer').height() + $('.preHeaderContainer').height() + 26;
    var central = $('.centralContainer');
    central.css('min-height', wheight - allheight - 32);
    var contentLeft = $('#contentLeft');
    if (contentLeft.length > 0) {
        contentLeft.css('min-height', wheight - allheight - 32);
        if (contentLeft.height() < central.height())
            contentLeft.css('min-height', central.height());
    }
});

function SetMainMenu() {
    $('.mainMenu a.firstLevel').hover(
        function() {
            if ($(this).parent().find('ul li').length)
                $(this).parent().find('ul').show();
        },
        function() {
            $(this).parent().find('ul').hide()
        }
    );

    $('li.firstLevel ul').hover(
        function() {
            $(this).show();
        },
        function() {
            $(this).hide();
        }
    );

        $('.mainMenu li.firstLevel:last-child ul').css('margin-left', '-120px');
}

function SetEnterLogin() {
    $(".AspNet-Login-PasswordPanel input, .AspNet-Login-UserPanel input").keypress(function(e) {
        if (e.which == 13) {
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$BaseContentPlaceHolder$ContentPlaceHolder$lgnUserLogin$LoginLinkButton", "", true, "ctl00$ctl00$BaseContentPlaceHolder$ContentPlaceHolder$lgnUserLogin", "", false, true))
        }
    });
}

function SetDroppedOldMessages() {
    $(".oldMessageTheme > .plus").toggle(
      function() {
          $(this).parent().parent().find(".oldMessagesByTheme").slideDown(300);
          $(this).html("--");
      },
      function() {
          $(this).parent().parent().find(".oldMessagesByTheme").slideUp(300);
          $(this).html("+");
      }
    );
}

function AddImageZoom() {
    if (jQuery('.pikachoose').length == 0) {
        var images = jQuery('#contentPage img.zoomImage').wrap('<div class="wrapImage"></div>');
        if (images != 'undefined' && images.length > 0) {
            images.each(function() {
                jQuery(this).after('<a class="zoomLupa" href="' + jQuery(this).attr('src').replace('/Small/', '/Big/').replace('/Medium/', '/Big/') + '"></a>');
                jQuery(this).parent().css('position', 'relative');
                var url = jQuery(this).parent().find('a.zoomLupa');
                var imgDesc = jQuery(this).attr('alt');
                if (imgDesc != null && imgDesc != '')
                    url.attr('title', imgDesc);
                url.fancybox({
                    'titlePosition': 'over',
                    'overlayColor': '#000',
                    'overlayOpacity': 0.6
                });
            });
        }
    }
}

//function OpenPopup(src) {
//    jQuery('.popup .popupImg img').remove();
//    jQuery('.popup .popupImg').append('<img src="' + src + '" />');
//    jQuery('.overlay').css('display', 'block');
//    jQuery('.popup').fadeIn(300);
//}

function ClosePopup() {
    jQuery('.popup').fadeOut(300);
    jQuery('.overlay').css('display', 'none');
}
