﻿function AYS(tekst) {
    return confirm(tekst);
}

(function ($) {
    if ($.browser.mozilla) {
        $.fn.disableTextSelect = function () {
            return this.each(function () {
                $(this).css({
                    'MozUserSelect': 'none'
                });
            });
        };
        $.fn.enableTextSelect = function () {
            return this.each(function () {
                $(this).css({
                    'MozUserSelect': ''
                });
            });
        };
    } else if ($.browser.msie) {
        $.fn.disableTextSelect = function () {
            return this.each(function () {
                $(this).bind('selectstart.disableTextSelect', function () {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function () {
            return this.each(function () {
                $(this).unbind('selectstart.disableTextSelect');
            });
        };
    } else {
        $.fn.disableTextSelect = function () {
            return this.each(function () {
                $(this).bind('mousedown.disableTextSelect', function () {
                    return false;
                });
            });
        };
        $.fn.enableTextSelect = function () {
            return this.each(function () {
                $(this).unbind('mousedown.disableTextSelect');
            });
        };
    }
})(jQuery);

function FillContent() {
    if (topContentArray.length > 0) {
        var carouselLinks = $('.CarouselLinkHolder .CarouselLink');
        carouselLinks.click(function () {
            $(document).stopTime();
            ChangeCarousel(this);
        });

        carouselLinks.hover(
                    function () { $(this).animate({ paddingLeft: '13px' }, 100); },
                    function () { $(this).animate({ paddingLeft: '3px' }, 100); }
                );

        $(carouselLinks[0]).addClass('CarouselLinkActive');

        InsertCarouselContent(0);
        if (topContentArray.length > 1) {
            $(document).everyTime(5000, function () {
                animateCarousel($('.CarouselLinkActive'));
            }, 0);
        }
        for (var i = 0; i < topContentArray.length; i++) {
            $('<img src="' + topContentArray[i][1] + '" alt="' + topContentArray[i][2] + '" />').prependTo(carouselLinks[i]);
        }
    }
    else {
        var carouselLinks = $('.CarouselLinkHolder .CarouselLink');
        carouselLinks.unbind('click');
    }
}

function animateCarousel(currentCarouselLink) {
    var index = $('.CarouselLink').index(currentCarouselLink);
    if (index < topContentArray.length - 1) {
        index = index + 1;
    }
    else {
        index = 0
    }

    var carrouselLink = $('.CarouselLinkHolder .CarouselLink:eq(' + index + ')');

    $('.CarouselLinkHolder .CarouselLink:eq(' + index + ')').animate({
        paddingLeft: "13px"
    }, 300);

    $('.CarouselLinkHolder .CarouselLink:eq(' + index + ')').animate({
        paddingLeft: "3px"
    }, 300);

    ChangeCarousel($('.CarouselLinkHolder .CarouselLink:eq(' + index + ')'));
}

function ChangeCarousel(carrouselLink) {
    var carouselLinks = $('.CarouselLinkHolder .CarouselLink').removeClass('CarouselLinkActive');
    $(carrouselLink).addClass('CarouselLinkActive');
    var index = $('.CarouselLink').index(carrouselLink);
    InsertCarouselContent(index);
}

function InsertCarouselContent(arrayPosition) {
    if ($('.CarouselItem img').length > 0) {
        $('.CarouselItemTekst').fadeOut('normal', function () {
            $('.CarouselItem img').replaceWith('<img src="' + topContentArray[arrayPosition][1] + '" alt="' + topContentArray[arrayPosition][2] + '" />');
            $('.CarouselItemTitle').attr("href", topContentArray[arrayPosition][0]);
            $('.CarouselItemTitle').html(topContentArray[arrayPosition][2]);
            $('.CarouselItemTekst span').html(topContentArray[arrayPosition][3]);
            $('.CarouselItemTekst').fadeIn();
        });
    }
    else {
        $('<img src="' + topContentArray[arrayPosition][1] + '" alt="' + topContentArray[arrayPosition][2] + '" />').prependTo('.CarouselItem');
        $('.CarouselItemTitle').attr("href", topContentArray[arrayPosition][0]);
        $('.CarouselItemTitle').html(topContentArray[arrayPosition][2]);
        $('.CarouselItemTekst span').html(topContentArray[arrayPosition][3]);
    }
}



//root.master
function Start() {
    $('.langSelector .RadComboBox .rcbInputCellLeft input').css("display", "none");
    $('.langSelector .RadComboBox .rcbInputCellLeft').css("text-align", "center");
    $('.langSelector .RadComboBox .rcbInputCellLeft').css("vertical-align", "middle");

    if ($('.langSelector .RadComboBox .rcbInputCellLeft:first').has('img').length < 1) {
        $('<img alt="" src="' + activeLangImg + '" />').appendTo('.langSelector .RadComboBox .rcbInputCellLeft');
    }

    $('.MainMenuItem').hover(function () {
        $(this).toggleClass('MainMenuItemActive');
    });

    $('.OutdexTab').click(function () {
        ChangeTabs(this);
    });

    ChangeTabs('TablPopular', "TabNew");

    SetNewsRelatedHeight();
}

function SetNewsRelatedHeight() {

    if ($("#RelatedNews .RelatedNewsInnerItemHolder a").length <= 3) {
        $("#RelatedNews").css('height', ($("#RelatedNews .RelatedNewsInnerItemHolder a").length == 3 ? 185 : 170) - (3 - $("#RelatedNews .RelatedNewsInnerItemHolder a").length) * 45);
        $("#RelatedNews .RelatedNewsItemHolder").css('height', ($("#RelatedNews .RelatedNewsInnerItemHolder a").length == 3 ? 159 : 150) - (3 - $("#RelatedNews .RelatedNewsInnerItemHolder a").length) * 45);
        $("#RelatedNews .RelatedNewsMoveUp, #RelatedNews .RelatedNewsMoveDown").css("display", "none");
    }
    else {
        $("#RelatedNews .RelatedNewsInnerItemHolder").css('height', $("#RelatedNews .RelatedNewsInnerItemHolder a").length * 55);
        AttachNewsRelatedMove();
    }

    if ($("#TagRelatedContent .RelatedNewsInnerItemHolder a").length < 3) {
        $("#TagRelatedContent").css('height', ($("#TagRelatedContent .RelatedNewsInnerItemHolder a").length == 3 ? 185 : 170) - (3 - $("#TagRelatedContent .RelatedNewsInnerItemHolder a").length) * 45);
        $("#TagRelatedContent .RelatedNewsItemHolder").css('height', ($("#TagRelatedContent .RelatedNewsInnerItemHolder a").length == 3 ? 159 : 144) - (3 - $("#TagRelatedContent .RelatedNewsInnerItemHolder a").length) * 45);
        $("#TagRelatedContent .RelatedNewsMoveUp, #TagRelatedContent .RelatedNewsMoveDown").css("display", "none");
    }
    else {
        $("#TagRelatedContent .RelatedNewsInnerItemHolder").css('height', $("#TagRelatedContent .RelatedNewsInnerItemHolder a").length * 55);
        AttachContentTagRelatedMove();
    }
}

var relatedAnimation = false;
var tagRelatedAnimation = false;

function AttachNewsRelatedMove() {

    var innerItemsHolder = $("#RelatedNews  .RelatedNewsInnerItemHolder");

    $(".RelatedNewsMoveUp, .RelatedNewsMoveDown").disableTextSelect();

    $("#RelatedNews .RelatedNewsMoveDown").click(function () {
        if (!relatedAnimation) {
            relatedAnimation = true;
            innerItemsHolder.animate({
                marginTop: (parseInt(innerItemsHolder.css("margin-top")) * -1 < parseInt(innerItemsHolder.css("height")) - 214 ? parseInt(innerItemsHolder.css("margin-top")) - 55 + "px" : innerItemsHolder.css("margin-top"))
            },
                    100,
                    function () { relatedAnimation = false; });
        }
    });

    $("#RelatedNews .RelatedNewsMoveUp").click(function () {
        if (!relatedAnimation) {
            relatedAnimation = true;
            innerItemsHolder.animate({
                marginTop: (parseInt(innerItemsHolder.css("margin-top")) < 0 ? parseInt(innerItemsHolder.css("margin-top")) + 55 + "px" : innerItemsHolder.css("margin-top"))
            },
                    100,
                    function () { relatedAnimation = false; });
        }
    });
}

function AttachContentTagRelatedMove() {

    var innerTagItemsHolder = $("#TagRelatedContent  .RelatedNewsInnerItemHolder");

    $(".RelatedNewsMoveUp, .RelatedNewsMoveDown").disableTextSelect();

    $("#TagRelatedContent .RelatedNewsMoveDown").click(function () {
        if (!tagRelatedAnimation) {
            tagRelatedAnimation = true;
            innerTagItemsHolder.animate({
                marginTop: (parseInt(innerTagItemsHolder.css("margin-top")) * -1 < parseInt(innerTagItemsHolder.css("height")) - 214 ? parseInt(innerTagItemsHolder.css("margin-top")) - 55 + "px" : innerTagItemsHolder.css("margin-top"))
            },
                    100,
                    function () { tagRelatedAnimation = false; });
        }
    });

    $("#TagRelatedContent .RelatedNewsMoveUp").click(function () {
        if (!tagRelatedAnimation) {
            tagRelatedAnimation = true;
            innerTagItemsHolder.animate({
                marginTop: (parseInt(innerTagItemsHolder.css("margin-top")) < 0 ? parseInt(innerTagItemsHolder.css("margin-top")) + 55 + "px" : innerTagItemsHolder.css("margin-top"))
            },
                    100,
                    function () { tagRelatedAnimation = false; });
        }
    });
}

function PostBackPage(btnId, btnLogin) {
    $('#' + btnLogin).click(function (e) {
        e.preventDefault();
    });
    $('#' + btnLogin).attr("href","javascript:void(0);");
    __doPostBack(btnId.toString().replace("_", "$"), '');
}

function SetTBUserNameValue(tbId) {
    $('#' + tbId).val('');
    $('#' + tbId).removeAttr('onfocus');
}

function SetTBPasswordValue(tbid, lblId) {
    $('#' + lblId).css('display', 'none');
    $('#' + tbid).removeAttr('onfocus');
}

function AlertErrors(errorMessage) {
    alert(errorMessage);
}

function ChangeTabs(tab) {

    if ($(tab).hasClass("OutdexTabInActive")) {
        $(tab).toggleClass("OutdexTabInActive");
        $(tab).siblings('.OutdexTabsContent').toggleClass("OutdexTabsContentVisible");
        $(tab).siblings('.OutdexTab').toggleClass("OutdexTabInActive");
    }
}

function OpenRegistration() {
    var wnd = GetWnd();
    wnd.SetUrl("/Registration.aspx");
    wnd.show();
}

function OpenProfile(userId) {
    var wnd = GetWnd();
    wnd.SetUrl("/Profile.aspx?UserId=" + userId);
    wnd.show();
}

function OpenForgot() {
    var wnd = GetWnd();
    wnd.SetUrl("/ResetUser.aspx");
    wnd.show();
}

