  
function loader() {
  return '<div class="loader"></div>';
}

$(document).ready(function() {
  //$("[tooltip]").css({background: "yellow"});
  //$("div").css({background: "yellow"});
  $('#contmenu').ready(function() {
    $('#contmenu a').click(function() {
      var target = $(this).attr("href") + "&inc";
      $('#contmenu td.buttonselected').removeClass().addClass("button");
      $(this).parent().removeClass().addClass("buttonselected");
      $('#contpage').html(loader())
      $('#contpage').load(target);
      return false;
    });
  });
});

/*
$('#mce_editor_0_image')mousover.(function(){
  $('#mce_editor_0_image').html('<div id="pop" style="border: 1px solid #cccccc;">Text here</div>'); //.hide().fadeIn("slow");
  $("#pop").hide();
  $('#txt').mouseover(function(e){
    //$('body').html($('body').html+'<div id="pop">Hello!</div>');
    $('#pop').load('ajax/test.txt');
    $("#pop").fadeIn();
    //$("#pop").html(e.pageX +', '+ e.pageY);
    $("#pop").mouseout(function(){
      $("#pop").fadeOut("slow");
    });
  });
});
*/
//    window.location('address_goes_here');
/*  $(document).ready(function() {
    $('<div id="submenu" style="position: absolute;"><div id="inner_submenu"></div></div>').appendTo("body"); //.hide().fadeIn("slow");
    $("#submenu").hide();
    //$(".mainmenu").css('background','yellow');
  });
  $("#menu .menuelement[menu_id]").mouseover(function(e){
      //alert($(this).attr('menu_id'));
      $("#submenu").load('ajax/submenu.php?menu_id='+$(this).attr('menu_id'));
      //$("#submenu").load('menu.php?view=menu&menu_id='+$(this).attr('menu_id'));
      //$("#submenu").html('test');
      
      $("#submenu").css("top",($(this).offset().top)+"px");
      $("#submenu").css("left",$(this).offset().left+"px");
      $("#submenu").ajaxStop(function(){
        $("#submenu").show();
        $("#submenu").mouseleave(function(){
          $("#submenu").hide();
        });
      });
  });
*/  
  $(document).ready(function() {
    $('<div id="pop" class="tooltip" style="border: 1px solid #cccccc; position: absolute;">Text here </div>').appendTo("body"); //.hide().fadeIn("slow");
    $("#pop").hide();
  });
  
  $("[tooltip]").click(function(e){
    //$('#txt').mouseover(function(e){
  //    $('<div id="pop" class="tooltip" style="border: 1px solid #cccccc; position: absolute; top: '+e.PageY+'px;">Text here '+e.PageY+'</div>').appendTo("body"); //.hide().fadeIn("slow");
      //$('body').html($('body').html+'<div id="pop">Hello!</div>');
      //$('#pop').load('ajax/test.txt');
      //$("#pop").html(e.pageX +', '+ e.pageY);
      $("#pop").html($(this).attr('tooltip'));
      $("#pop").css("top",$(this).offset().top+"px");
      $("#pop").css("left",$(this).offset().left+"px");
      //$("#pop").html($(this).offset().top);
      $("#pop").fadeIn();
//      $("#pop").mouseleave(function(){
//        $("#pop").hide();
        //$("#pop").prepend();
//      });
      $("#pop").click(function(){
        $("#pop").hide();
        //$("#pop").prepend();
      });
    //});
  });
  $(window).keydown(function(e){
    //alert(e.keyCode);
    if (e.keyCode == 37){
      //alert("vänster");
    }
    if (e.keyCode == 39){
      //alert("höger");
    }
  });
  $('#img_btn').click(function(){
    //$('#txt').mouseover(function(e){
  //    $('<div id="pop" class="tooltip" style="border: 1px solid #cccccc; position: absolute; top: '+e.PageY+'px;">Text here '+e.PageY+'</div>').appendTo("body"); //.hide().fadeIn("slow");
      //$('body').html($('body').html+'<div id="pop">Hello!</div>');
      //$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=iso-latin1"});
      $('#pop').load('upload_frame.php');
      //$("#pop").html(e.pageX +', '+ e.pageY);
      //$("#pop").html($(this).attr('tooltip'));
      $("#pop").css("top","10px");
      $("#pop").css("left","10px");
      //$("#pop").html($(this).offset().top);
      $("#pop").css("background","#ffffff");
      $("#this_img").html('Img 2');
      $("#pop").fadeIn();
      $("#pop").click(function(){
        $("#pop").hide();
        //$("#pop").prepend();
      });
    //});
  });
  
  
  $("#this_img").click(function(e){
    alert($(this).attr("url"));
    //$.session("img_url", $(this).attr("url"));
    //$('<div id="selected">URL:::'+$(this).attr("url")+'</div>').appendTo("body"); //.hide().fadeIn("slow");
    //$("#pop").hide();
    //$("#pop").prepend();
  });
