/* Author: 
Feast 2011
*/
$(document).ready(function() {
	
	// file browser
	if($('#documents').length >=1){
		$('.filelist').click(function(e){
			e.preventDefault();
			var folder = "folder=" + $(this).attr('href');
			$.ajax({
			  url: "_inc/asset/asset_filelist.php",
			  type: "GET",
			  data: folder,
			  success: function(data){		  
				$("#files").html();	
				$("#files").html(data);		  
			  }
			});	
			return false;
		});
		
		$('.folderinfo').click(function(e){
			e.preventDefault();
			var folder = "folder=" + $(this).attr('rel');
			$.ajax({
			  url: "_inc/asset/asset_folderinfo.php",
			  type: "GET",
			  data: folder,
			  success: function(data){
				$("#description").html();
				$("#description").html(data);		  
			  }
			});	
			return false;
		});
	};
	
  //Tooltips
	var tip;	
	if($('ul.bios li').length >=1){
		$("ul.bios li a").hover(function(){
			tip = $(this).find('.tip').remove();
			$('body').append(tip);
			tip.show(); //Show tooltip
		}, function() {
			tip.hide().remove(); 
			$(this).append(tip); 
		}).mousemove(function(e) {
			  var mousex = e.pageX + 20; //Get X coodrinates
			  var mousey = e.pageY + 20; //Get Y coordinates
			  var tipWidth = tip.width(); //Find width of tooltip
			  var tipHeight = tip.height(); //Find height of tooltip
	
			 //Distance of element from the right edge of viewport
			  var tipVisX = $(window).width() - (mousex + tipWidth);
			  var tipVisY = $(window).height() - (mousey + tipHeight);
	
			if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
				mousex = e.pageX - tipWidth - 20;
				$(this).find('.tip').css({  top: mousey, left: mousex });
			} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
				mousey = e.pageY - tipHeight - 20;
				tip.css({  top: mousey, left: mousex });
			} else {
				tip.css({  top: mousey, left: mousex });
			}
		});	
	};

});

