/***********************************************
* CMotion Image Gallery- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for source code
* Last updated Mar 15th, 04'. Added "End of Gallery" message.
* This copyright notice must stay intact for legal use
***********************************************/

var restarea=6 //1) width of the "neutral" area in the center of the gallery in px
var maxspeed=7 //2) top scroll speed in pixels. Script auto creates a range from 0 to top speed.
var endofgallerymsg="" //3) message to show at end of gallery. Enter "" to disable message.
var x=-1;
var y=-1;
var currentParent=null;
var currentWin=null;

function enlargeimage(path, optWidth, optHeight){ //function to enlarge image. Change as desired.
var actualWidth=typeof optWidth!="undefined" ? optWidth : "600px" //set 600px to default width
var actualHeight=typeof optHeight!="undefined" ? optHeight : "500px" //set 500px to  default height
var winattributes="width="+actualWidth+",height="+actualHeight+",resizable=yes"
window.open(path,"", winattributes)
}

////NO NEED TO EDIT BELOW THIS LINE////////////

var iedom=document.all||document.getElementById
var scrollspeed=0
var movestate=""
var motioncontainer
var actualwidth=''
var cross_scroll, ns_scroll
var loadedyes=0
var crossmain
var menuwidth
var mainobjoffset
var isShown='false';

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function creatediv(){
statusdiv=document.createElement("div")
statusdiv.setAttribute("id","statusdiv")
document.body.appendChild(statusdiv)
statusdiv=document.getElementById("statusdiv")
statusdiv.innerHTML=endofgallerymsg
}

function positiondiv(){
menuheight=parseInt(crossmain.offsetHeight)
mainobjoffsetH=getposOffset(crossmain, "top")
statusdiv.style.left=mainobjoffset+(menuwidth/2)-(statusdiv.offsetWidth/2)+"px"
statusdiv.style.top=menuheight+mainobjoffsetH+"px"
}

