/*****************************************************
     Craiga.us JS Library
      You can use this for whatever you want 
       if you leave this message intact :)
        this Libary is only STANDARDS compliant 
         which means it won't work with non-standards
          compliant browers. 
******************************************************/

// Shorcuts (hehe)
 d = document; 
 d.ge = d.getElementById; 
 d.ce = d.createElement; 
 n = navigator; 
 w = window; 
 abs = Math.abs;
 min = Math.min; 
 max = Math.max; 
 sin = Math.sin; 
 cos = Math.cos; 
 round = Math.round; 
 ceil = Math.ceil; 
 floor = Math.floor; 
///////////////////////////////
// Variables
var cid = 0; 
var oid = 0; 
var nid = 0; 
///////////////////////////////

 function isStandards( )
 {
   if( d.ge && d.ce )
   { 
       return true;  
   } 
       else
   {
     return false; 
   }
 }
 function Create ( tag , text ) 
 {
   node = d.ce( tag ); 
   node.setAttribute('id',"CA_DIV" + cid); 
   text = text || ""; 
   str  = d.createTextNode( text ); 
   node.appendChild( str ); 
   body       = d.getElementsByTagName('body').item(0); 
     if(!body) alert('Your missing a body tag and this cannot work!'); 
   body.appendChild( node ); 
   return "CA_DIV" + cid; 
   cid++; 
 }

 function CA_Object ( id )
 {
   this.rt    = 0; 
   this.x     = 0; 
   this.y     = 0;
   this.w     = 1; 
   this.h     = 1; 
   this.css   = d.ge( id ).style; 
   this.ref   = d.ge( id ); 
   this.id    = id; 
   this.obj   = "CA_Object" + oid; 
   this.nodes = new Array(); 
   eval(this.obj+'=this'); 
   oid++; 
 }

