// JavaScript Document

var ShowFlags_Image = 1;
var ShowFlags_Text  = 2;




function CustomBorder ( )
{
	// Setup Defaults;
  this . TopStyle    = "solid";
	this . LeftStyle   = "solid";
	this . RightStyle  = "solid";
	this . BottomStyle = "solid";
	
	this . TopColor    = "black";
	this . LeftColor   = "black";
	this . RightColor  = "black";
	this . BottomColor = "black";
	
	this . TopWidth    = "1px";
	this . LeftWidth   = "1px";
	this . RightWidth  = "1px";
	this . BottomWidth = "1px";	
	
	this . ApplyBorderToObject = ApplyBorderToObject;
	this . Apply               = Apply;
	this . ApplyStyle          = ApplyStyle;
	this . ApplyColor          = ApplyColor;
	this . ApplyWidth          = ApplyWidth;
}

function ApplyBorderToObject ( Obj )
{
	var Style = Obj . style;
	
	Style . borderTopStyle    = this . TopStyle;
	Style . borderLeftStyle   = this . LeftStyle;
	Style . borderRightStyle  = this . RightStyle;
	Style . borderBottomStyle = this . BottomStyle;
	
	Style . borderTopColor    = this . TopColor;
	Style . borderLeftColor   = this . LeftColor;
	Style . borderRightColor  = this . RightColor;
	Style . borderBottomColor = this . BottomColor;
	
	Style . borderTopWidth    = this . TopWidth;
	Style . borderLeftWidth   = this . LeftWidth;
	Style . borderRightWidth  = this . RightWidth;
	Style . borderBottomWidth = this . BottomWidth;	
}

function Apply ()
{
	if ( arguments . length > 0 ) 
	{
		this . ApplyStyle ( arguments [ 0 ] );
	}
	if ( arguments . length > 1 ) 
	{
		this . ApplyColor ( arguments [ 1 ] );
	}
	if ( arguments . length > 2 ) 
	{
		this . ApplyWidth ( arguments [ 2 ] );
	}
}

function ApplyStyle ( AStyle )
{
	this . TopStyle    = AStyle;
	this . LeftStyle   = AStyle;
	this . RightStyle  = AStyle;
	this . BottomStyle = AStyle;	
}

function ApplyColor ( AColor )
{
	this . TopColor    = AColor;
	this . LeftColor   = AColor;
	this . RightColor  = AColor;
	this . BottomColor = AColor;
}


function ApplyWidth ( AWidth )
{
	this . TopWidth    = AWidth;
	this . LeftWidth   = AWidth;
	this . RightWidth  = AWidth;
	this . BottomWidth = AWidth;	
}


function SlideShow ( SelfRef, Dx, Dy, ZOrder, AttackDecay, OverFrames, InitTime )
{	
  this . SelfRef     = SelfRef;
	this . ZOrder      = ZOrder; 
	this . AttackDecay = AttackDecay;
	this . OverFrames  = OverFrames;	
	this . Scale       = 100;
	this . LayerA      = dLinkLayer ( SelfRef, "", "", "", Dx, Dy, 10, 10, "", ZOrder, true, 0 );
	this . LayerB      = dLinkLayer ( SelfRef + "A", "", "", "", Dx, Dy, 10, 10, "", ZOrder - 1, true, 100 );
	
	this . Paths      = new Array ();
	this . BorderObj  = new Array ();
	this . Delay      = new Array ();
	this . XLPos      = new Array ();
	this . YLPos      = new Array ();
	this . Width      = new Array ();
	this . Height     = new Array ();
	this . Flags      = new Array ();
	this . Images     = new Array ();
	this . ImageA     = null;
	this . ImageB     = null;
	this . TextA      = null;
	this . TextB      = null;
	this . Timer      = null;
	this . AddFactor  = 0;
	this . Opacity    = 0;
	this . ImagePos   = 0;
	this . DefX       = Dx;
	this . DefY       = Dy;
	this . TimerStyle = 0;
	this . IntervalStr = "";
	this . Interval    = 0;
	this . Triggered   = false;
	this . InitTime    = InitTime;
	this . TrigTrue    = false;
	
	this . ImageDir  = "";
	
	this . LogPath              = LogPath;	
	this . Execute              = Execute;	
	this . ChangeImages         = ChangeImages;
	this . ProcessImageInterval = ProcessImageInterval;
	this . PreloadImages        = PreloadImages;
	this . Execute              = Execute;
	this . ImageTimeOut         = ImageTimeOut;
	this . StartTimeOut         = StartTimeOut;
	this . ScaleImage           = ScaleImage;
	this . SetImage             = SetImage;
	this . InterruptTimer       = InterruptTimer;
	this . RestartTimer         = RestartTimer;
	this . Reset                = Reset;
	this . Trigger              = null;
	this . TimerExecute         = TimerExecute;
	
	
	
	this . FirstPass = true;
}

