$(document).ready
(
    function()
    {
        $("#TagCenter").hide();
        $("#BgMain").hide();
        $("#BgEffect").hide();
        $("#Main").hide();
        $("#CopyRight").hide();
        $("#imgStatistic").hide();
        $("#Content").hide();
        $("#Line").hide();
        $("#Menu").hide();

        $("#Loading").html('<img src="' + SiteUrl + 'template/user/images/loading.gif" alt="" /><br />' + PleaseWaitTitle + ' ...');
        $("#Loading").show(150);

        //======================

        $('textarea[maxlength]').keyup
        (
            function()
            {
                var limit = parseInt($(this).attr('maxlength'));
                var text = $(this).val();
                var chars = text.length;

                if(chars > limit)
                {
                    var new_text = text.substr(0, limit);
                    $(this).val(new_text);  
                }
            }
        );

        //======================

        $("#TableMainFormContact input").focus
        (
            function()
            {
                $(this).css({"border":"1px solid #acacac"});
                $(this).next("span").css({"color":"#cf0000", "font-size":"9pt", "visibility": "hidden"});
            }
        );

        $("#TableMainFormContact input").each
        (
            function()
            {
                $(this).next("span").css({"color":"#cf0000", "font-size":"9pt", "visibility": "hidden"});
            }
        );

        $("#TableMainFormContact textarea").focus
        (
            function()
            {
                $(this).css({"border":"1px solid #acacac"});
                $(this).next("span").css({"color":"#cf0000", "font-size":"9pt", "visibility": "hidden"});
            }
        );

        $("#TableMainFormContact textarea").each
        (
            function()
            {
                $(this).next("span").css({"color":"#cf0000", "font-size":"9pt", "visibility": "hidden"});
            }
        );

        //======================  Scroll

        var win = $(window);
        var isResizing = false;
        win.bind
        (
            'resize',
            function()
            {
                if (!isResizing)
                {
                    isResizing = true;
                    var Content = $('#Content .ContentText');
                    Content.css({'width': Content.width, 'height': Content.height});
                    isResizing = false;
                    Content.jScrollPane({'showArrows': true});
                }
            }
        ).trigger('resize');

        //======================
    }
);

/***********************************************************************/

$(window).load
(
    function()
    {
        $("#Loading").hide("fast", ShowTagCenter);

        function ShowTagCenter()
        {
            $("#TagCenter").show(1500, ShowBgMain);
        }

        function ShowBgMain()
        {
            $("#BgMain").show(1000);
            $("#BgMain").slideDown(1000, ShowBgEffect);
        }

        function ShowBgEffect()
        {
            $("#BgEffect").show(1000);
            $("#BgEffect").slideDown(1000, ShowMain);
        }

        function ShowMain()
        {
            $("#Main").rotateAnimation(360);
            $("#Main").slideDown(800, ShowCopyRight);
        }

        function ShowCopyRight()
        {
            $("#CopyRight").fadeTo(500, 1);/*
            if (!BrowserType.msie)
                $("#imgStatistic").rotateAnimation(360);*/
            $("#imgStatistic").show(500, ShowMainChildren);
        }

        function ShowMainChildren()
        {/*
            if (!BrowserType.msie)
                $("#imgStatistic").rotateAnimation(0);*/
    
            $("#Content").show(800);
            $("#Content").slideDown(800);
            $("#Line").show(500);
            $("#Menu").slideDown(800);
        }

        //======================
    
        $('#Menu a').each
        (
            function()
            {
                $(this).mouseover
                (
                    function()
                    {
                        $(this).animate({"background-position":"5px"}, 100);
                        $(this).animate({"background-position":"-5px"}, 80);
                        $(this).animate({"background-position":"3px"}, 80);
                        $(this).animate({"background-position":"-3px"}, 60);
                        $(this).animate({"background-position":"2px"}, 60);
                        $(this).animate({"background-position":"-2px"}, 40);
                        $(this).animate({"background-position":"1px"}, 40);
                        $(this).animate({"background-position":"-1px"}, 20);
                        $(this).animate({"background-position":"1px"}, 10);
                    }
                );

                $(this).mouseout
                (
                    function()
                    {
                        $(this).animate({"background-position":"-155px"}, 100);
                        $(this).animate({"background-position":"-145px"}, 80);
                        $(this).animate({"background-position":"-153px"}, 80);
                        $(this).animate({"background-position":"-147px"}, 60);
                        $(this).animate({"background-position":"-152px"}, 60);
                        $(this).animate({"background-position":"-148px"}, 40);
                        $(this).animate({"background-position":"-151px"}, 40);
                        $(this).animate({"background-position":"-149px"}, 20);
                        $(this).animate({"background-position":"-150px"}, 10);
                    }
                );

                $(this).click
                (
                    function()
                    {
                        var pageURl = $(this).attr("href");

                        $("#Content").fadeTo("slow", 0, WaitToLoad);

                        function WaitToLoad()
                        {
                            $("#Content").html('<div style="text-align: center; margin-top: 50px;"><img src="' + SiteUrl + 'template/user/images/loading.gif" alt="" /></div>');

                            $("#Content").fadeTo("slow", 1, LoadContent);
                        }

                        function LoadContent()
                        {
                            $("#Content").load(pageURl, {action:"AjaxGetContent"}, ShowNewContent);
                        }

                        function ShowNewContent(){}

                        return false;
                    }
                );
            }
        );
    }
);

