// Button Rollovers

function goLite(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#a1c27e";
   window.document.forms[FRM].elements[BTN].style.borderColor = "#a1c27e";
}

function goDim(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#ffffff";
   window.document.forms[FRM].elements[BTN].style.borderColor = "#d6d6d6";
}

// NAV ROLLOVERS
	function r_closelast(){
		document.lastM.style.visibility='hidden' ;
		document.lastMB.style.visibility='hidden' ;
		document.lastMH.style.visibility='hidden' ;}
		
	function r_openmenu(name){
		if(document.lastM){
			if(document.lastM!=document.getElementById(name)) document.getElementById(name+"Highlight").style.top=0 ;
			r_closelast() ;}
		menu=document.getElementById(name) ;
		menu.style.visibility='visible' ;
		var divs=menu.childNodes ;
		var icntr=0 ;
		for(i=0;i<divs.length;i++){
			if(divs[i].className=="menuI"){
				divs[i].style.top = icntr*24 ;
				icntr++ ;}}
		menu.style.height=icntr*24 ;
		document.getElementById(name+"Back").style.visibility='visible' ;
		document.getElementById(name+"Highlight").style.visibility='visible' ;
		document.lastM=menu ;
		document.lastMB=document.getElementById(name+"Back") ;
		document.lastMH=document.getElementById(name+"Highlight") ;}
		
	function r_menuitem(index){
		document.lastM.style.visibility='visible' ;
		document.lastMB.style.visibility='visible' ;
		var divs=document.lastM.childNodes ;
		var icntr=0 ;
		for(i=0;i<divs.length;i++){
			if(divs[i].className=="menuI"){
				icntr++ ;
				if(index==icntr){
					//Found clicked item...
					document.lastMH.style.top=parseInt(divs[i].style.top) ;}}}}
					
	// function r_highlight(name, updown)
		// {document.getElementById(name).src="images/top-"+updown+".gif" ;}
		
	function r_highlight(name, updown){
		if (updown == "up") document.getElementById(name).src=document.getElementById(name).src.replace("down","up");
		else document.getElementById(name).src=document.getElementById(name).src.replace("up","down");}

function open_window(url)
		{			
		var logpage = '';
		eval("logpage = window.open(url, 'Display1', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0, width=658, height=410, left=300,top=200');");	  
		}
function open_window2(url)
		{			
		var logpage = '';
		eval("logpage = window.open(url, 'Display1', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0, width=658, height=410, left=300,top=200');");	  
		}
		
		
		
	function clickButton(btn) {
		if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
			document.getElementById(btn).click();
			return false;
		} 
    	else return true;
	}

	function viewPhoto(id, width, height, title)
   {
      if (id != "0") {
      view = window.open("viewer.htm?id="+id, id, "width="+width+",height="+height+",scrollbars=no,toolbar=no,status=no,resizable=no,menubar=no,location=no");
      view.focus();
      }
   }
 
function showPhoto(obj_photo,id,width,height,text) {
	while(obj_photo.indexOf(":") > -1) {
		obj_photo = obj_photo.replace(':','_');
	}
	document.getElementById(obj_photo).src = "../photos/display.aspx?"+id+"_254_254.jpg";
	document.getElementById(obj_photo).alt = text;
	document.getElementById(obj_photo).parentNode.href = "javascript:viewPhoto(" + id + "," + width + "," + height + ",'" + text + "');";
}

function showRelatedPhoto(obj_photo,id,width,height,text) {
	while(obj_photo.indexOf(":") > -1) {
		obj_photo = obj_photo.replace(':','_');
	}
	document.getElementById(obj_photo).src = "../photos/"+id+"_138_0.jpg";
	document.getElementById(obj_photo).alt = text;
	document.getElementById(obj_photo).parentNode.href = "javascript:viewPhoto(" + id + "," + width + "," + height + ",'" + text + "');";
}

   function setCost() {		
	var id = setCost.arguments[1].replace(":", "_").replace(":", "_").replace(":", "_");
		document.getElementById(id).innerHTML =  setCost.arguments[setCost.arguments[0].selectedIndex + 2];
		   
   }
   
   function jumpGroup(obj) {
	 document.location.href = "catalog.aspx?group="+obj.options[obj.selectedIndex].value;
   }




function showPreOrder() {
	alert('This item is a pre-order. Items offered for pre-order are in high demand, but by reserving yours you are guaranteed to be the first to own it. Your credit card will not be charged until it ships. The delivery date for pre-orders varies and is only an estimate. Please check the item\'s description for more information.');
}



function showSwatchTitle(title, space) {
	if (title == "") {
		document.getElementById("swatch_title").innerHTML = "&nbsp;";
	}
	else {
		space = 44 * space;
		image = "<img src='../images/blank.gif' height='2' width='"+space+"'>";
		document.getElementById("swatch_title").innerHTML = "&nbsp;"+image+"<span class='alert'>"+title+"</span>";
	}
}

