﻿
function AddAudio(file)
{
    // <![CDATA[


    var s1 = new SWFObject("audioplayer.swf", "single", "395", "102", "7");
    s1.addParam("allowfullscreen", "true");
    s1.addParam("FlashVars", "filename=" + file);
    s1.addParam("bgcolor", "#FFFFFF");
    s1.addVariable("width", "395");
    s1.addVariable("height", "102");

    s1.write("swfdiv_ttpreview");
    SWFFormFix("single");

    // ]]>
}

$(document).ready(function ()
{
    $(".StyleMenuLink").hover(function ()
    {
        $(this).animate({ color: "#ff0000" }, 200);
    }, function ()
    {
        $(this).animate({ color: "#ffff55" }, 200);
    });

    $(".sliderContent a").hover(function ()
    {
        $(this).animate({ color: "#ff0000" }, 200);
    }, function ()
    {
        $(this).animate({ color: "#ffff55" }, 200);
    });

    $(".LeftLinkSelect").css({ visibility: "visible", opacity: "0.1" })
    $(".LeftLinkSelect").hover(function ()
    {
        $(this).animate({ opacity: "1" }, 500);
    }, function ()
    {
        $(this).animate({ opacity: "0.1" }, 500);
    });


    $(".MenuPanel").animate({ marginLeft: "0px" }, 0, "linear", function ()
    {
        var heigh = $(this).attr("PanelHeight");
        var widt = $(this).attr("PanelWidth");
        $(this).css({ width: widt });
        $(this).find(".sliderContent").css({ height: heigh, marginTop: "-" + heigh });
    });

    $(".MenuItem").hover(function ()
    {
        slider = $(this).find(".MenuPanel");

        if (slider[0].IsShown != true)
        {

            slider[0].IsHovered = true;
            slider[0].IsShown = true;
            slider[0].DisableHide = false;
            var heigh = "+=" + slider.attr("PanelHeight");


            slider.animate({ height: heigh }, 300);
            slider.find(".sliderContent").animate({ marginTop: heigh }, 300);
            slider.css({ border: "solid 1px gray", padding: "5px" });

        }
        else
        {
            slider[0].DisableHide = true;
        }


    }, function ()
    {
        slider = $(this).find(".MenuPanel");
        slider[0].IsHovered = false;

        if (slider[0].DisableHide != true)
        {
            var width = slider.attr("PanelWidth");
            slider.animate({ marginLeft: "0px" }, 300, "linear", function ()
            //setTimeout(function()
            {

                slider = $(this); //.find(".MenuPanel");
                if (slider[0].IsHovered != true && slider[0].IsShown == true)
                {
                    var heigh = "-=" + slider.attr("PanelHeight");

                    slider.animate({ height: heigh }, 300, "linear", function () { $(this)[0].IsShown = false; $(this).css({ border: "solid 0px gray", padding: "0px" }); });
                    slider.find(".sliderContent").animate({ marginTop: heigh }, 300);
                    //setTimeout("IsShowMenuItem = false;", 500);
                }
            });
            //}, 300);
        }

        //        slider.animate({ width: "300" }, 500, "backf", function()
        //        {
        //            alert("no");
        //            if (!IsShowMenuItem)
        //            {
        //                slider.animate({ height: sliderDirectSecond }, 500);
        //                slider.find(".sliderContent").animate({ marginTop: sliderDirectSecond }, 500);
        //            }

        //        });

    });

    //    $(".MenuPanel").hover(function()
    //    {
    //        var slider = $(this);
    //        IsPanelHover = true;

    //    }, function()
    //    {
    //        var slider = $(".MenuItem .MenuPanel")
    //        if (IsLinkHover != true)
    //        {
    //            IsPanelHover = false;
    //            slider.animate({ height: sliderDirectSecond }, 500);
    //            slider.find(".sliderContent").animate({ marginTop: sliderDirectSecond }, 500);
    //        }
    //    });

});

//LoadTextEditor = function(isSetValue, areaId)
//{

//    if (areaId == undefined) areaId = "FckEditorArea";

//    var areaEditor = document.getElementById(areaId);

//    if (isSetValue != undefined && isSetValue)
//    {
//        var el = document.getElementById("FckEditorValue");
//        areaEditor.innerHTML = el.value;
//    }

//    var oFCKeditor = new FCKeditor(areaEditor.name);
//    oFCKeditor.BasePath = '/fckeditor/';
//    oFCKeditor.ReplaceTextarea();
//}



