$(document).ready(function() {
    //search
   // $("#search_input").focus(function(){
   //     $("#search_input").val("");
   // });
   
   //IE6
    if ($.browser.msie && $.browser.version <= 6 )	
        document.location.href=SYSTEMPATH+"IE6/";
 
   //login overlay
   	$("#overlay_login").overlay({
		onClose: cancelLogin()
	});
    $("#searchform").submit(function(){
     
        if(jQuery.trim($("#search_input").val()) =="")
            return false;
    });
    
    //icon rollover
	$(".add_icon").hover(
	    function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_add_over.gif"});
        },
        function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_add.gif"});
        }
    );
    //
    $("#searchpfeil").hover(
	    function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_search_arrow_over.gif"});
        },
        function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_search_arrow.gif"});
        }
    );
    //
    $(".add_trans_icon").hover(
	    function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_addtrans_over.gif"});
        },
        function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_addtrans.gif"});
        }
    );
    //
    $(".trash_icon").hover(
	    function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_trash_over.gif"});
        },
        function(){
	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_trash.gif"});
        }
    );
    //icon_email
    $(".icon_email").hover(
   	    function(){
   	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_email_over.gif"});
           },
           function(){
   	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_email.gif"});
           }
       );
      //icon_edit
      $(".icon_edit").hover(
     	    function(){
     	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_edit_over.gif"});
             },
             function(){
     	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_edit.gif"});
             }
         );
    //
     $(".download_icon").hover(
      	    function(){
      	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_download_over.gif"});
              },
              function(){
      	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_download.gif"});
              }
     );
          
          
    // navigation divs clickable
    $(".naviNotActive").click(function(){
        document.location.href=$(this).find("a").attr("href");
        
    });
    $(".navi_home").click(function(){
        document.location.href=$(this).find("a").attr("href");
        
    });
    
    //icon_insertnew
    $(".icon_insertnew").hover(
      	    function(){
      	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_insertnew_over.gif"});
              },
              function(){
      	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_insertnew.gif"});
              }
     );
    //icon_addlist
    $(".icon_addlist").hover(
      	    function(){
      	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_addlist_over.gif"});
              },
              function(){
      	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_addlist.gif"});
              }
     );
     //arrow_right
     $(".arrow_right").hover(
       	    function(){
       	        $(this).attr({src: SYSTEMPATH+"html/img/icons/arrow_right_over.gif"});
               },
               function(){
       	        $(this).attr({src: SYSTEMPATH+"html/img/icons/arrow_right.gif"});
               }
      );
      //arrow_left
       $(".arrow_left").hover(
         	    function(){
         	        $(this).attr({src: SYSTEMPATH+"html/img/icons/arrow_left_over.gif"});
                 },
                 function(){
         	        $(this).attr({src: SYSTEMPATH+"html/img/icons/arrow_left.gif"});
                 }
        );
      //icon_asso
       $(".asso_icon").hover(
         	    function(){
         	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_asso_over.gif"});
                 },
                 function(){
         	        $(this).attr({src: SYSTEMPATH+"html/img/icons/icon_asso.gif"});
                 }
        );

      
      //nach oben
      $("#nachoben").hide();
      $(document).scroll(function(e){
           
            if(window.pageYOffset > 160)
                $("#nachoben").show();
            else
                $("#nachoben").hide();
    });
   
});
/*********************************************************************/
function openLoginOverlay() { 
	
 
    // get access to the overlay API 
    var api = $("#overlay_login").overlay(); 
 
    // call it's open() method         
    api.load();             
}
/*********************************************************************/
function cancelLogin() { 

		$("#dolog").show();     
}
/*********************************************************************/
function login() { 

		var url=SYSTEMPATH+"code/log/login.php";
    	var o={};
    	o.email=$("#email").val();
    	o.passw=$("#passw").val();
    	o.log_mode= "login";
    	$.getJSON(url,o,function (result) {
      		if(result.success){
      		    document.location.href=result.pfad;
  		    }
  		    else{
  		        if(result.error ==1){
  		            $("#warning").html("Wrong Password! ");
  		            $("#warning").show();
  		            $("#newPass").show();
  		            
	            }
	            else{
	                 $("#warning").html("This email adress is unknown to the system! ");
      		         $("#warning").show();
	                
                }
	        }
    	});
}
/*********************************************************************/
function sendNewPass() { 

		var url=SYSTEMPATH+"code/log/newPass.php";
    	var o={};
    	o.email=$("#email").val();
    
    	o.log_mode= "newPass";
    	$.getJSON(url,o,function (result) {
      		if(result.success){
      		    
      		    $("#newPass").html("Your new Password has been send to :"+result.email);
      		    $("#dolog_form2").hide();
  		    }
  		   
    	});
}


/*************************************************/
function showLogForm(){
	//
	//  $("#dolog_form").show();
	//  $("#dolog").hide();
	openLoginOverlay();
		
}
/*************************************************/
function logout(){
console.log("logout");	
		var url=SYSTEMPATH+"code/log/logout.php";
    	var o={};
    	o.email=$("#email").val();
    
    	o.log_mode= "newPass";
    	$.getJSON(url,o,function (result) {
      		if(result.success){
      		    
      		    document.location.href=SYSTEMPATH;
  		    }
  		   
    	});
		
}
/*************************************************/
function cancel(which){
	
		switch(which){
			case "login": $("#dolog_form").hide();
						  $("#dolog").show();
						break;
		}
		
}
/*************************************************/
function switchLang(lang){

	document.location.href=SYSTEMPATH+"code/global/selectLang.php?lang="+lang;

}
/*************************************************/
function switchEditMode(){
	var emode=$('#edit_mode:checked').val();
	console.log("hier::"+$('#edit_mode:checked').val());
	if(emode == "on")
		var mode=1;
	else
		var mode=0;
	document.location.href=SYSTEMPATH+"code/global/switchEditMode.php?mode="+mode;

}
/*********************************************************************/

function showFullView(path){

	
	$("#picViewContainer").remove();
	$("<div id='picViewContainer'><div id='picView'><img src='"+path+"' /></div></div>").appendTo('body').fadeIn(100).center();
	
	$("#picViewContainer").click(function() {$("#picViewContainer").remove();});

}

/*********************************************************************/
function preload(file) 

{
console.log("preload:"+file);
	img = new Image(); 

	img.src = file;

}
/***************************************not used yet******************************/
function submitsearch(){

	if($("#search_input").val() !="search pattern")
		$("#searchform").submit();
	else{
		$("#search_input").val("");
		$("#search_input").focus();
	}
}