/*

  $('#mce_editor_0_image').click(function(){
  });


<a id="mce_editor_0_image" 
   href="javascript:tinyMCE.execInstanceCommand('mce_editor_0','mceImage',true);" 
   onclick="tinyMCE.execInstanceCommand('mce_editor_0','mceImage',true);return false;" 
   onmousedown="return false;" 
   class="mceButtonNormal" 
   target="_self">
   <img src="http://localhost/SVN_repo/firma/trunk/magma/tiny_mce/themes/advanced/images/image.gif"
        alt="Insert/edit image" 
        title="Insert/edit image">
*/
/*
  $("#leftbar").mouseover(function(e){
    //$('#txt').mouseover(function(e){
  //    $('<div id="pop" class="tooltip" style="border: 1px solid #cccccc; position: absolute; top: '+e.PageY+'px;">Text here '+e.PageY+'</div>').appendTo("body"); //.hide().fadeIn("slow");
      //$('body').html($('body').html+'<div id="pop">Hello!</div>');
      //$('#pop').load('ajax/test.txt');
      //$("#pop").html(e.pageX +', '+ e.pageY);
      $("#pop").html('ää');
      $("#pop").css("top",$(this).offset().top+"px");
      $("#pop").css("left",$(this).offset().left+"px");
      //$("#pop").html($(this).offset().top);
      $("#pop").fadeIn();
      $("#pop").mouseleave(function(){
        $("#pop").hide();
        //$("#pop").prepend();
      });
    //});
  });
  $(document).ready(function() {
    $('#mce_editor_0_image').html('öö');
    
  }
*/ 
    
    
	function vGo( sUrl ) {
	
	  window.location.href = sUrl
	  
	}
	
	function vPrepareTags( sTagList, sTagField, sFunction ) {

		var tags = $(sTagList);
		var tag = tags.find('span');
		for(var i = 0;i<tag.length;i++) {
		
		  tag[i].onmouseover = function() { this.style.background = '#eee'; }
		  tag[i].onmouseout = function() { this.style.background = '#fff'; }

		  if(sFunction == undefined)
		  	tag[i].onclick = function() { vTag( sTagField, this.innerHTML ) }
		  else if(sFunction=="search")
		    tag[i].onclick = function() { vGo('memberlist.php?tags='+this.innerHTML) }

		}
		
	}

	function vTag( iTextID, sTag ) {

		var oText = $(iTextID)
		var aTag = oText.value.split(" ")
		
	  if(oText.value.length==0) oText.value = sTag;
	  else {
	    if(in_list(sTag, oText.value)) {
	      oText.value = "";
			  for(var i = 0;i<aTag.length;i++) {
		      if(trim(aTag[i]) != sTag) {
		        if(oText.value.length==0)
		          oText.value = trim(aTag[i])
		        else
		        	oText.value = oText.value + " " + trim(aTag[i])
		      }
		    }
			} else {
				oText.value = oText.value + " " + sTag
			}
	  }
	
	}
	
	function in_list( sValue, sList ) {
	
	  sValue = " " + sValue + " "
	  sList = " " + sList + " "
	  if(sList.match(sValue))
	    return true;
		else
		  return false;
	
	}
	
	function trim(str) {
		s = str.replace(/^(\s)*/, '');
		s = s.replace(/(\s)*$/, '');
		return s;
	}

	function addClass( oNode, sClass ) {

		var sCurrentClass = oNode.className

		var aClass = sCurrentClass.split(" ")
	  var sNewClass = ""
	
	  oNode.removeAttribute('class')
	  for(var iIndex=0;iIndex<aClass.length;iIndex++) {
	    sNewClass = sNewClass + aClass[iIndex]+" "
	  }
	  sNewClass = sNewClass + sClass
	
	  oNode.className = sNewClass
	
	}
	
	function removeClass( oNode, sClass ) {
	
	  var sCurrentClass = oNode.className
		var aClass = sCurrentClass.split(" ")
	  var sNewClass = ""

	  oNode.removeAttribute('class')
	  for(var iIndex=0;iIndex<aClass.length;iIndex++) {
	    if(sClass != aClass[iIndex])
	    	sNewClass = sNewClass + aClass[iIndex]+" "
	  }
	  sNewClass = trim(sNewClass)
	  

	  oNode.className = sNewClass
	  
	}
	
	function vPopUp( sTarget, iWidth, iHeight ) {
	
	  window.open(sTarget, "popup", 'width='+iWidth+',height='+iHeight+',scrollbars=yes,resizable=no');
	  
	}
	
	function bPrepareHover(oContainer, sClass) {
	
	  var aItem = document.getElementsByClassName(sClass, oContainer)
	  for(var i=0;i<aItem.length;i++) {
		  if(BrowserDetect.browser=="Explorer") {
				aItem[i].onmouseenter = function() { addClass(this,'hover') }
				aItem[i].onmouseleave = function() { removeClass(this,'hover') }
			} else {
			  aItem[i].onmouseover = function() { addClass(this,'hover') }
				aItem[i].onmouseout = function() { removeClass(this,'hover') }
			}
		}
	
	}
	
	Array.prototype.in_array = function ( obj ) {
		var len = this.length;
		for ( var x = 0 ; x <= len ; x++ ) {
			if ( this[x] == obj ) return true;
		}
		return false;
	}