/***********************************************************************/

var BrowserType = $.browser;

function ShowStatistic(Flag)
{
    if(Flag == 1)
    {/*
        if (!BrowserType.msie)
            $("#imgStatistic").rotateAnimation(360);*/

        $("#Statistic").animate({"left":"0"}, "normal");
    }
    else if(Flag == 0)
    {/*
        if (!BrowserType.msie)
            $("#imgStatistic").rotateAnimation(0);*/

        $("#Statistic").animate({"left":"-220px"}, "fast");
    }
}

/***********************************************************************/

var CountClickRefreshCaptcha = 0;

function RefreshCaptcha()
{
    CountClickRefreshCaptcha++;

    $(".ImgCaptcha").attr("src", SiteUrl + 'captcha/captcha.php?id=' + CountClickRefreshCaptcha);
}

/***********************************************************************/

function ValidateFormContact()
{
    var FormContactSubjectLength = $("input[name=ContactSubject]").val().length;
    var FormContactTextLength	 = $("textarea[name=ContactText]").val().length;
    var FormContactCaptcha		 = $("input[name=ContactCaptcha]").val().length;

    var ErrorContact = 0;

    if(FormContactSubjectLength < 3)
    {
        $("input[name=ContactSubject]").css({"border":"1px solid #eb7f7f"});
        $("input[name=ContactSubject]").next("span").css({"visibility":"visible"});
        ErrorContact = 1;
    }

    if(FormContactTextLength < 10)
    {
        $("textarea[name=ContactText]").css({"border":"1px solid #eb7f7f"});
        $("textarea[name=ContactText]").next("span").css({"visibility":"visible"});
        ErrorContact = 1;
    }

    if(FormContactCaptcha < 8)
    {
        $("input[name=ContactCaptcha]").css({"border":"1px solid #eb7f7f"});
        $("input[name=ContactCaptcha]").next("span").css({"visibility":"visible"});
        ErrorContact = 1;
    }

    $("#TableMainFormContact input").focus
    (
        function()
        {
            $(this).css({"border":"1px solid #acacac"});
            $(this).next("span").css({"color":"#cf0000", "font-size":"9pt", "visibility": "hidden"});
        }
    );

    $("#TableMainFormContact textarea").focus
    (
        function()
        {
            $(this).css({"border":"1px solid #acacac"});
            $(this).next("span").css({"color":"#cf0000", "font-size":"9pt", "visibility": "hidden"});
        }
    );

    if(ErrorContact == 0)
        document.FormContact.submit();
}

/***********************************************************************/