function showhidediv(what){
if (endofgallerymsg!="")
statusdiv.style.visibility=what
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function moveleft(){
if (loadedyes){

movestate="left"
if (iedom&&parseInt(cross_scroll.style.left)>(menuwidth-actualwidth)){
cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
lefttime=setTimeout("moveleft()",10)
}

function moveright(){
if (loadedyes){
movestate="right"
if (iedom&&parseInt(cross_scroll.style.left)<0){
cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
righttime=setTimeout("moveright()",10)
}

function moverightButton(){
	scrollspeed=5
if (loadedyes){
movestate="right"
if (iedom&&parseInt(cross_scroll.style.left)<0){
cross_scroll.style.left=parseInt(cross_scroll.style.left)+scrollspeed+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
righttime=setTimeout("moveright()",10)
}

function moveleftButton(){
	scrollspeed=5
if (loadedyes){
movestate="left"
if (iedom&&parseInt(cross_scroll.style.left)<(menuwidth-actualwidth)){
cross_scroll.style.left=parseInt(cross_scroll.style.left)-scrollspeed+"px"
showhidediv("hidden")
}
else
showhidediv("visible")
}
lefttime=setTimeout("moveleft()",10)

}

function motionengine(e){
var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
var dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop;
var curposy=window.event? event.clientX : e.clientX? e.clientX: ""
curposy-=mainobjoffset-dsocx
var leftbound=(menuwidth-restarea)/2
var rightbound=(menuwidth+restarea)/2
if (curposy>rightbound){
scrollspeed=(curposy-rightbound)/((menuwidth-restarea)/2) * maxspeed
if (window.righttime) clearTimeout(righttime)
if (movestate!="left") moveleft()
}
else if (curposy<leftbound){
scrollspeed=(leftbound-curposy)/((menuwidth-restarea)/2) * maxspeed
if (window.lefttime) clearTimeout(lefttime)
if (movestate!="right") moveright()
}
else
scrollspeed=0
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function stopmotion(e){
if ((window.event&&!crossmain.contains(event.toElement)) || (e && e.currentTarget && e.currentTarget!= e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))){
if (window.lefttime) clearTimeout(lefttime)
if (window.righttime) clearTimeout(righttime)
movestate=""
}
}

function stopMotionButton() {
	if (window.lefttime) clearTimeout(lefttime)
	if (window.righttime) clearTimeout(righttime)
movestate=""
}

function showSlideWindow (parentId, windId) {
	if ((isShown == 'true') && (currentWin != null) && (currentParent != null)){
		closeSlideWindow(currentParent, currentWin)
	}
	if (isShown =='false') {
	var xoffSet=x-8;
	var yoffSet=y-8;
	parentWin = document.getElementById(parentId);
	popupWin = document.getElementById(windId);
	parentWin.style.left = (document.documentElement.scrollLeft+xoffSet)+'px';
    parentWin.style.top  = (document.documentElement.scrollTop +yoffSet)+'px';
	parentWin.style.visibility="visible"
	parentWin.style.display= "block";
  	popupWin.style.visibility = "visible";
	isShown='true';
	currentParent = parentId;
	currentWin = windId;
	}
 }
 
function closeSlideWindow (parentId, windId) {
if (isShown == 'true') {
	popupWin = document.getElementById(windId);
	parentWin = document.getElementById(parentId);
	parentWin.style.visibility="hidden";
	parentWin.style.display="none";
  	popupWin.style.visibility = 'hidden';
	isShown='false';
	}
 }
 
 function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer" || b=="Opera") this.b = "ie" 
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}

// automatically create the "is" object
var is = new BrowserCheck()

	var currentX=-1;
	var currentY=-1;

	function init() {
		crossmain=document.getElementById? document.getElementById("motioncontainer") : document.all.motioncontainer
		menuwidth=parseInt(crossmain.style.width)
		mainobjoffset=getposOffset(crossmain, "left")
		cross_scroll=document.getElementById? document.getElementById("motiongallery") : document.all.motiongallery
		actualwidth=document.all? cross_scroll.offsetWidth : document.getElementById("trueContainer").offsetWidth
		loadedyes=1;
		document.onmousedown = mouseDown
		document.onmousemove = mouseMove
		document.onmouseup = mouseUp
		if (is.ns4) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
	}
	function alertCoord(e) {
	  if( !e ) {
		if( window.event ) {
		  //Internet Explorer
		  e = window.event;
		} else {
		  //total failure, we have no way of referencing the event
		  return;
		}
	  }
	  if( typeof( e.pageX ) == 'number' ) {
		//most browsers
		var xcoord = e.pageX;
		var ycoord = e.pageY;
	  } else if( typeof( e.clientX ) == 'number' ) {
		//Internet Explorer and older browsers
		//other browsers provide this, but follow the pageX/Y branch
		var xcoord = e.clientX;
		var ycoord = e.clientY;
		var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
		 ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
		 ( navigator.vendor == 'KDE' )
		if( !badOldBrowser ) {
		  if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//IE 4, 5 & 6 (in non-standards compliant mode)
			xcoord += document.body.scrollLeft;
			ycoord += document.body.scrollTop;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE 6 (in standards compliant mode)
			xcoord += document.documentElement.scrollLeft;
			ycoord += document.documentElement.scrollTop;
		  }
		}
	  } else {
		//total failure, we have no way of obtaining the mouse coordinates
		return;
	  }
	  x=xcoord;
	  y=ycoord;
	}	
	function mouseDown(e) {
		if ((is.ns && e.which!=1) || (is.ie && event.button!=1)) return true
		 x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
		 y = (is.ns)? e.pageY : event.y+document.body.scrollTop
		currentX= x;
		currentY= y;
		alertCoord(e);
		return true
	}
	function mouseMove(e) {
		 x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
		 y = (is.ns)? e.pageY : event.y+document.body.scrollTop
		 alertCoord(e);
		return true
	}
	function mouseUp(e) {
		 x = (is.ns)? e.pageX : event.x+document.body.scrollLeft
		 y = (is.ns)? e.pageY : event.y+document.body.scrollTop
		alertCoord(e);
		return true
	}
	

	function setImageArray(id) {
		arrayName = eval("photoLinkArray"+id);
		contents ="";
		for (var x = 0; x < arrayName.length; x++) {
   				contents = contents + arrayName[x];
  		}
		theBrowser = returnObjById("trueContainer");
		theBrowser.innerHTML=contents;
	}
	
	function showBrowser(id) {
		  setImageArray(id);	 
		  showSlideWindow('popup', 'motioncontainer');
		  
	} 
	
	function returnObjById( id )
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}