// Functions for CA_Object:

   CA_Object.prototype.resizeToOverflow = function ( inc, speed )
   {
     this.before = this.css.overflow; 
     this.css.overflow="visible"; 
     this.overflowh = parseInt(this.ref.offsetHeight); 
     this.overfloww = parseInt(this.ref.offsetWidth); 
     this.css.overflow=this.before; 
     this.resizeElasticTo(this.overfloww,this.overflowh,inc,speed); 
   } 

   CA_Object.prototype.resizeDoSlide = function ( )
   {
     if(this.rsteps > 0)
     {
       this.resizeTo( this.w + this.incw, this.h + this.inch ); 
       this.rsteps--; 
       this.rt = setTimeout(this.obj+'.resizeDoSlide()',this.rspeed); 
     }
   }

   CA_Object.prototype.resizeSlideTo = function ( w , h , steps , speed )
   {
     this.distw = w - this.w; 
     this.disth = h - this.h; 
     this.incw  = this.distw / steps; 
     this.inch  = this.disth / steps; 
     this.rsteps = steps; 
     this.rspeed = speed; 
     this.resizeDoSlide(); 
   }

   CA_Object.prototype.resizeDoElasticSlide = function (a)
   {
     this.distw = this.tow - this.w;
     this.disth = this.toh - this.h;
     if (( abs (this.distw) > 1) || ( abs(this.disth) > 1 )) 
     {
       this.neww = this.w + ( this.distw / this.rinc );
       this.newh = this.h + ( this.disth / this.rinc ); 
       this.resizeTo ( this.neww , this.newh );  
       setTimeout(this.obj+'.resizeDoElasticSlide()',this.rspeed); 
     }
   }

   CA_Object.prototype.resizeElasticTo = function ( w , h , inc , speed )
   {
     this.tow    = w; 
     this.toh    = h; 
     this.rinc   = inc; 
     this.rspeed = speed;
     this.resizeDoElasticSlide(1);  
   }

   CA_Object.prototype.doElasticSlide = function ( )
   {
     this.distx = this.tox - this.x;
     this.disty = this.toy - this.y; 
     if ( abs ( this.distx ) > 1 || abs ( this.disty ) > 1 ) 
     {
       this.newx = this.x + ( this.distx / this.inc );
       this.newy = this.y + ( this.disty / this.inc ); 
       this.moveTo ( this.newx , this.newy ); 
       setTimeout(this.obj+'.doElasticSlide()',this.speed); 
     }
   }

   CA_Object.prototype.elasticTo = function ( x , y , inc , speed )
   {
     this.tox   = x; 
     this.toy   = y; 
     this.inc   = inc; 
     this.speed = speed;
     this.doElasticSlide();  
   }

   CA_Object.prototype.doSlide = function ( )
   {
     if(this.steps > 0)
     {
       this.moveTo( this.x + this.incx, this.y + this.incy ); 
       this.steps--; 
       setTimeout(this.obj+'.doSlide()',this.speed); 
     }
   }

   CA_Object.prototype.slideTo = function ( x , y , steps , speed )
   {
     this.distx = x - this.x; 
     this.disty = y - this.y; 
     this.incx  = this.distx / steps; 
     this.incy  = this.disty / steps; 
     this.steps = steps; 
     this.speed = speed; 
     this.doSlide(); 
   }

   CA_Object.prototype.clearNodes = function ( )
   {
     for( i = 0; i < this.nodes.length; i++ ){
       this.nodes[i].remove(); 
     }
    this.nodes = new Array(); 
   }

   CA_Object.prototype.moveTo = function ( x , y ) 
   {
     this.x = x; this.y = y; 
     this.css.left = x; this.css.top = y; 
   }

   CA_Object.prototype.resizeTo = function ( w , h )
   {
     this.w = w; this.h = h; 
     this.css.width = w; this.css.height = h; 
   }
   
   CA_Object.prototype.insertTag = function ( tag , text )
   {
     node = d.ce( tag ); 
     if(text){
     str  = d.createTextNode( text );  
     node.appendChild( str ); 
     }
     if(tag.toLowerCase() == "a") node.setAttribute('href','#'); 
     node.setAttribute('id',"CA_NODE" + nid); 
     this.ref.appendChild( node ); 
     lng = this.nodes.length;   
     this.lastNode     = new CA_Object ( "CA_NODE" + nid ); 
     this.nodes[lng]   = new CA_Object ( "CA_NODE" + nid ); 
     nid++; 
   }
       
   CA_Object.prototype.remove = function ( )
     { this.ref.parentNode.removeChild(this.ref); }

   CA_Object.prototype.hide = function ( )
     { this.css.visibility = "hidden"; }
 
   CA_Object.prototype.show = function ( )
     { this.css.visibility = "visible";}

   CA_Object.prototype.makeAbsolute = function ( ) 
     { this.css.position = "absolute"; }
  
   CA_Object.prototype.hideOverflow = function ( )
     { this.css.overflow = "hidden"; }
 
   CA_Object.prototype.border = function ( brd )
     { this.css.border = brd; }
  
   CA_Object.prototype.bg = function ( bgc ) 
     { this.css.backgroundColor = bgc; }
  
   CA_Object.prototype.fg = function ( fgc )
     { this.css.color = fgc; }

   CA_Object.prototype.fontSize = function ( fs )
     { this.css.fontSize = fs; }
  
   CA_Object.prototype.fontFamily = function ( ff )
     { this.css.fontFamily = ff; }
 
   CA_Object.prototype.font = function ( f ) 
     { this.css.font = f; }

   CA_Object.prototype.setCSS = function ( )
     { 
       args = CA_Object.prototype.setCSS.arguments; 
       for(i = 0; i < args.length; i+=2) {
         eval("this.css"+"."+args[i]+"='"+args[(i+1)]+"'"); 
       }
     }

// JS Object, handles some js stuff
//
  function JS ( site )
  {
    this.site = site; 
  }
 
  JS.prototype.include = function ( file )
  {
    ojs = d.ce('script'); 
    ojs.src = this.site + file; 
    body       = d.getElementsByTagName('body').item(0); 
     if(!body) alert('Your missing a body tag and this cannot work!'); 
    body.appendChild( ojs ); 
  }
