var ns4 = ( document.layers ) ? 1 : 0;
var ie4 = ( document.all ) ? 1 : 0;
var ie5 = ( navigator.appVersion.indexOf( 'MSIE 5' ) > 0 ) ? 1 : 0;

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var ns6 = (is_nav && (is_major >= 5));


function getInsideWindowWidth() {
	if( ns4 ) {
		return window.innerWidth;
	} else if( ie4 ) {
		return document.body.clientWidth;
	}
}

function getInsideWindowHeight() {
	if( ns4 ) {
		return window.innerHeight;
	} else if( ie4 ) {
		return document.body.clientHeight;
	}
}

function Dynamic( id, path ) {
	if( ns4 ) {
		this.p = ( !path ? document.layers[id] : document.getElementById( id )  ); // eval( "document." + path + ".document." + id )
		this.elm = this.event = this.p;
		if( typeof this.elm == 'undefined' ) alert( '<div id=' + id + '> does not exist' );
		this.x = this.p.left;
		this.y = this.p.top;
		// NS4 TEST
		this.xDefault = this.p.left;
		this.yDefault = this.p.top;
		// NS4 TEST END
		this.z = this.elm.zIndex;
		this.visibility = (this.p.visibility == 'show');
		this.width = this.p.clip.width;
		this.height = this.p.clip.height;
		this.doc = this.p.document;
	} else if( ie4 || ns6 ) {
		this.p = ( ie5 || ns6 ? document.getElementById( id ).style : document.all[id].style );
		this.elm = this.event = ( ns6 ? document.getElementById( id ) : this.event = document.all[id] );
		this.x = this.p.pixelLeft;
		this.y = this.p.pixelTop;
		this.z = this.p.zIndex;
		this.visibility = (this.p.visibility == 'visible');
		if( ie4 ) {
			this.width = this.elm.offsetWidth;
			this.height = this.elm.offsetHeight;
		} else {
			this.width = this.p.pixelWidth;
			this.height = this.p.pixelHeight;
		}
	}
	this.id = id;
	this.obj = id + "Dyn";
	eval( this.obj + " = this" );
	this.moveTo = dynamicMoveTo;
	this.moveBy = dynamicMoveBy;
	this.scrolling = 0;
	this.scrollStep = 8;
	this.scrollLeft = dynamicScrollLeft;
	this.scrollRight = dynamicScrollRight;
	this.scrollStop = dynamicScrollStop;
	this.clipTo = dynamicClipTo;
	this.getClip = dynamicGetClip;
	this.show = dynamicShow;
	this.hide = dynamicHide;
	this.setZ = dynamicSetZ;
	this.setBody = dynamicSetBody;
	this.getSize = dynamicGetSize;
}

function dynamicMoveTo( x, y ) {
	this.x = x;
	this.y = y;
	if( ns4 ) {
  	this.xDefault = x;
   	this.yDefault = y;
		this.p.left = x;
		this.p.top = y;
	} else if( ie4 || ie5 ) {
		this.p.pixelLeft = x;
		this.p.pixelTop = y;
	} else {
		this.p.left = x;
		this.p.top = y;
	}
}

function dynamicMoveBy( x, y ) {
	this.moveTo( this.x + x, this.y + y );
}

function dynamicClipTo( t, r, b, l) {
	if( ns4 ) {
		this.p.clip.top = t;
		this.p.clip.right = r;
		this.p.clip.bottom = b;
		this.p.clip.left = l;
	} else if( ie4 ) {
		this.p.clip = "rect(" + t + "px " + r + "px " + b + "px " + l + "px)";
	}
}

function dynamicGetClip( edge ) {
	if( ns4 ) {
		switch( edge ) {
			case 't':
				return this.p.clip.top;
				break;
			case 'r':
				return this.p.clip.right;
				break;
			case 'b':
				return this.p.clip.bottom;
				break;
			case 'l':
				return this.p.clip.left;
				break;
		}
	} else if( ie4 ) {
		var edges = this.p.clip.split("rect(")[1].split(")")[0].split("px");
		switch( edge ) {
			case 't':
				return Number( edges[0] );
				break;
			case 'r':
				return Number( edges[1] );
				break;
			case 'b':
				return Number( edges[2] );
				break;
			case 'l':
				return Number( edges[3] );
				break;
		}
	}
}