//function GetFckEditorInnerHTML()
//{
//    // Get the editor instance that we want to interact with.
//    var oEditor = FCKeditorAPI.GetInstance('FckEditorArea');
//    var el = document.getElementById("FckEditorValue");
//    el.value = oEditor.EditorDocument.body.innerHTML;
//}


//ScriptManager.RegisterStartupScript(this, this.GetType(), "LoadFckeditorLoa", "LoadTextEditor(true);", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "LoadFckeditorLoa", string.Format("LoadTextEditor(false, '{0}');", PrevFckEditorArea.ClientID), true);
//            <input type="hidden" runat="server" id="FckEditorValue" />
//<textarea name="FckEditorArea" id="FckEditorArea" rows="10" cols="80" style="width: 100%; height: 200px"></textarea>


jQuery.fn.center = function ()
{

    var w = $(window);

    this.css("top", (w.height() - this.height()) / 2 + document.documentElement.scrollTop + "px");
    this.css("left", (w.width() - this.width()) / 2 + document.documentElement.scrollLeft + "px");
    return this;
}
function OnStartupExplorer()
{

    $(document).ready(function ()
    {

        $("#CreateFolderButton").click(function ()
        {
            $("#RenameFolderDialog").animate({ opacity: "hide" }, 1000);
            $("#MessageDialog").animate({ opacity: "hide" }, 1000);
            $("#ConfirmDeleteFolderDialog").animate({ opacity: "hide" }, 1000);

            $("#CreateFolderDialog input")[0].value = "";


            $("#CreateFolderDialog").animate({ opacity: "hide" }, 1, function ()
            {

                var createButton = $("#CreateFolderButton")[0];
                $("#CreateFolderDialog").css("top", (createButton.offsetTop + createButton.offsetHeight) + 50 + "px");
                $("#CreateFolderDialog").css("left", (createButton.offsetLeft + createButton.offsetWidth) + 20 + "px");

                $("#CreateFolderDialog").animate({ opacity: "show" }, 1000);
            });

        });

        $("#RenameFolderButton").click(function ()
        {
            $("#CreateFolderDialog").animate({ opacity: "hide" }, 1000);
            $("#MessageDialog").animate({ opacity: "hide" }, 1000);
            $("#ConfirmDeleteFolderDialog").animate({ opacity: "hide" }, 1000);

            if (!CheckIsCheckedFolders("переименовать")) return;
            $("#RenameFolderDialog input")[0].value = "";

            $("#RenameFolderDialog").animate({ opacity: "hide" }, 1, function ()
            {

                var createButton = $("#RenameFolderButton")[0];
                $("#RenameFolderDialog").css("top", (createButton.offsetTop + createButton.offsetHeight) + 50 + "px");
                $("#RenameFolderDialog").css("left", (createButton.offsetLeft + createButton.offsetWidth) + 20 + "px");

                $("#RenameFolderDialog").animate({ opacity: "show" }, 1000);
            });

        });

        $("#DeleteFolderButton").click(function ()
        {
            var count = 0;
            var checkboxes = $("#TDPanelFolders input");
            for (var i = 0; i < checkboxes.length; i++)
            {
                if (checkboxes[i].checked)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                ShowMessageDialog("Не выбрана ни одна папка!");
                return false;
            }

            $("#ConfirmDeleteFolderDialog").animate({ opacity: "hide" }, 1, function ()
            {
                $("#ConfirmDeleteFolderDialog").center();
                $("#ConfirmDeleteFolderDialog").animate({ opacity: "show" }, 1000);
            });

        });


        $(".CancelButtonDialod").click(function ()
        {
            $(this).parent().parent().animate({ opacity: "hide" }, 1000);
        });

    });
}
function DeleteFolders()
{
    var checkboxes = $("#TDPanelFolders input");
    for (var i = 0; i < checkboxes.length; i++)
    {
        if (checkboxes[i].checked)
        {
            return confirm("Вы уверены, что хотите удалить помеченные папки? Вместе с ними будут удалены вложенные папки и их содержимое!");
        }
    }
    ShowMessageDialog("Не выбрана ни одна папка!");
    //alert("Не выбрана ни одна папка!");
    return false;
}

function CutFolder()
{
    if (!CheckIsCheckedFolders("вырезать")) return false;

    return true;
}

