//------------Start of  Multi-Browser DOM operator--------------
var isAll = 0;
var isLayers = 0;
var isID = 0;

//Browser Detect
if (document.getElementById) {isID = 1;} //Both ie5+ , netscape6 have this property - newer browsers
if (document.all) {isAll = 1; }		       //Only ie has this property - If isID=0 then this will identify old IE4 browsers
if (document.layers) {isLayers = 1; } //Only netscape 4 has this property 


/*
alert('isID =' + isID);
alert('isLayers =' + isLayers);
alert('isAll =' + isAll);
*/

// You must check for document.getElementById first because newer versions of IE have both document.getElementById and document.all
// But IE 4 < 5 only has document.all

//objectID is the id of the Div/Layer.
//image is the id of the imange
function findDOM(objectID,withStyle,image) 
{//0
	if (image != null) {//3  If image passed - Returns an image within a Div. (i.e. the full path), use to access the properties of image's within a Div, 
		if (isID) {return (document.getElementById(image)) ; } //check for ns6,ie5+
			else{//2
				if (isAll) {return (document.all(objectID).document.images(image)); } //pick up older ie note:this is because they don not support getElementById
				else{//1
					if (isLayers) {return (document.layers[objectID].document.images[image]); }
					};//1
				}//2								
		}//3		
		
		else{//7 Returns the Style property of a Div. (i.e. the full path), use to access a Div's Style property properties
			 	
			if (withStyle == 1){//6
					if (isID) { return (document.getElementById(objectID).style) ; }
					else{ //5
						if (isAll) { return (document.all[objectID].style); }
						else{//4
							if (isLayers) { return (document.layers[objectID]); }
							};//4
						}//5
					}//6
			 
			  else{//10 Returns the Div.  (i.e. the full path), use to access Div properties
			  		
					if (isID) { return (document.getElementById(objectID)) ; }
					else{//9
						if (isAll) { return (document.all[objectID]);}
						else{//8
							if (isLayers) { return (document.layers[objectID]);}
							};//8
						}//9
				}//10
			}//7
}//0
//------------End of  Multi-Browser DOM operator------------------------



//-----------Start of get page name function----------------------------
//takes a full url includin the "http://" .e.g. http://lalala/ 
function getPageName(fullurl){
	//Find page name
	if (fullurl != 'current'){
		var the_url = fullurl;
	}else{
		var the_url = document.location.href;
	}
	
	var first_split = the_url.split("//"); //splits the string and puts it into an array
	var after_domain = first_split[1]; // store all after "//"
	
	//alert (after_domain);
	var second_split = after_domain.split("/"); // split at the all "/" in the URL 	
	//get the last part of the split and forget about the middle folder names
	var full_page_name = second_split[second_split.length-1]; // -1 because length starts from 1 but arrays start from 0
	//alert(full_page_name);
	var full_page_name_split = full_page_name.split(".");
	//alert(full_page_name_split[0]);
	
	var only_page_name = full_page_name_split[0];
	return only_page_name;
}
//-----------End of get page name function----------------------------




//------------Start of Image Functions----------------------------------
function SwapImage(id,name) {
	document.images[id].src = eval(name+".src");
}

function SwapImageInDiv(div,ImageId,newImage) {

	findDOM(div,0,ImageId).src = eval(newImage+'.src');

}
//------------End of Image Functions-------------------------------------

// Fix Netscape window resize
function FixNSResize() {
  if (isLayers == 1) { document.location.reload(true);}
}

//Function that can write to a layer/div - Multibrowser. - Not Opera yet
function writetoLyr(name, message) {
    if (document.layers) {							//NS4
        document.layers[name].document.close();
        document.layers[name].document.write(message);
        document.layers[name].document.close();
    } else {
        if (document.all) {  						//IE4 > IE5
			//eval("document.all." + name + ".innerHTML=\"" + message + " \" "); original line
			//Swap the innerHTML of the Layer for the string called message
			eval("document.all." + name + ".innerHTML =  message");			
			
        } else {									//IE 5>
            document.getElementById(name).innerHTML = message;
        }
    }
}


//------------Start of slide Function-------------------------------------

called = false; //HAVE WE Performed calculations
xhigh = false;	//x-axis movement is higher than y-axis movement
yhigh = false;	//y-axis movement is higher than x-axis movement


xright = false;
yup = false;	

var ypos; //original y-axis position
var yinc; //Calculated size of y increments
var ydist;
var xpos; //original x-axis position
var xinc; //Calculated size of x increments
var xdist;

var moved = 0; //pixels moved

moveEndY = false;
moveEndX = false;

//		alert('totalsteps =' +steps);
//		alert('yinc=' +yinc);