function dynamicScrollLeft( endX, speed ) {
	if( this.x < endX ) {
    if( endX - this.x >= this.scrollStep ) {
  		this.moveBy( this.scrollStep, 0 );
  		this.scrolling = setTimeout( this.obj + ".scrollLeft(" + endX + ", " + speed + ")", speed );
  	} else {
      this.moveTo( endX, this.y );
      clearTimeout( this.scrolling );
    }
	} else {
    this.moveTo( endX, this.y );
    clearTimeout( this.scrolling );
  }
}

function dynamicScrollRight( endX, speed ) {
	if( this.x > endX ) {
    if( this.x - endX >= this.scrollStep ) {
  		this.moveBy( -this.scrollStep, 0 );
  		this.scrolling = setTimeout( this.obj + ".scrollRight(" + endX + ", " + speed + ")", speed );
  	} else {
      this.moveTo( endX, this.y );
      clearTimeout( this.scrolling );
    }
	} else {
    this.moveTo( endX, this.y );
    clearTimeout( this.scrolling );
  }
}

function dynamicScrollStop() {
	if( this.scrolling ) clearTimeout( this.scrolling );
}

function dynamicShow() {
	this.visibility = 1;
	this.p.visibility = ( ns4 ? 'show' : 'visible' );
}

function dynamicHide() {
	this.visibility = 0;
	this.p.visibility = ( ns4 ? 'hide' : 'hidden' );
}

function dynamicSetZ( z ) {
	this.p.zIndex = z;
	this.z = z;
}

function dynamicSetBody() {
	if( ns4 ) {
	  var newBody = '';
	  newBody = '<html><head>\n';
	  newBody += '</head><body>\n';

		for( var i = 0; i < arguments.length; i++ ) {
			newBody += arguments[i] + '\n';
	  }
	  newBody += '</body></html>\n';

	  with( this.doc ) {
	    open();
	    write( newBody );
		  close();
		}
		this.width = this.p.clip.width;
		this.height = this.p.clip.height;
	} else if( ie4 || ns6 ) {
		var body = "";
		for( var i = 0; i < arguments.length; i++ ) {
			body += arguments[i] + "\n";
		}
		this.elm.innerHTML = body;
		this.getSize();
	}
}

function dynamicGetSize() {
	if( ie4 ) {
		this.width = this.elm.offsetWidth;
		this.height = this.elm.offsetHeight;
  }
}

document.write( '<div id="thepictureID" style="position: absolute; visibility: hidden;"></div>' );
var thepicture = new Dynamic( 'thepictureID' );
var closeTimeout = 0;

function showSuper( body, clickURL, doesScroll, autoClose ) {

  if( typeof( window.innerWidth ) == 'number' ) {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else {
    if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }

	theImage = new Image();
	theImage.src = body;
	imgWidth = theImage.width;
	imgHeight = theImage.height;

	thepicture.hide();
	thepicture.setZ( 10 );
	adCode = '<table border="0" cellspacing="0" cellpadding="0">' +
		         '<tr><td align="right" style="background-color: #efefef;"><a href="#" style="color: #000000; font-weight: bold; font-size: 13px; text-decoration: none;" onclick="thepicture.hide();">X</a>&nbsp;</span></td></tr>' +
		         '<tr><td><a href="' + clickURL + '" target="_blank"><img src="' + body + '" border="0"></a></td></tr>' +
		         '</table>';
	thepicture.setBody(adCode);

	if( doesScroll == true ) {
		thepicture.moveTo( (imgWidth - (imgWidth * 2)), ((myHeight / 2) - (imgHeight / 2)) );
		thepicture.show();
		thepicture.scrollLeft( ((myWidth / 2) - (imgWidth / 2)), .05 );
	} else {
		thepicture.moveTo( ((myWidth / 2) - (imgWidth / 2)), ((myHeight / 2) - (imgHeight / 2)) );
		thepicture.show();
	}

	if( autoClose != false ) {
		closeTimeout = setTimeout( "doHide()", (autoClose * 1000) );
	}
}

function doHide() {
	clearTimeout( closeTimeout );
	thepicture.hide();
}