home *** CD-ROM | disk | FTP | other *** search
- init( "Flip.init()" );
- var IMAGE_OFF_SUFFIX = "_off";
- var IMAGE_ON_SUFFIX = "_on";
-
- /********************************************************************************
- *
- * thing.flip.js
- *
- * usage :
- * Change OFF_SUFFIX and ON_SUFFIX to match image names.
- *
- * For each image which is to be flipped, document.onload should call
- * flip.myFlipName = new Flip( myImageName, myImageSource )
- * To turn image on, call
- * flip.myFlipName.on()
- * To turn image off, call
- * flip.myFlipName.off()
- *
- ********************************************************************************/
-
- var flip = new Array();
- function Flip( imgName, imgSrc, doc ){
- this.docImg = getDocImg(imgName, doc);
- this.imgOff = new Image( this.docImg.width, this.docImg.height );
- this.imgOffsrc = this.imgOff.src = this.docImg.src;
-
- this.imgOn = new Image ( this.docImg.width, this.docImg.height );
- this.imgOnsrc = this.imgOn.src = ( imgSrc != null ) ? imgSrc : this.docImg.src.replace( IMAGE_OFF_SUFFIX, IMAGE_ON_SUFFIX );
- }
-
- Flip.prototype.on = function(force){
- if( force ){
- this.imgOn.src = "";
- this.docImg.src = this.imgOnsrc;
- }
- else if( this.imgOn.src ){
- this.docImg.src = this.imgOn.src;
- }
- if ( this.status )
- window.status = this.status;
- return true;
- }
-
- Flip.prototype.off = function(force){
- if( force ){
- this.imgOff.src = "";
- this.docImg.src = this.imgOffsrc;
- }
- else if( this.imgOff.src ){
- this.docImg.src = this.imgOff.src;
- }
- window.status = "";
- return true;
- }
- Flip.prototype.killFlip = function( newSrc ){
- var fixedImgSrc;
- if ( newSrc == "on" )
- fixedImgSrc = this.imgOn.src;
- else if ( newSrc == "off" )
- fixedImgSrc = this.imgOff.src;
- else
- fixedImgSrc = newSrc;
- this.imgOff.src = this.imgOn.src = this.docImg.src = fixedImgSrc;
- }
- Flip.prototype.resurect = function(){
- this.imgOff.src = this.imgOffsrc;
- this.imgOn.src = this.imgOnsrc;
- this.docImg.src = this.imgOffsrc;
- }
- // function getDocImg( name )
- // - searches recursively through document.layers for the named image
- // - returns the named element in document.images
- function getDocImg(name, d){
- d = ( d == null ) ? document : d; //set d to be the document if empty
- var img = d.images[name];
- if (img) return img; //found it
-
- if ( ! document.layers ) return null; //in ie, we die here
-
- for ( var i=0; i < d.layers.length; i++ )
- if ( d.layers[i].id ){
- img = getDocImg( name, d.layers[i].document ); //recursive call
- if (img) return img; //found it
- }
- return null; //did not find it
- }
-
- // function mouseover(name)
- // - turn on flip[name] if it exists
- function mouseover(name){
- if (flip[name])
- flip[name].on();
- }
-
- // function mouseover(name)
- // - turn off flip[name] if it exists
- function mouseout(name){
- if (flip[name])
- flip[name].off();
- }
-
- // function getAllImages( d )
- // - searches through document for images
- // - recurses through layers
-
- Flip.init = function( d ){
- if( d == null ) d = document;
- for ( var i = 0; i < d.images.length; i++ ){
- var src = d.images[i].src;
- if ( d.images[i].name ){
- if ( src.indexOf( IMAGE_OFF_SUFFIX ) != -1 ){
- flip[ d.images[i].name ] = new Flip( d.images[i].name, null, d );
- }
- }
- }
- if ( !document.layers ) return;
- for ( var i=0; i < d.layers.length; i++ )
- Flip.init( d.layers[i].document ); //recursive call
- }
-
-