function ScaleImage ()
{
  if ( this . Scale == 100 ) return;
	if ( this . FirstPass == false ) return;
	
	this . ImageA . width  = ( this . ImageA . width  * this . Scale ) / 100;
	
	this . ImageA . height = ( this . ImageA . height * this . Scale ) / 100;
		
}

function Reset ()
{
	SetLayerOpacity ( this. LayerA, 0 );
	SetLayerOpacity ( this. LayerB, 100 );
	this . InterruptTimer ();
	if ( this . TimerStyle == 2 ) 
	{
		this . ImagePos = this . ImagePos - 1;
		if ( this . ImagePos < 0 ) this . ImagePos = this . Paths . length - 1;
	}
  if ( this . ImageA != null )
	{
		this . LayerA . removeChild ( this . LayerA . lastChild );
		delete this . ImageA;
	}	
	if ( this . ImageB != null )
	{
		this . LayerB . removeChild ( this . LayerB . lastChild );
		delete this . ImageB;
	}
}

function SetImage ( Pos )
{	
	var NewImage;
	if ( Pos > this . Paths . length ) 
	{
		alert ( "Image not at position  " + Pos );
		return;
	}
	if ( this . LayerA . childNodes . length > 0 )
	{
		var leng      = this . LayerA . childNodes . length;
		var NodeType;
		var ChildList = this . LayerA . childNodes;
		while ( leng != 0 )
		{
			Child = ChildList [ 0 ];
			NodeType = Child . nodeType;
			this . LayerA . removeChild ( Child );			
			//if ( NodeType == 3 ) Child = null;			
			leng --;
		}		
	}
	
	if ( ( this . Flags [ Pos ] & ShowFlags_Text ) == 0 ) 
	{
		//this . ImageA = BuildImageLayer ( this . LayerA );
		
		
		
		if ( this . Images [ Pos ] == null ) // this section has to be in for IE
		{
			NewImage = new Image ();
			NewImage . src = this . Paths [ Pos ]; // it prealoads the image for its natural height and width
			this . Images [ Pos ] = NewImage;
			
		}
		this . LayerA . appendChild ( this . Images [ Pos ] );	
		
		var P = Pos + 1;
		if ( P >= this . Paths . length )
		{
			P = 0;
		}
		if ( this . Images [ P ] == null )
		{
			this . PreloadImages ( P );
		}
		
	}
	else
	{
		this . ImageA = BuildTextLayer ( this . LayerA, "hidden" );	
		this . LayerA . innerHTML = this . Paths [ Pos ];
	}
	
	if ( ( this . Flags [ Pos ] & ShowFlags_Text ) > 0 )
	{
		SetLayerWidthHeight ( this . LayerA, this . Width [ Pos ], this . Height [ Pos ] );
	}
	else
	{
	  if ( this . Width [ Pos ] == null  || this . Height [ Pos ] == null ) 
		{ 
		  SetLayerToImageDims ( this . LayerA, this . ImageA );
		}
	  else                                                              SetLayerWidthHeight ( this . LayerA, this . Width [ Pos ], this . Height [ Pos ] );
	}
	if ( this . XLPos [ Pos ] == null || this . YLPos [ Pos ] == null ) SetLayerPosition ( this . LayerA, this . DefX, this . DefY );
	else                                                                SetLayerPosition ( this . LayerA, this . XLPos [ Pos ], this . YLPos [ Pos ] );
	
		
	if ( this . BorderObj [ Pos ] != null )
	{
	  ( this . BorderObj [ Pos ] ) . ApplyBorderToObject ( this . LayerA );	
	}	
}

function PreloadImages ( )
{
	var Pos;
  if ( arguments . length == 0 ) return;
	
	for ( var x = 0; x < arguments . length; x = x + 1 )
	{
		Pos = arguments [ x ];
		if ( Pos < 0 || Pos >= this . Paths . length ) continue;
		if ( this . Images [ Pos ] != null ) continue;
		this . Images [ Pos ] = new Image ();
		this . Images [ Pos ] . src = this . Paths [ Pos ];
	}
}

function ChangeImages ()
{
	this . IntervalStr = ""; 
	this . IntervalStr   = "ProcessImageTimer ('" + this . SelfRef + "')";
	this . Interval      = ( this . AttackDecay * 1000 ) / this . OverFrames; 
	this . AddFactor  = 100 / this . OverFrames;
	this . Opacity    = 0;
	this . TimerStyle = 1;
	this . TrigTrue   = true;
	this . Timer      = setInterval ( this . IntervalStr, this . Interval );		
}



