function gup( name, url )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  if (typeof url == "undefined") {
      url = window.location.href;
      }
  var results = regex.exec( url );
  if( results == null )
    return "";
  else
    return results[1];
}


function activeSimpleLayoutControls(){
    /*var sl_layouts = jq('.sl-layout');
    sl_layouts.bind("click", function(e){
        e.stopPropagation();
        e.preventDefault();
    });*/
    jq(".sl-layout").bind("click", function(e){
            item = this;
            var a_el = jq('a', item);
            var id = a_el[0].id.split("-")
            uid = id[0]
            //ohhh we have to change this asap - it makes no sense
            layout = id[1];
            cssclass = id[2] && '-' +id[2] || '';
            layout = layout + cssclass;
            var fieldname = gup('fieldname',a_el[0].href);
            jq.post('sl_ui_changelayout', { uid : uid, layout :layout,fieldname:fieldname }, function(data){
                jq('#' + uid +' .simplelayout-block-wrapper').replaceWith(data);
                jq('#' + uid +' .active').removeClass('active');
                jq(item).addClass('active');
            });
            e.stopPropagation();
            e.preventDefault();
        });

}

jq(activeSimpleLayoutControls);



