function addSortables()
{
    var ul_arr = [];
    var count = 0;
    var sorttablecookie = '';
    
    $$('.sortable').each(function(elem){
        count++;
        var sorttablecookieend = '';
        if(count!=8)
        {
            sorttablecookieend = '|';
        }
        sorttablecookie = sorttablecookie +elem.get('id')+sorttablecookieend;
        if(count==2)
        {
            elem.setStyle('margin-left', '8px');
        }
        if(count==4)
        {
            elem.setStyle('margin-left', '8px');
        }
        if(count==6)
        {
            elem.setStyle('margin-left', '8px');
        }
        if(count==8)
        {
            elem.setStyle('margin-left', '8px');
        }
        if(count==1)
        {
            elem.setStyle('margin-left', '0px');
        }
        if(count==3)
        {
            elem.setStyle('margin-left', '0px');
        }
        if(count==5)
        {
            elem.setStyle('margin-left', '0px');
        }
        if(count==7)
        {
            elem.setStyle('margin-left', '0px');
        }
        var ul = elem.getParent();
        ul.addClass('ul_sortable');
    });
    
    Cookie.write("rubricsort", sorttablecookie, {duration:7});
    var mySortables = new Sortables($$('#container .ul_sortable'), 
	{
        clone: false,
        revert: false,
        opacity: 0.7,
        onComplete: function(el) {
        	addSortables();
        },        
        onSort: function(el) {
        	addSortables();
        }        
    });
}

function SwapRubricBlocks()
{
    var rubriccookiedata=Cookie.read("rubricsort");
    if (rubriccookiedata!=null && rubriccookiedata!="")
    {
        var rubriccookiedataarray = rubriccookiedata.split('|');
        //'theme_10365','theme_10369','theme_10366','theme_10370','theme_10371','theme_10374','theme_10377','theme_10380'
        if(rubriccookiedata!='')
        {
        var parent = $(rubriccookiedataarray[0]).getParent();
        parent.set('id', 'myrubricsortul');
        Array.each(rubriccookiedataarray, function(rubricname, index){
            $('myrubricsortul').grab(rubricname, 'bottom');
        }); 
        }
    }
    addSortables();
}

