/*
SimpleJS ver 0.02 beta
----------------------
SimpleJS is developed by Christophe "Dyo" Lefevre (http://bleebot.com/)

$ajax function is based on Simple AJAX Code-Kit (SACK)
Gregory Wild-Smith (http://www.twilightuniverse.com/)

*/ 
//generic fonctions
function $(id) {
   return document.getElementById(id);
   }
function STO(func,time) {
	return window.setTimeout(func,time);
	} 
//blinds effects

function $toggle(id) {
   if (act_height(id) == 0) $blinddown(id);
   else $blindup(id);
   }
function act_height(id) {
   height = $(id).clientHeight;
   if(height == 0) height = $(id).offsetHeight;
   return height;
   }
function act_width(id) {
   width = $(id).clientWidth;
   if(width == 0) width = $(id).offsetWidth;
   return width;
   }
function max_height(id) {
   var ids = $(id).style;
   ids.overflow = 'hidden';
   if (act_height(id)!=0) return act_height(id);
   else
   {
   origdisp = ids.display;
   origheight = ids.height;
   origpos = ids.position;
   origvis = ids.visibility;
   ids.visibility = 'hidden';
   ids.height = '';
   ids.display = 'block';
   ids.position = 'absolute';
   height = act_height(id);
   ids.display = origdisp;
   ids.height = origheight;
   ids.position = origpos;
   ids.visibility = origvis;
   return height;
   }
   }
function $blindup(id, time) {
   if (!time)time = 500;
   acth = act_height(id);
   maxh = max_height(id);
   if (acth == maxh) {
      $(id).style.display = 'block';
      var steps;
      steps = Math.ceil(time / acth);
      for(i = 0; i <= acth; i++) {
         newh = acth - i;
         STO("$('" + id + "').style.height='" + newh + "px'", steps * i);
         }
      }
   }
function $blinddown(id, time) {
   if (!time)time = 500;
   acth = act_height(id);
   if (acth == 0) {
      maxh = max_height(id);
      $(id).style.display = 'block';
      $(id).style.height = '0px';
      var steps;
      steps = Math.ceil(time / maxh);
      for(i = 1; i <= maxh; i++) {
         STO("$('" + id + "').style.height='" + i + "px'", steps * i);
         }
      }
   }  

//$opacity effects
function $opacity(id, opacStart, opacEnd, time) {
   if($(id).style.width==0) $(id).style.width=act_width(id);
   var speed = Math.round(time / 100);
   var timer = 0;
   if(opacStart > opacEnd) {
      for(i = opacStart; i >= opacEnd; i--) {
         STO("changeOpac(" + i + ",'" + id + "')", (timer * speed));
         timer++;
         }
      }
   else if(opacStart < opacEnd) {
      for(i = opacStart; i <= opacEnd; i++) {
         STO("changeOpac(" + i + ",'" + id + "')", (timer * speed));
         timer++;
         }
      }
   }
function changeOpac(opacity, id) {
   var ids = $(id).style;
   ids.opacity = (opacity / 100);
   ids.MozOpacity = (opacity / 100);
   ids.KhtmlOpacity = (opacity / 100);
   ids.filter = "alpha(opacity=" + opacity + ")";
   }
function $shiftOpacity(id, time) {
   if($(id).style.opacity < 0.50) {
      $opacity(id, 0, 100, time);
      }
   else {
      $opacity(id, 100, 0, time);
      }
   }
function currentOpac(id, opacEnd, time) {
   var currentOpac = 100;
   if($(id).style.opacity < 100) {
      currentOpac = $(id).style.opacity * 100;
      }
   $opacity(id, currentOpac, opacEnd, time)}