function CheckIsCheckedFolders(insText)
{
    var checkboxes = $("#TDPanelFolders input");
    var count = 0;
    for (var i = 0; i < checkboxes.length; i++)
    {
        if (checkboxes[i].checked)
        {
            count++;
        }
    }
    if (count > 1)
    {
        ShowMessageDialog("Выбраны несколько папок, чтобы " + insText + " надо выбрать только одну!");
        //alert("Выбраны несколько папок, чтобы " + insText + " надо выбрать только одну!");
        return false;
    }
    if (count == 0)
    {
        ShowMessageDialog("Не выбрана ни одна папка!");
        //alert("Не выбрана ни одна папка!");
        return false;
    }
    return true;
}

function DisableCheckedFolders()
{
    var checkboxes = $("#TDPanelFolders input");
    for (var i = 0; i < checkboxes.length; i++)
    {
        if (checkboxes[i].checked)
        {
            checkboxes[i].checked = false;
        }
    }
}
function ShowMessageDialog(text)
{

    $("#MessageDialogText")[0].innerText = text;

    $("#MessageDialog").animate({ opacity: "hide" }, 1, function ()
    {
        $("#MessageDialog").center();
        $("#MessageDialog").animate({ opacity: "show" }, 1000);
    });
}


function FullImageLoaded()
{
    $("#MovingImage").animate({ "left": "-2000px" }, 10, function ()
    {
        var w = $(window)
        var movingImage = $("#MovingImage")[0];
        var ttop = (w.height() - movingImage.offsetHeight) / 2 + document.documentElement.scrollTop + "px";
        var lleft = 20 + document.documentElement.scrollLeft + "px";
        var left0 = -movingImage.offsetWidth + document.documentElement.scrollLeft + "px";
        $("#MovingImage").animate({ "left": left0, "top": ttop }, 10);

        $("#MovingImage").animate({ "left": lleft, "top": ttop }, 200);

        if (isHide)
        {
            var movingImage = $("#MovingImage")[0];
            var left0 = -movingImage.offsetWidth + document.documentElement.scrollLeft + "px";
            //$("#MovingImage").stop();
            $("#MovingImage").animate({ "left": left0 }, 100);
        }
    });
}

function ShowAnimate()
{
    $("#ctl00_ImgUp").animate({ opacity: 'hide' }, 1000, function ()
    {
        $("#ctl00_ImgUp").animate({ opacity: 'show' }, 1000, function ()
        {
            window.setTimeout(Function.createDelegate(this, ShowAnimate), 15000);
        });
    });
}
var sliderDirectFirst = "+=170px";
var sliderDirectSecond = "-=170px";

var urlSource;
var isHide = false;

$(document).ready(function ()
{
    //Всплывающие картинки




});

function setImagesBehaviour()
{
    $(".ShowFullImageCSS").hover(function ()
    {
        urlSource = this.src;

        var movingImage = $("#MovingImage")[0];
        var w = $(window);

        isHide = false;
        $("#MovingImage").animate({ "left": "-2000px" }, 10, function ()
        {
            var imgInside = $("#MovingImage img")[0];
            var url = urlSource.replace("t=1", "t=2");
            imgInside.src = url;
            imgInside.onload = FullImageLoaded;


        });

        //                $("#MovingImage").animate({ "left": "-2000px" }, 1300, function()
        //                {
        //                    var w = $(window)
        //                    var movingImage = $("#MovingImage")[0];
        //                    var ttop = (w.height() - movingImage.offsetHeight) / 2 + document.documentElement.scrollTop + "px";
        //                    var lleft = 20 + document.documentElement.scrollLeft + "px";
        //                    var left0 = -movingImage.offsetWidth + document.documentElement.scrollLeft + "px";
        //                    $("#MovingImage").animate({ "left": left0, "top": ttop }, 10);

        //                    $("#MovingImage").animate({ "left": lleft, "top": ttop }, 200);

        //                    if (isHide)
        //                    {
        //                        var movingImage = $("#MovingImage")[0];
        //                        var left0 = -movingImage.offsetWidth + document.documentElement.scrollLeft + "px";
        //                        //$("#MovingImage").stop();
        //                        $("#MovingImage").animate({ "left": left0 }, 100);
        //                    }
        //                });

    }, function ()
    {
        isHide = true;
        var movingImage = $("#MovingImage")[0];
        var left0 = -movingImage.offsetWidth + document.documentElement.scrollLeft + "px";
        $("#MovingImage").stop();
        $("#MovingImage").animate({ "left": left0 }, 100);

    });
}