//Move the layer by adding small increments to the top or left position values of the Layer.
function Slide(layer,distancex,inc,pause,distancey,nextfunc){
//layer 	= Layer name in quotes
//distancex	= Distance to move along the x-axis
//inc		= Size of increments on the x-axis
//pause 	= Length of time to pause between each increment
//distancey	= Distance to move along the y-axis

//I have made this function to save repeating the same line.
function iterate(){
	setTimeout('Slide(\'' +layer+ '\',' +distancex+ ','+inc+ ',' +pause+ ',' +distancey+ ',\'' +nextfunc+ '\')', pause );
}
		// if all movements finished
		if(((distancex == 0) && (distancey ==0)) || (moveEndX || moveEndY)){
			//alert(nextfunc);
			eval(nextfunc);
		}

		//Make sure that the incremental value is positive
		inc = Math.abs(inc);
		
		//Set some Style Sheet properties, This is needed for  IE5, NS6.
		//Find OffsetLeft and Top and use them to populate the style object in IE5 and NS6 because they report style top and left as nothing or unpopulated.				
		if (document.getElementById) {
							findDOM(layer,1,null).left = findDOM(layer,0,null).offsetLeft;
							findDOM(layer,1,null).top = findDOM(layer,0,null).offsetTop;
		}
	
		//Use the varaible myStyleSheet as an easy reference to the style sheet object 
		myStyleSheet 	= findDOM(layer,1,null);							
		
		//get current position
		this.x 		= parseInt(myStyleSheet.left,10); //use parseInt to remove 'px' from the pixel value
		this.y 		= parseInt(myStyleSheet.top,10);
		
//---Start X-axis movement only--------------
	if (((distancex != 0) && (distancey ==0)) && (!xhigh && !yhigh)){
			//If the positive value of the distance to move is less than the incremental value(distance to move per shift), then the movement will be too great
			//so the inc is reduced to the distance to move
			if (Math.abs(distancex) < inc){
						inc = Math.abs(distancex);
			}	
			
			//if distance is greater than zero
			if (distancex > 0){
						//Move layer by inc value .ie. to the right
						myStyleSheet.left = this.x + inc;		
						//reduce dictance to move by distance just moved
						//i.e. if distance is a positive number we minus the inc value until distance = 0, when the function will stop. 
						distancex -=  inc;
						//alert(distance);alert(inc);
						//repeat function with the smaller distance
						iterate();
						
			}else{					
					//if distance is less than zero ,move left
					if (distancex < 0){
								//Move layer by -inc value .ie. to the left because distance is a minus value
								myStyleSheet.left = this.x - inc;
								//reduce distance to move by distance just moved
								//i.e if distance is a negative number we add the inc value, until distance = 0, when the function will stop.
								distancex += inc;
								//alert(distance);alert(inc);
								//repeat function with the smaller distance
								iterate();
					}
			}//end else
	} 
//---End X-axis movement only--------------
	
//---Start Y-axis movement only--------------
	if (((distancex == 0) && (distancey !=0)) && (!xhigh && !yhigh)){
			if (Math.abs(distancey) < inc){
						inc = Math.abs(distancey);
			}
	
			if (parseInt(distancey,10) > 0){
						myStyleSheet.top = this.y + inc;		
						distancey -=  inc;
						iterate();
						
			}else{					
					if (parseInt(distancey,10) < 0){
								myStyleSheet.top = this.y - inc;
								distancey += inc;
								iterate();
					}
			}//end else
			
	}
//---End Y-axis movement only--------------	
					
		
		
//movex() and movey() are used to move the layer along the secondary axis for a X-axis and Y-axis movement
function movex(){
	if (xright){		//if y-axis movement is positive	
			//Add up increments because they could be less than 1px which would produce no movement
			//If you don't add them up and they are all under 1px then no movement will be seen.
			moved += xinc;								
			myStyleSheet.left = xpos + moved;//Round up and Add total movements to original position														
	}else{
			if (!xright){														
				moved += xinc;			
				//alert(moved);											
				myStyleSheet.left = xpos - moved;								
			}
	}//end else
}

function movey(){
	if (!yup){	//if x-axis movement is positive				
				moved += yinc;
				myStyleSheet.top = ypos + moved;							
		}else{
				if (yup){	
					moved += yinc;
					myStyleSheet.top = ypos - moved;									
				}
	}//end else
}

//---Start X-axis and Y-axis movement--------------
	if (((distancex != 0) && (distancey !=0)) || (xhigh || yhigh)){	
		//----Start One off calculations-----------
			//if we have not calculated the 'smaller distance to move' increments
			if (!called){
				called = true; 			
				(//We must see which axis has the greater movement, and use that axis to calculate movements on the other axis
				(Math.abs(distancex) >= Math.abs(distancey)) ? xhigh=true : yhigh=true);
				
				((distancex>0) ? xright=true : xright=false); //check for x movement direction
				((distancey>0) ? yup=false : yup=true); //check for y movement direction
				
				//Store the original x and y move distances
				xdist = distancex;
				ydist = distancey;
				
								
				ypos = this.y;				//store the original y-axis position in global variable, so it does not change on the next iteration of the function
				steps	= Math.abs(distancex)/inc; 	
				yinc	= Math.abs(distancey)/steps;	//calculate the required y increments
				//alert('totalsteps =' +steps);alert('yinc=' +yinc);
				
				xpos = this.x;				//store the original y-axis position in global variable, so it does not change on the next iteration of the function
				steps	= Math.abs(distancey)/inc; 
				xinc	= Math.abs(distancex)/steps;	//calculate the required x increments
					
			}					
		//----End One off calculations-----------					
					
					
			if (xhigh){	//if xhigh we move using the x-axis movement to guide the y-axis movement
					if (Math.abs(distancex) < inc){	 
								inc = Math.abs(distancex);	//if the inc is too big for the movement left, reduce it to the size of the distance left to move
					}
					if (Math.abs(distancey) < yinc){
								yinc = Math.abs(distancey);	//if the calculated value yinc is too big for the movement left, reduce it to the size of the distance left to move
					}				
				//if x-axis distance is greater than zero 
					if (distancex > 0){
							movey();
							//Move layer by inc value .ie. to the right
							myStyleSheet.left = this.x + inc;		
							//reduce dictance to move by distance just moved
							//i.e. if distance is a positive number we minus the inc value until distance = 0, when the function will stop. 
							distancex -=  inc;			
							//alert(distance);alert(inc);
							//repeat function with the smaller distance
							iterate();						
					}else{					
						    //if distance is less than zero
							if (distancex < 0){
									movey();
									//Move layer by -inc value .ie. to the left because distance is a minus value
									myStyleSheet.left = this.x - inc;
									//reduce distance to move by distance just moved
									//i.e if distance is a negative number we add the inc value, until distance = 0, when the function will stop.
									distancex += inc;									
									//alert(distance);alert(inc);
									//repeat function with the smaller distance
									iterate();
							}
					}//end else		
					
				}
				
				if (yhigh){	//if yhigh we move using the y-axis movement to guide the x-axis movement
					if (Math.abs(distancey) < inc){
								inc = Math.abs(distancey);
					}
					if (Math.abs(distancex) < xinc){
								xinc = Math.abs(distancex);
					}	
				//if x-axis distance is greater than zero
						if (distancey > 0){//Move layer by inc value .ie. downwards						
							movex();
							myStyleSheet.top = this.y + inc;		
							distancey -=  inc;			
							//repeat function with the smaller distance
							iterate();						
						}else{
								if (distancey < 0){//Move layer by inc value .ie. upwards					
									movex();
									myStyleSheet.top = this.y - inc;		
									distancey +=  inc;			
									//repeat function with the smaller distance
									iterate();						
								}
						}//end else
				}
		//show cords for debug
		//window.status=('myStyleSheet.left= ' +myStyleSheet.left+ 'myStyleSheet.top= ' +myStyleSheet.top);
		
		//IF layers position is the same as the original position plus the required movement then movement on that axis is over and moveEndX set to true
		((parseInt(myStyleSheet.left,10) == (xpos+xdist)) ? moveEndX=true : moveEndX=false);	
		((parseInt(myStyleSheet.top,10)  == (ypos+ydist)) ? moveEndY=true : moveEndY=false);
		// call for testing, x axis movement will not fin unless slide cend checking in place Slide('MyLayer',-99,11,10,-1100)
		//if the main axis movement finishes before the second axis then some movement on the second axis will be lost so we can add the extra movment to the second axis
			if ((moveEndX || moveEndY) && (!moveEndX || !moveEndY)){
				myStyleSheet.left = xpos+xdist;
				myStyleSheet.top = ypos+ydist;
				
			}
	
	}//---End X-axis and Y-axis movement--------------	


//show cords for debug
//window.status=('myStyleSheet.left= ' +myStyleSheet.left+ 'myStyleSheet.top= ' +myStyleSheet.top);

}//------------End of slide Function----------------------------------
	




//Page footer same on each page - Not in use because the layers cause problems. Netscape Won't Write easily to the div.
footer = '<p align="center"><br>'
		+'<IMG name="1Title" width="62" height="22" src="art/images/gif1title.gif" alt="Entertainment Agency ,  Dawn Judd Entertainment ,entertainment agency"><IMG name="2Title" width="54" height="22" src="art/images/gif2title.gif" alt="Entertainment Agency ,  Dawn Judd Entertainment ,entertainment agency">'
		+'<IMG name="3Title" width="134" height="22" src="art/images/gif3title.gif" alt="Entertainment Agency ,  Dawn Judd Entertainment ,entertainment agency">'
		+'<BR><A href="entertainmentagent.htm"><IMG src="bluelinenew.gif" alt="entertainment agency / agent, entertainment for pubs home bussiness, bands shows fun comedy, discos and karaoke" height="20" width="580" border="0"></A>'
		+'<BR><BR><address id="address"><a href="http://www.broadshot.com/" target="_blank">Web Site Creator</a></address><BR><BR>';

function write_footer(){document.write(footer);}
