function upload(v){
 CLEAR.f.setvalue('uploadpath',[v]);
 CLEAR.f.$('uploadfilefield').click();
}






$.fn.outer = function(val){
 if(val){
  $(val).insertBefore(this);
  $(this).remove();
 }else{
  return $("<div>").append($(this).clone()).html();
 }
}




$(document).ready(function(){

 var i,divArray,j,p,k,text,hook;

 divArray=Sizzle('[data-login=true]')
 jQuery.extend(Tipped.Skins, {
  'editortooltip' : {}
 });








Tipped.create('.contact_tooltip',null,{
  hook: {
   target:  'bottomleft',
   tooltip: 'topleft'
  },
  maxWidth: 290,
  showOn: 'click',
  hideOn: 'click-outside',
  hideOthers: true
 }
);


Tipped.create('.minicontact_tooltip',null,{
  hook: {
   target:  'topleft',
   tooltip: 'bottomleft'
  },
  maxWidth: 290,
  showOn: 'click',
  hideOn: 'click-outside',
  hideOthers: true
 }
);


 for (i=0; i < divArray.length; i++){
  var j=divArray[i].getAttribute('data-editor');
  var p=j.split('|');
  var k;
  var text='<ul class="tooltipeditmenu">';
  for (k=0; k<p.length;k++){
   var q=p[k].split(',')

if (q[0].slice(0,10)=='javascript'){
   text=text+'<li><a href="'+q[0]+'">'+q[3].toString()+'</a></li>';
} else {
   text=text+'<li><a href="javascript:editor_window.show(\''+q[0]+'\',\''+q[1]+'\',\''+q[2]+'\',\''+q[4].toString()+'\')">'+q[3].toString()+'</a></li>';
}


  }
  text=text+'</ul>';

  if (q[5] && q[5]=='top') {
   hook='topleft';
  }else{
   hook='leftmiddle';
  }

  Tipped.create(divArray[i], text,{
   hook:hook,
   skin:'editortooltip',
   hideDelay: 500,
   background:{
    opacity:1,
    color: [{position:0,color:'#F79406'},{position:1,color:'#EB7901' }]
   },
   shadow: false,
   border: 0,
   zIndex: 1000,
   onShow: function(content, element) { 
    $(element).css({'outline': '3px solid #F68506','outline-offset':'-3px'});
   },
   onHide: function(content, element) {
    $(element).css({'outline': 'none'});
   },
   showDelay: 500
  });

 }




$('[data-reload]').each(
 function(index,val){
  var v=$(val).attr('data-reload');
  $(val).attr('data-id',index);
  CLEAR.f.runOverlay('/skeleton/datareload?ajaxrequest=true&exec='+v+'&id='+index);
 }
)



})




editor_window={
 show:function(url,w,h,windowname,refresh){
  this.remove();
  Tipped.hideAll();
  w=parseInt(w,10);
  h=parseInt(h,10);
  var size,resizePopup,dim,win,iframe,r;

  if (typeof refresh=='string' && refresh=='norefresh'){
   r='javascript:editor_window.remove();';
  } else {
   r='javascript:editor_window.removerefresh();';
  }
  size=function(){
   var dim=CLEAR.f.getDimensions();
   var x=dim.width;
   var y=dim.height;
   var width=w;
   var height=h;
   if(width>(x-80)){width=(x-80);}
   if(height>(y-(110))){height=(y-(110));}
   var left=Math.round((x-width)/2)-20;
   var top=Math.round((y-(height+50))/2)-10;
   return {left:left,top:top,width:width,height:height}
  }
  dim=size();
//  appendHTML(document.getElementById('editor_window_outer'),'<div style="position:absolute; top:0; z-index: 1000001; position:fixed; left:0; width: 100%; height:100%; background-color:#000;opacity:.7;filter:alpha(opacity=80);" id="editor_window_bg"></div>');
  appendHTML(document.getElementById('editor_window_outer'),'<div style="position:absolute; top:'+dim.top+'px; z-index: 1000002; background-color:#D0D0D0; position:fixed; left:'+dim.left+'px; width: '+parseInt(dim.width+40,10)+'px; height:'+parseInt((dim.height+50)+20,10)+'px;border-radius: 15px;-webkit-border-radius: 15px;-moz-border-radius: 15px;-webkit-box-shadow: 0px 0px 23px rgba(50, 50, 50, 0.89);-moz-box-shadow: 0px 0px 23px rgba(50, 50, 50, 0.89);box-shadow: 0px 0px 23px rgba(50, 50, 50, 0.89);" id="editor_window"></div>');
  win=CLEAR.f.$('editor_window');
  win.innerHTML='<div style="margin: 0 auto 0; padding:10px;padding-left:20px; font-size:24px;color:#fff;width:'+parseInt(dim.width+40,10)+'px;height:50px;">'+windowname+'<span style="text-align:right;float:right;"><a href="'+r+'"><img src="/apps/blocks/images/close.png" width="32" height="32" border="0"></a></span></div><div id="editor_window_iframe_div" style="background-image: url(/apps/blocks/images/loading.png);background-position: center;background-repeat: no-repeat;width:'+dim.width+'px;height:'+dim.height+'px;background-color:#fff;margin-left:20px;"><iframe src="'+url+'" style="overflow:auto; padding-top:0; border-width:0; background-color: #fff;" width="'+dim.width+'" height="'+(dim.height)+'" frameborder="0" scrolling="yes" id="editor_window_iframe"></iframe></div>';
//  $("#editor_window_iframe").bind('mousewheel', function(e, d){e.preventDefault();})


$("#editor_window_iframe").bind('mousewheel', function(e, d)  
    {  
                e.preventDefault()  
    })  





 },
 removerefresh:function(){
  var W;
  W=document.getElementById('editor_window')
  if(W) W.parentElement.removeChild(W);
  history.go(0);
 },
 remove:function(){
  var W;
  W=document.getElementById('editor_window')
  if(W) W.parentElement.removeChild(W);
 }
}





  function mtoggle(t,id){
   // First turn off all menu's
   // also turn off all background-positions

   var e=document.getElementsByClassName('editoranchor')
   var x;
   for (i=0;i<e.length;i++){
    x=e[i].style.backgroundPosition.split(' ');
    e[i].style.backgroundPosition=x[0]+" -0px";
   }

   x=t.style.backgroundPosition.split(' ');
   t.style.backgroundPosition=x[0]+" -168px";

   ddmenuitem = document.getElementById(id);
   if (ddmenuitem.style.display === 'block'){q=true;}else{q=false;}
   var e=document.getElementsByClassName('editormenu')
   for (i=0;i<e.length;i++){
    e[i].style.display='none';
   }

   document.getElementById('bg').style.display = 'none';

   if (q){
    document.getElementById('bg').style.display = 'none';
    ddmenuitem.style.display = 'none';
    x=t.style.backgroundPosition.split(' ');
    t.style.backgroundPosition=x[0]+" -0px";
    document.getElementById('outer_content').style.left='24px';

    jQuery('#outer_content').width(   jQuery('body').width()-24    );

   } else {
    document.getElementById('bg').style.display = 'block';
    ddmenuitem.style.display = 'block';
    document.getElementById('outer_content').style.left='224px';

    jQuery('#outer_content').width(   jQuery('body').width()-224  );


   }
  }