function InterruptTimer ()
{
	switch ( this . TimerStyle ) 
	{
		case 1:  clearInterval   ( this . Timer );
		         
		         break;
		case 2:  clearTimeout   ( this . Timer );
	           break;
						 
		default: break;	
		
	} // end switch
	
}

function RestartTimer ()
{
	switch ( this . TimerStyle ) 
	{
		case 1:  this . Timer = setInterval ( this . IntervalStr, this . Interval );			         
		         break;
		case 2:  this . Timer = setTimeout ( this . IntervalStr, 2000 );
	           break;
						 
		default: break;	
		
	} // end switch
}
	

function ProcessImageInterval ()
{
	this . Opacity = this . Opacity + this . AddFactor;
	
	if ( this . TrigTrue && this . Opacity > 50 )
	{
		this . TrigTrue = false;
		//if ( this . Trigger != null ) ( this . Trigger ) ( this . ImagePos );
	}
	
	if ( this . Opacity > 100 )
	{
		SetLayerOpacity ( this. LayerA, 100 );
		SetLayerOpacity ( this. LayerB, 0   );
		this . TimerStyle = 0;
		clearInterval   ( this . Timer );
		
		var Temp = this . LayerA;
		this . LayerA = this . LayerB;
		this . LayerB = Temp;
		
		Temp = this . ImageA;
		this . ImageA = this . ImageB;
		this . ImageB = Temp;
		
		if ( this . Triggered ) return; 
		
		this . IntervalStr = "";
		this . IntervalStr = "ProcessDelayTimer ('" + this . SelfRef + "')"; 
		this . TimerStyle = 2;
		
		
		var OldImage = this . ImagePos;
		
		this . ImagePos = this . ImagePos + 1;
		if ( this . ImagePos >= this . Paths . length ) 
		{ 
		  this . ImagePos  = 0;
			this . FirstPass = false; 
		}
		
		this . SetImage ( this . ImagePos );
		this . Timer = setTimeout ( this . IntervalStr, this . Delay [ OldImage ] );
		if ( this . Trigger != null ) ( this . Trigger ) ( OldImage );
		return;
	}
	else
	{
		SetLayerOpacity ( this. LayerA,       this . Opacity );
		SetLayerOpacity ( this .LayerB, 100 - this . Opacity );
	}
}

function TimerExecute ( Interval )
{
	if ( Interval == 0 )
	{
		this . Execute ();
		return;
	}
  this . IntervalStr = "";
	this . IntervalStr = "ProcessStartTimer ('" + this . SelfRef + "')"; 
	this . Timer = setTimeout ( this . IntervalStr, Interval * 1000 );
	this . TimerStyle = 2;
}

function Execute ( )
{
	if ( arguments . length == 0 ) this . ImagePos = 0;
	else
	{
		this . ImagePos = arguments [ 0 ];
	}
	this . SetImage ( this . ImagePos );
	this . ChangeImages ( );
}

function ProcessStartTimer ( Name )
{
	eval ( Name + ". StartTimeOut ();" );	
}

function ProcessImageTimer ( Name )
{
	eval ( Name + ". ProcessImageInterval ();" );	
}

function ProcessDelayTimer ( Name )
{
	eval ( Name + ". ImageTimeOut ();" );	
}

function ImageTimeOut ()
{
	this . ChangeImages ( );
}

function StartTimeOut ()
{
	this . Execute ();
}



function LogPath ( X, Y, Wid, Hei, Path, Delay, Border, Flags )
{
	if ( arguments . length == 0 ) return;
	for ( var x = 0; x < arguments . length; x = x + 8 )
	{
		this . XLPos      . push (                   arguments [ x     ] );
		this . YLPos      . push (                   arguments [ x + 1 ] );
		this . Width      . push (                   arguments [ x + 2 ] );
		this . Height     . push (                   arguments [ x + 3 ] );		
		this . Paths      . push ( this . ImageDir + arguments [ x + 4 ] );
		this . Delay      . push (                   arguments [ x + 5 ] * 1000 );
		this . BorderObj  . push (                   arguments [ x + 6 ] );
		this . Flags      . push (                   arguments [ x + 7 ] );
		this . Images     . push ( null );
	}
}