function showPhotoTitle(title) {
	if (title == "") {
		document.getElementById("photo_title").innerHTML = "&nbsp;";
	}
	else {
		document.getElementById("photo_title").innerHTML = "&nbsp;<span class='alert'>"+title+"</span>";
	}
}
function emailPageLink() {
	urlAddress = window.location.href;
	pageName = document.title;
	
	efpopup = window.open("http://linux.virtualatlantic.com/common/pk_emailfriend.php?url="+urlAddress+"&title="+pageName, "efpopup", "width=400,height=300,scrollbars=no,menubar=no");
}




   function openWindow(url,win)
   {
      view = window.open(url, "", win);
      view.focus();
   }
   
   function hov(loc,cls)
{
   if(loc.className)
      loc.className=cls;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function displayImage(file) {

	document.getElementById("header").src = '../images/gt3_tour/images/' + file + '.gif';
	
	document.getElementById("flash_file").innerHTML = (VAI_FL_RunContent('codebase','https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','scale','exactfit','width','563','height','400','src','../images/gt3_tour/images/' + file,'quality','high','pluginspage','https://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','../images/gt3_tour/images/' + file));	


}

function openPrintable() {
		popup = window.open("printable.htm", "popup", "width=680,height=200,scrollbars=yes,menubar=yes,resize=yes");
 
	}

function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}

function toggle_visibility1(index) {
var e = document.getElementById(index);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}

// Scroll Bar
// basic methods.
ypSimpleScroll.prototype.scrollNorth = function() { this.startScroll(90) }
ypSimpleScroll.prototype.scrollSouth = function() { this.startScroll(270)  }
ypSimpleScroll.prototype.scrollWest  = function() { this.startScroll(180) }
ypSimpleScroll.prototype.scrollEast  = function() { this.startScroll(0)   }


// start scrolling in an arbitrary direction, with an optional arbitrary speed.
// if no speed is provided, the default speed from the constructor parameter is used.
ypSimpleScroll.prototype.startScroll = function(deg, speed) {
  if (this.loaded)
  {
    if (this.aniTimer) window.clearTimeout(this.aniTimer)
    this.overrideScrollAngle(deg)

    this.speed    = speed ? speed : this.origSpeed
    this.lastTime = (new Date()).getTime() - this.y.minRes
    this.aniTimer = window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
  }
}

// kills pending calls to .scroll(), resets speed
ypSimpleScroll.prototype.endScroll = function() {
  if (this.loaded)
  {
    window.clearTimeout(this.aniTimer)
    this.aniTimer = 0;
    this.speed = this.origSpeed
  }
}

// override the current angle from startScroll() with a new angle
// this method should not be used with scrollTo() because it will
// override the angle created by the first two params to scrollTo().
ypSimpleScroll.prototype.overrideScrollAngle = function(deg) {
  if (this.loaded)
  {
    deg = deg % 360
    if (deg % 90 == 0) {
      var cos = deg == 0  ? 1 : deg == 180 ? -1 : 0
      var sin = deg == 90 ? -1 : deg == 270 ? 1 : 0
    } else {
      var angle = deg * Math.PI / 180
      var cos   = Math.cos(angle)
      var sin   = Math.sin(angle)
      sin = -sin
    }
    this.fx = cos / (Math.abs(cos) + Math.abs(sin))
    this.fy = sin / (Math.abs(cos) + Math.abs(sin))
    this.stopH = deg == 90 || deg == 270 ? this.scrollLeft : deg < 90 || deg > 270 ? this.scrollW : 0
    this.stopV = deg == 0 || deg == 180 ? this.scrollTop : deg < 180 ? 0 : this.scrollH
  }
}

// override the speed for the current scroll.
// should not be used with scrollTo, unless you want to 
// override the speed computed from the aniLen param of scrollTo()
ypSimpleScroll.prototype.overrideScrollSpeed = function(speed) {
  if (this.loaded) this.speed = speed
}

// scroll to an arbitrary position in two dimensions over in
// an arbitrary lenth of time.
ypSimpleScroll.prototype.scrollTo = function(stopH, stopV, aniLen) {
  if (this.loaded)
  {
    if (stopH != this.scrollLeft || stopV != this.scrollTop) {
      if (this.aniTimer) window.clearTimeout(this.aniTimer)
      this.lastTime = (new Date()).getTime()
      var dx = Math.abs(stopH - this.scrollLeft)
      var dy = Math.abs(stopV - this.scrollTop)
      var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))
      this.fx = (stopH - this.scrollLeft) / (dx + dy)
      this.fy = (stopV - this.scrollTop) / (dx + dy)
      this.stopH = stopH
      this.stopV = stopV
      this.speed = d / aniLen * 1000
      window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
    }
  }
}

