/*NAVIGATIONSBEREICH*/

function addvalue(form,feld,inhalt)
{
   $('form[name=chdir] :input[name=directory]').val(inhalt);
   submitform();
}

function submitform()
{
  $('form[name=chdir]').submit();
}

var submitform2 = function(action)
{
   if(action!='#'){
      $('form[name=fileaction]: input[name=action]').val(action);
      $('form[name=fileaction]').submit();
   }
}

function download(url)
{
   $('form[name=download]: input[name=url]').val(url);
   $('form[name=download]').submit();
}

//*********** Tabellenfuntionen ********
// checkboxen Navigationsbereich select/unselect all
function select_all(state){ $('#navtable tbody input:.ckbox').prop('checked',state);}

// refresh navigation bereich
var navrefresh=function(options){
      $("#navtable tbody tr td:nth-child(2)").click(function(){return fwlink(this);}   ).addClass("csor");//.addClass("csor")
      $("#navtable thead tr th:.sortcol").click(function(){return fwlink(this);}   );
      $('#navtable thead tr th').aToolTip();
      
}

// forward link-klicks
var fwlink = function(tdp){   window.location.href=$(tdp).find("a").attr("href"); return false; }

function hide_form_elements(){
      $("#content > div.box").hide();
      $("#content > h3").hide();
      $("#content > p").hide();
      $(":input").hide();
      $("#upload").show();
}

// * aToolTip *
$(function(){
        $('a.tooltip').aToolTip({show_delay:0});
        $('div.actions: img').aToolTip();
        $('#content div a img').aToolTip();
        $('#content > div :input').aToolTip();
        $('#content form > div :input').aToolTip();
        $('div.content: .actions > input').aToolTip();
        $('.dropmenu').aToolTip();
        $('#topmenu > ul: li a').aToolTip({});
});

$(window).load(function(){
    if($(window).width() >= 1280){
            $("#wrapper").css("width",1262);
    }else{
            $("#wrapper").css("width",'auto');
    }

    $("input[type='text']:first", document.forms[0]).focus();
});

$(window).bind("resize",function(){
      if($(window).width() >= 1280){
         $("#wrapper").css("width",1262);
      }else{
         $("#wrapper").css("width",'auto');
      }
});

function async_request(url,params){
var ret_val;
    $.ajax({type: "GET",
	async: false,
	url: url,
	data: $.param(params),
	success: function(data){
	    if(data.length >0) {
	       ret_val = data;
	    }
	}
    });
    
return ret_val;
}

/*
	jQuery Version:				jQuery 1.3.2
	Plugin Name:				aToolTip V 1.0
	Plugin by: 				Ara Abcarians: http://ara-abcarians.com
	License:				aToolTip is licensed under a Creative Commons Attribution 3.0 Unported License
						Read more about this license at --> http://creativecommons.org/licenses/by/3.0/			
*/
function show_tooltip(element,settings,tipContent){
      var obj = $(element);
      if(!settings){
         // setup default settings
    	settings = {
    		clickIt: false,
    		closeTipBtn: 'aToolTipCloseBtn',
    		fixed: true,
    		inSpeed: 400,
    		outSpeed: 100,
    		tipContent: '',
    		toolTipClass: 'aToolTip',
    		xOffset: -25,
    		yOffset: 10,
                show_delay: 500
    	};
        obj.mouseout(function(){
            $('.' + settings.toolTipClass).fadeOut(settings.outSpeed).remove();
            obj.attr({title: tipContent});
         });
         
      }
      obj.attr({title: ''});

      if(obj.context.nodeName!="option"){
      $('body').append("<div class='"+ settings.toolTipClass +"' ><p class='aToolTipContent'>"+ tipContent +"</p></div>");
      
      $('.' + settings.toolTipClass).css({
              position: 'absolute',
              display: 'none',
              zIndex: '50000',
              top: (obj.offset().top - $('.' + settings.toolTipClass).outerHeight() - settings.yOffset) + 'px',
              left: (obj.offset().left + obj.outerWidth() + settings.xOffset) + 'px'
      })
      .stop(false,true).delay(settings.show_delay).fadeIn(settings.inSpeed);
      }
}


(function($) {
    $.fn.aToolTip = function(options) {
    
    	// setup default settings
    	var defaults = {
    		clickIt: false,
    		closeTipBtn: 'aToolTipCloseBtn',
    		fixed: false,
    		inSpeed: 400,
    		outSpeed: 100,
    		tipContent: '',
    		toolTipClass: 'aToolTip',
    		xOffset: 5,
    		yOffset: 5,
                show_delay: 1500
    	},
    
    	// This makes it so the users custom options overrides the default ones
    	settings = $.extend({}, defaults, options);
    
		return this.each(function() {


			// Decide weather to use a title attr as the tooltip content
			if($(this).attr('title')){
				// set the tooltip content/text to be the obj title attribute
				var tipContent = $(this).attr('title');
                                
			} else {
                                 var tipContent = $(this).children('[title]').attr("title");
                                 if(!tipContent){
                                  //if no title attribute set it to the tipContent option in settings
				 var tipContent = settings.tipContent;
                                 }else{
                                    $(this).children('[title]').attr({title:''});
                                 }
			}
			
			// check if obj has a title attribute and if click feature is off
			if(tipContent && !settings.clickIt){
				// Activate on hover	
				$(this).hover(function(){
                                    show_tooltip($(this),settings,tipContent);
                                 },
                                //$(this).one('hover',function(){show_tooltip(this,settings,tipContent);},
				function(){
					// Fade out
					$('.' + settings.toolTipClass).stop(true,true).fadeOut(settings.outSpeed, function(){$(this).remove();});
			    });	
                        }
                        //Follow mouse if fixed is false and click is false
                        if(!settings.fixed && !settings.clickIt){
				$(this).mousemove(function(el){
					$('.' + settings.toolTipClass).css({
						top: (el.pageY - $('.' + settings.toolTipClass).outerHeight() - settings.yOffset),
						left: (el.pageX + settings.xOffset)
					})
				});			
			}
		    
		}); // END: return this
		
		// returns the jQuery object to allow for chainability.  
        return $(this);
    };
})(jQuery);

$('#help').ready(function(){
   $('.togglehelp').click(function(){
               $('#help').delay(100).toggle();
               $('.togglehelp').delay(400).toggle();
   });
});