function dLink( Name, JCClick, JCOver, JCOut, Cinit, Cin, Cout, underline )
{
  var Text;
	var Link;
	var L;
	var LBody = '';
	var noT = 0;
	var Add;
	
  for ( var x = 8; x < arguments . length; x = x + 2 )
	{
    Link = '';
		L    = '';	 
		LBody = '';
		Text = '';
		Add  = '';
		Add  = arguments [ x     ];
		Text = arguments [ x + 1 ];
		

    //var Link  = '\'link'+ no + '\'';
	  var L    = Name + noT;
		var Link = "'" + L + "'";
		
        LBody = LBody  + Add + '<span id=' + Link + ' onClick="'      + JCClick + '(' + noT + ');" ';
	      LBody = LBody              + ' onMouseover ="' + JCOver  + '(' + Link + ',' + Cin  + ');" ';
        LBody = LBody              + ' onMouseout  ="' + JCOut   + '(' + Link + ',' + Cout + ');" ';
	      LBody = LBody + '>' + Text + '</span>';

    document.write( LBody );

	  var Obj = new GetJCObject ( L );
	  Obj.style.color= eval ( Cinit );
	  if ( underline == "y" ) Obj.style.textDecoration="underline";
    noT += 1;
  }	
		
}

function dLinkText( Name, JCClick, JCOver, JCOut, Cinit, Cin, Cout, underline )
{
  var Text;
	var Link;
	var L;
	var LBody = '';
	var noT = 0;
	var Add;
	
  for ( var x = 8; x < arguments . length; x = x + 2 )
	{
    Link = '';
		L    = '';	 
		LBody = '';
		Text = '';
		Add  = '';
		Add  = arguments [ x     ];
		Text = arguments [ x + 1 ];
		

    //var Link  = '\'link'+ no + '\'';
	  var L    = Name + noT;
		var Link = "'" + L + "'";
		
        LBody = LBody  + Add + '<span id=' + Link + ' onClick="'      + JCClick + '(' + noT + ');" ';
	      LBody = LBody              + ' onMouseover ="' + JCOver  + '(' + Link + ',' + Cin  + ');" ';
        LBody = LBody              + ' onMouseout  ="' + JCOut   + '(' + Link + ',' + Cout + ');" ';
	      LBody = LBody + '>' + Text + '</span>';

    //document.write( LBody );
    return LBody;
	  //var Obj = new GetJCObject ( L );
	  //Obj.style.color= eval ( Cinit );
	  //if ( underline == "y" ) Obj.style.textDecoration="underline";
    noT += 1;
  }	
		
}

function dLinkLayer( Name, JCClick, JCOver, JCOut, X, Y, W, H, Color, Zorder, Visible, Opacity )
{
	var Link = "'" + Name + "'";
	var LBody = '';
	
	LBody = '<div id=' + Link + '></div>';	  
	
  document.write( LBody );
	//document.write( "<div id='TestLayer'>Hello</div>" );
	

	var ObjT = new GetFullObject ( Name ); 
	var Obj = ObjT . Obj;
	SetLayerVisibility      ( Obj, Visible );
	SetLayerPositionType    ( Obj );
	SetLayerOpacity         ( Obj, Opacity );  
	SetLayerPosition        ( Obj, X, Y );
	SetLayerWidthHeight     ( Obj, W, H );
	
	if ( Color != null )  SetLayerBackgroundColor ( Obj, Color );
  SetLayerZIndex          ( Obj, Zorder );	
	
	return Obj;
}

function GetFullObject ( name )
{
  if ( document . getElementById )
  {
  	this . Obj   = document . getElementById ( name );	  
  }
  else if (document.all)
  {
	  this . Obj   = document . all [ name ];	  
  }
  else if (document.layers)
  {
   	this . Obj   = document . layers [ name ];   	
  }
}

function SetLayerText ( Layer, Text )
{
  var FormObj          = new GetFullObject ( Layer );
	FormObj . Obj . innerHTML = "";
	FormObj . Obj . innerHTML = Text;
}

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{	
    try 
		{
      xmlhttp = new XMLHttpRequest();
    } 
		catch (e) 
		{
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function SetOpacity ( LayerObj, value )
{
  var testObj = new GetJCObject ( LayerObj );
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function GetJCObject ( name )
{
	var Obj;
  if ( document . getElementById )
  {
  	Obj   = document . getElementById ( name );
  }
  else if (document.all)
  {
	  Obj   = document . all [ name ];
  }
  else if (document.layers)
  {
   	Obj   = document . layers [ name ];
  }
	return Obj;
}





function OpacityOver ( e )
{
  var value = 3.5;
	
  this.style.opacity = value/10;
	this.style.filter = 'alpha(opacity=' + value*10 + ')';
  
}	

function RegisterEvents ( Layer )
{
  SetOpacity ( Layer   , 2.5 );
  var FormObj          = new GetFullObject ( Layer );	
	FormObj . Obj. onmouseover = OpacityOver;
	if ( FormObj . Obj .captureEvents ) FormObj . Obj . captureEvents( Event . MOUSEOVER );	
}
/*
function OpacityOut ( e )
{
  var value = 2.5;
  this.style.opacity = value/10;
	this.style.filter = 'alpha(opacity=' + value*10 + ')';
  
}	*/