// jump to an arbitrary position in two dimensions.
ypSimpleScroll.prototype.jumpTo = function(nx, ny) { 
  if (this.loaded)
  {
    nx = Math.min(Math.max(nx, 0), this.scrollW)
    ny = Math.min(Math.max(ny, 0), this.scrollH)
    this.scrollLeft = nx
    this.scrollTop = ny
    if (this.y.ns4)this.content.moveTo(-nx, -ny)
    else {
      this.content.style.left = -nx + "px"
      this.content.style.top = -ny + "px"
    }
  }
}



// =========================================================================
// =============================== private =================================
// =========================================================================

ypSimpleScroll.minRes = 10
ypSimpleScroll.ie  = document.all ? 1 : 0
ypSimpleScroll.ns4 = document.layers ? 1 : 0
ypSimpleScroll.dom = document.getElementById ? 1 : 0
ypSimpleScroll.mac = navigator.platform == "MacPPC"
ypSimpleScroll.mo5 = document.getElementById && !document.all ? 1 : 0

// recursively calls itself to animate
ypSimpleScroll.prototype.scroll = function() {
  this.aniTimer = window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
  var nt = (new Date()).getTime()
  var d = Math.round((nt - this.lastTime) / 1000 * this.speed)
  if (d > 0)
  {
    var nx = d * this.fx + this.scrollLeft
    var ny = d * this.fy + this.scrollTop

    var xOut = (nx >= this.scrollLeft && nx >= this.stopH) || (nx <= this.scrollLeft && nx <= this.stopH)
    var yOut = (ny >= this.scrollTop && ny >= this.stopV)  || (ny <= this.scrollTop && ny <= this.stopV)
    //window.status = nx + " " + this.fx + " " + this.scrollLeft + " " + this.stopH + " | " + ny + " " + this.fy + " " + this.scrollTop + " " + this.stopV + " : " + d
    if (nt - this.lastTime != 0 &&
      ((this.fx == 0 && this.fy == 0) ||
       (this.fy == 0 && xOut) ||
       (this.fx == 0 && yOut) ||
       (this.fx != 0 && this.fy != 0 && xOut && yOut)))
    {
      this.jumpTo(this.stopH, this.stopV)
      this.endScroll()
    }
    else {
      this.jumpTo(nx, ny)
      this.lastTime = nt
    }
  }
}

// constructor
function ypSimpleScroll(id, left, top, width, height, speed, contentWidth, initLeft, initTop)
{
  var y = this.y = ypSimpleScroll
  if (!initLeft)     initLeft     = 0
  if (!initTop)      initTop      = 0
  if (!contentWidth) contentWidth = width

  // fix for netscape4 first-page bug.
  if (document.layers && !y.ns4) history.go(0)

  if (y.ie || y.ns4 || y.dom) {
    this.loaded    = false
    this.id      = id
    this.origSpeed  = speed
    this.aniTimer  = false
    this.op      = ""
    this.lastTime  = 0
    this.clipH    = height
    this.clipW    = width
    this.scrollTop  = initTop
    this.scrollLeft  = initLeft

    // global reference to this object
    this.gRef = "ypSimpleScroll_"+id
    eval(this.gRef+"=this")

    var d = document
    d.write('<style type="text/css">')
    d.write('#' + this.id + 'Container { left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; clip:rect(0 ' + width + ' ' + height + ' 0); overflow:hidden; }')
    d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; }')
    d.write('#' + this.id + 'Content { left:' + (-initLeft) + 'px; top:' + (-initTop) + 'px; width:' + contentWidth + 'px; }')
    d.write('</style>')
  }
}

// once the nceesary objects are present in the DOM, this gathers some info about them.
ypSimpleScroll.prototype.load = function() {
  var d, lyrId1, lyrId2

  d = document
  lyrId1 = this.id + "Container"
  lyrId2 = this.id + "Content"

  this.container  = this.y.dom ? d.getElementById(lyrId1) : this.y.ie ? d.all[lyrId1] : d.layers[lyrId1]
  this.content  = obj2 = this.y.ns4 ? this.container.layers[lyrId2] : this.y.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
  this.docH    = Math.max(this.y.ns4 ? this.content.document.height : this.content.offsetHeight, this.clipH)
  this.docW    = Math.max(this.y.ns4 ? this.content.document.width  : this.content.offsetWidth,  this.clipW)
  this.scrollH  = this.docH - this.clipH
  this.scrollW  = this.docW - this.clipW
  this.loaded    = true
  this.scrollLeft = Math.max(Math.min(this.scrollLeft, this.scrollW),0)
  this.scrollTop  = Math.max(Math.min(this.scrollTop, this.scrollH),0)
  this.jumpTo(this.scrollLeft, this.scrollTop)
}

	





