/*<![CDATA[*/
// Basic Element Animator (12-January-2007) DRAFT
// by Vic Phillips http://www.vicsjavascripts.org.uk

// To progressively change the Left, Top, Width, Height or Opacity of an element over a specified period of time.

// **** Application Notes

// **** The HTML Code
//
// when moving an element the inline or class rule style position of the element should be assigned as
// 'position:relative;' or 'position:absolute;'
//
// The element would normally be assigned a unique ID name.
//

// **** Executing the Effect(Script)
//
// The effect is executed by an event call to function 'zxcBAnimator('left','tst1',20,260,2000);'
// where:
// parameter 0 = the mode(see Note 1).                                                                     (string)
// parameter 1 = the unique ID name or element object.                                                     (string or element object)
// parameter 2 = the start position of the effect.                                                         (digits, for opacity minimum 0, maximum 100)
// parameter 3 = the finish position of the effect.                                                        (digits, for opacity minimum 0, maximum 100)
// parameter 4 = (optional) period of time between the start and finish of the effect in milliseconds.     (digits or defaults to 2000 milliSeconds)
//
//  Note 1:  The default units(excepting opacity) are 'px'.
//  Note 2:  Examples modes: 'left', 'top', 'width', 'height', 'opacity.
//           For hyphenated modes, the first character after the hyphen must be upper case, all others lower case.
//  Note 3:  To 'toggle' the effect include '#' in parameter 0.
//           The first call will set the toggle parameters.
//           Subsequent calls with '#' in parameter 0 and the same start and finish parameters will 'toggle' the effect.
//  Note 4:  The function may be re-executed with a different set of parameters (start/finish time or period)
//           whenever required, say from an onclick/mouseover/out event.
//           The period parameter will be retained unless re-specified.
//
// **** Advanced Applications
//
//  It may be required to access the current value of the effect.
//  The element effect is accessible from the element property
//  element effect = elementobject[mode.replace(/[-#]/g,'')+'oop'];
//  where mode is parameter 0 of the initial call.
//  An array storing the current, start and finish values of the element effect may be accessed
//  from the element effect.data as fields 0, 1 and 2 respectively
//

// **** General
//
// All variable, function etc. names are prefixed with 'zxc' to minimise conflicts with other JavaScripts.
// These characters may be changed to characters of choice using global find and replace.
//
// The Functional Code (about 2K) is best as an External JavaScript.
//
// Tested with IE7 and Mozilla FireFox on a PC.
//



// **** Functional Code - NO NEED to Change


