$(function(){
    modal_links();
    deploy_wysiwyg();
    core_ui();
    theme_ui();
    run_anim();
})


function run_anim()
{
    var c = 2;
    $(".hsimg").each(function(){
        var v = c * 500;
        var p = c * 100;
        $(this).animate({width:"196px"}, p).fadeIn(v)
        ++c;
    }).hover(function(){
        $(this).animate({opacity:".8"}); 
    }, function (){
        $(this).animate({opacity:"1"}); 
    })
    
}

function core_ui()
{
    $("ul.weightsort").css({listStyle:"none", margin:"0px", padding: "0px"}).children('li').css({background: 'white', marginBottom:'5px', padding:'5px', border: '1px solid #e8e8e8'}).end().sortable({
        stop: function()
        {
            var count = 0;
            $(this).children('li').each(function(){
                $(this).children('input.weight').val(count);
                ++count;
            });
        }
    });
    
    $("ul.weightsort-multi").css({listStyle:"none", margin:"0px", padding: "0px"}).children('li').css({background: 'white', marginBottom:'5px', padding:'5px', border: '1px solid #e8e8e8'}).end().sortable({
        connectWith: ".sort-connected",
        stop: function(event, ui)
        {
            var side = ui.item.parent('ul').attr('id');
            var count = 0;
            ui.item.parent("ul").children("li").each(function(){
                $(this).children('input.weight').val(count);
                $(this).children('input.side').val(side);
                ++count;
            });
        }
    });
}

function modal_links()
{
    $("a.fancybox").fancybox({
        overlayColor: "#000"
    });
    $("a.modal, .modal_group a").live("click", function(){
        var t = $(this);
        $.fancybox({
            overlayShow	    :	true,
            overlayColor    :   "#000",
            href            :   this.href,
            centerOnScroll  :   true,
            onComplete      :   function()
            {
                if (t.hasClass("mtop"))
                {
                    $("#fancybox-wrap").css("top","0px");
                }
                deploy_wysiwyg();
            },
            onClosed        :   function()
            {
                if(t.hasClass('admin-link'))
                {
                    //window.location = window.location.href;
                }
            }
        });
        return false;
    });
}

function theme_ui()
{
    $("input:submit, input:button, button, .button").button();
    $(".accordion").accordion({
        autoHeight: false
    });
    $( "input.date" ).datepicker();
}