function zxcBAnimator(zxcmde,zxcobj,zxcsrt,zxcfin,zxctime){
 if (typeof(zxcobj)=='string'){zxcobj=document.getElementById(zxcobj);}
 if (!zxcobj||(!zxcsrt&&!zxcfin)) return;
 var zxcoop=zxcobj[zxcmde.replace(/[-#]/g,'')+'oop'];
 if (zxcoop){
  clearTimeout(zxcoop.to);
  if (zxcoop.srtfin[0]==zxcsrt&&zxcoop.srtfin[1]==zxcfin&&zxcmde.match('#')) zxcoop.update([zxcoop.data[0],(zxcoop.srtfin[0]==zxcoop.data[2])?zxcfin:zxcsrt],zxctime);
  else zxcoop.update([zxcsrt,zxcfin],zxctime);
 }
 else zxcobj[zxcmde.replace(/[-#]/g,'')+'oop']=new zxcBAnimatorOOP(zxcmde,zxcobj,zxcsrt,zxcfin,zxctime);
}

function zxcBAnimatorOOP(zxcmde,zxcobj,zxcsrt,zxcfin,zxctime){
 this.srtfin=[zxcsrt,zxcfin];
 this.to=null;
 this.obj=zxcobj;
 this.mde=zxcmde.replace(/[-#]/g,'');
 this.update([zxcsrt,zxcfin],zxctime);
}

zxcBAnimatorOOP.prototype.update=function(zxcsrtfin,zxctime){
 this.time=zxctime||this.time||2000;
 if (zxcsrtfin[0]==zxcsrtfin[1]) return;
 this.data=[zxcsrtfin[0],zxcsrtfin[0],zxcsrtfin[1]];
 this.srttime=new Date().getTime();
 this.cng();
}

zxcBAnimatorOOP.prototype.cng=function(){
 var zxcms=new Date().getTime()-this.srttime;
 this.data[0]=(this.data[2]-this.data[1])/this.time*zxcms+this.data[1];
 if (this.mde!='opacity') this.obj.style[this.mde]=this.data[0]+'px';
 else  this.opacity(this.data[0]);
 if (zxcms<this.time) this.to=setTimeout(function(zxcoop){return function(){zxcoop.cng();}}(this), 10);
 else {
  if (this.mde!='opacity') this.obj.style[this.mde]=this.data[2]+'px';
  else  this.opacity(this.data[2]);
 }
}

zxcBAnimatorOOP.prototype.opacity=function(zxcopc){
 if (zxcopc<0||zxcopc>100){return;}
 this.obj.style.filter='alpha(opacity='+zxcopc+')';
 this.obj.style.opacity=this.obj.style.MozOpacity=this.obj.style.KhtmlOpacity=zxcopc/100-.001;
}


/*]]>*/

/*<![CDATA[*/
// Slide Show Fade Application of Basic Element Animator (07-March-2008)
// by Vic Phillips http://www.vicsjavascripts.org.uk

// **** The HTML Code
// Images are defined and displayed in a parent DIV
// this DIV must be assigned a unique id name and have a style position defined a 'relative' or 'absolute'
// The Images must have a style position of 'absolute' and top and left of '0px'.
// Images may be nested in link tags in which case the image will be assigned a cursor of 'pointer' by the code.
// Clicking the image will link to the page specified by the href
// or if no href but assigned a title of a valid function name the image object will be passed to the function.

// **** Initialisation
// Normally initialised  from a <BODY> or window onload event call to function:
// zxcInitSlideShow(zxcid,zxcspd,zxchold,zxctxt,zxcauto)
// where:
// parameter 0 = the unique id name of the slide show patent node.                (string)
// parameter 1 = (optional) the speed of the fade effect in millSeconds.          (digits, default 1000)
// parameter 2 = (optional) the auto rotate hold delay between images.            (digits, default 4000)
// parameter 3 = (optional) the class name of the DIV to display the image title. (string)
// parameter 4 = (optional) to automaticaly start auto rotation.                  (string)
//
// Subsequent calls to zxcInitSlideShow may be used to modify parameters 1 and 2.

// **** Manual Controls (Rotate)
// The slideshow may be rotated by event calls to function:
// zxcSlideShow('tst',1,'auto');
// where:
// parameter 0 = the unique id name of the slide show patent node.                     (string)
// parameter 1 = 1 to rotate forward, -1 to rotate backwards, 0 to stop auto rotation. (1, -1 or 9)
// parameter 2 = (optional) to auto rotate.                                            (string)
//

// **** Manual Controls (GoTo)
// The slideshow may be forced to go to a specific image by event calls to function:
// zxcSlideShowGoTo('tst',0);
// where:
// parameter 0 = the unique id name of the slide show patent node.                     (string)
// parameter 1 = the image to goto.                                                    (1 to n)


// **** Functional Code - NO NEED TO CHANGE

function zxcInitSlideShow(zxcid,zxcspd,zxchold,zxctxt,zxcauto){
 var zxcp=document.getElementById(zxcid);
 if (!zxcp.slideshow) zxcp.slideshow=new zxcSlideShowOOP(zxcp,zxcspd,zxchold,zxctxt,zxcauto);
 else {
  var zxcoop=zxcp.slideshow;
  zxcoop.spd=zxcspd||zxcoop.spd;
  zxcoop.hold=zxchold||zxcoop.hold;
 }
}

function zxcSlideShowOOP(zxcp,zxcspd,zxchold,zxctxt,zxcauto){
 this.imgs=zxcp.getElementsByTagName('IMG');
 for (var zxc0=0;zxc0<this.imgs.length;zxc0++){
  zxcBAnimator('opacity',this.imgs[zxc0],(zxc0==0)?90:10,(zxc0==0)?100:0,10);
  zxcES(this.imgs[zxc0],{zIndex:(zxc0>0)?'0':'1',left:(zxcp.offsetWidth-this.imgs[zxc0].offsetWidth)/2+'px',top:(zxcp.offsetHeight-this.imgs[zxc0].offsetHeight)/2+'px',cursor:(this.imgs[zxc0].parentNode.tagName.toUpperCase()=='A')?'pointer':'default'});
  if (this.imgs[zxc0].style.cursor=='pointer'){
   this.imgs[zxc0].link=this.imgs[zxc0].parentNode.href||this.imgs[zxc0].parentNode.title||null;
   this.imgs[zxc0].parentNode.removeAttribute('title');
   this.imgs[zxc0].onclick=function(){
     if (window[this.link]) window[this.link](this);
     else if (this.link) window.top.location=this.link;
    }
  }
  if (zxctxt){
   this.imgs[zxc0].txt=zxcES('DIV',{visibility:(this.imgs[zxc0].title)?'visible':'hidden'},zxcp,this.imgs[zxc0].title||'');
   this.imgs[zxc0].txt.className=zxctxt;
   zxcBAnimator('opacity',this.imgs[zxc0].txt,(zxc0==0)?90:10,(zxc0==0)?100:0,10);
   this.imgs[zxc0].removeAttribute('title');
  }
 }
 this.p=zxcp;
 this.cnt=0;
 this.spd=zxcspd||1000;
 this.hold=zxchold||this.spd*4;
 this.to=null;
 if (zxcauto) this.to=setTimeout(function(zxcoop){return function(){zxcoop.auto(1);}}(this),this.hold);
}

zxcSlideShowOOP.prototype.rotate=function(zxcud,zxcgoto){
 zxcES(this.imgs[this.cnt],{zIndex:'0'});
 zxcBAnimator('opacity',this.imgs[this.cnt],this.imgs[this.cnt]['opacityoop'].data[0],0,this.spd)
 if (this.imgs[this.cnt].txt) zxcBAnimator('opacity',this.imgs[this.cnt].txt,this.imgs[this.cnt].txt['opacityoop'].data[0],0,this.spd)
 this.cnt+=zxcud||0;
 if (zxcgoto) this.cnt=zxcgoto-1;
 if (this.cnt>=this.imgs.length) this.cnt=0;
 if (this.cnt<0) this.cnt=this.imgs.length-1;
 zxcES(this.imgs[this.cnt],{zIndex:'1'});
 zxcBAnimator('opacity',this.imgs[this.cnt],this.imgs[this.cnt]['opacityoop'].data[0],100,this.spd)
 if (this.imgs[this.cnt].txt) zxcBAnimator('opacity',this.imgs[this.cnt].txt,this.imgs[this.cnt].txt['opacityoop'].data[0],100,this.spd)
}

zxcSlideShowOOP.prototype.auto=function(zxcud){
 this.rotate(zxcud);
 this.to=setTimeout(function(zxcoop){return function(){zxcoop.auto(zxcud);}}(this),this.hold);
}

function zxcES(zxcele,zxcstyle,zxcp,zxctxt){
 if (typeof(zxcele)=='string'){zxcele=document.createElement(zxcele);}
 for (key in zxcstyle){zxcele.style[key]=zxcstyle[key];}
 if (zxcp){zxcp.appendChild(zxcele);}
 if (zxctxt){zxcele.appendChild(document.createTextNode(zxctxt));}
 return zxcele;
}

function zxcSlideShow(zxcid,zxcud,zxcauto){
 var zxcoop=document.getElementById(zxcid).slideshow;
 if (!zxcoop) return false;
 clearTimeout(zxcoop.to);
 if (!zxcauto) zxcoop.rotate(zxcud);
 else if (zxcud) zxcoop.auto(zxcud);
}

function zxcSlideShowGoTo(zxcid,zxcnu){
 var zxcoop=document.getElementById(zxcid).slideshow;
 if (!zxcoop||!zxcoop.imgs[zxcnu-1]) return false;
 clearTimeout(zxcoop.to);
 zxcoop.rotate(0,zxcnu)
}

/*]]>*/


/*<![CDATA[*/

function MyFunction(img){
 alert(img.src);
}
/*]]>*/

