
//slideshow functions
var SS = {
	skip: 15,
	defaultSkip: 15,
	numSlides: 0,
	currSlide: 0,
	nextSlide: 0,
	currDiv: 'div0',
	nextDiv: 'div0',
	hiderTimer: 0,
	fadeIn: '',
	init: function() {
	 this.numSlides=imgA.length-1;
	 var startSlide=Math.floor(Math.random()*(this.numSlides+1));
	 this.currDiv = 'div'+startSlide;
	 this.nextDiv = 'div'+startSlide;
	 this.currSlide = startSlide;
	 for (i=0; i<=this.numSlides; i++) {
		var newEl = document.createElement("div");
		newEl.id= 'div'+i;
		newEl.className = (i==startSlide)?'show':'noshow';
		if (imgA[i][0]=='img') {
			newEl.style.backgroundImage = 'url('+imgA[i][1]+')';
			var newDiv = document.createElement("div");
			newDiv.style.padding = imgA[i][4]+"px 10px 10px 10px";
//			newDiv.style.width = "612px";
			newDiv.style.cursor = "pointer";
			newDiv.onclick= function() { SS.go(this); };
			//newDiv.setAttribute("onclick", "SS.link('"+i+"');");
			newDiv.style.height = 670-imgA[i][4]+"px";
			if (imgA[i][7] != '') {
				newDiv.style.textAlign = imgA[i][3];
				newDiv.style.fontSize = imgA[i][5]+"px";
				newDiv.style.color = imgA[i][6];
				newDiv.innerHTML = imgA[i][7];
			}
			newEl.appendChild(newDiv);
		}
		dojo.byId('mainbox').appendChild(newEl);
		var newO = (i==startSlide)?1:0;
		dojo.style(dojo.byId('div'+i),"opacity",newO);
		dojo.style(dojo.byId('div'+i),"zIndex",newO);

		var newSts = document.createElement("img");
		newSts.id="stsimg-"+i;
		if (i==startSlide) {
			newSts.src = "/images/pageActive.gif";
		} else {
			newSts.src = "/images/pageInactive.gif";
		}			
		newSts.alt="Slide #"+(i+1);
		newSts.onclick= function() { SS.slide(this); };		
		dojo.byId('status-img').appendChild(newSts);
	 }
	},
	go: function(e) {
		var str = e.parentNode.id
		str = parseFloat(str.substring(3));
		this.link(str);
	},
	slide: function(e) {
		var str = e.id
		str = parseFloat(str.substring(7));
		this.showNext(str);
	},
	showNext: function(id, dly) {
		this.skip -=1;
		if (typeof id == 'undefined' ) {
			if (this.skip > 0) return;
			this.nextSlide = (this.currSlide>=this.numSlides)?0:this.currSlide+1;
			this.skip = this.defaultSkip;
		} else {
			if (typeof dly == 'undefined' ) dly = 500;
			this.nextSlide = id;
			this.skip=15;
			dojo.fadeOut({node: this.nextDiv, duration: dly}).play(0);
		}
		if (typeof dly == 'undefined' ) dly = 1000;
		this.nextDiv = "div"+this.nextSlide;
		this.currDiv = "div"+this.currSlide;
		dojo.style(dojo.byId(this.nextDiv),"display","block");
 	    this.fadeIn = dojo.fadeIn({node: this.nextDiv, duration: dly});		
		this.hiderTimer = setTimeout("SS.hider('"+this.currDiv+"')",dly);
	    dojo.style(dojo.byId(this.nextDiv),'zIndex',1)
	    dojo.style(dojo.byId(this.currDiv),'zIndex',0)
		this.fadeIn.play();
		dojo.byId('stsimg-'+this.currSlide).src = "/images/pageInactive.gif";
		dojo.byId('stsimg-'+this.nextSlide).src = "/images/pageActive.gif";
		this.currSlide=this.nextSlide;
	},
	link: function(id) {
		if (typeof id == 'undefined') return;
		window.location = imgA[id][2];
	},
	hider: function(e) {
		dojo.style(dojo.byId(e),"display","none");
		dojo.style(dojo.byId(e),"opacity",0);
	}
}

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_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

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 disableRightClick(e) {
  var message = "� 2006 Ruby Livingdesign";
  if(!document.rightClickDisabled) // initialize
  {
    if(document.layers) 
    {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all))
  {
    if (e.which==2||e.which==3)
    {
      //alert(message);
      return false;
    }
  }
  else
  {
    //alert(message);
    return false;
  }
}
//disableRightClick();

function showAttribute(e) {
	sList = window.open("/catalog/view_att.php?i="+e, "Attribute", "location=no,resizable=yes,menubar=no,status=no,toolbar=no,width=414,height=550");
}

//Google Maps support
function load() {
    if (GBrowserIsCompatible()) {
    	// init
      var map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(37.878, -122.457), 11);
      map.enableScrollWheelZoom();
      map.addControl(new GLargeMapControl()); 
  	map.addControl(new GMapTypeControl()); 
  	map.addControl(new GScaleControl());

  	// San Francisco Store
  	infoTabRL = [  new GInfoWindowTab("Address", "<b>Ruby Living - San Francisco</b><br />180 Townsend St.<br>San Francisco, CA 94107"), new GInfoWindowTab("Hours", "Mon. - Sat. 10a to 6p<br>Sunday 12pm to 5pm")];
  	infoTabFM = [  new GInfoWindowTab("Address", "<b>Ruby Living - Fillmore</b><br />1919 Fillmore St.<br>San Francisco, CA 94115"), new GInfoWindowTab("Hours", "Mon. - Sat. 10am to 6pm<br>Sunday 12pm to 5pm")];
  	infoTabMV = [  new GInfoWindowTab("Address", "<b>Ruby Living - Mill Valley</b><br />1 Throckmorton Ave.<br>Mill Valley, CA 94941"), new GInfoWindowTab("Hours", "Mon. - Sat. 10am to 6pm<br>Sunday 12pm to 5pm")];
  	
  	// Place a marker in the center of the map and open the info window// automatically
  	marker = new GMarker(new GLatLng(37.779197, -122.392382));
  	GEvent.addListener(marker, "click", function() {  
  		marker.openInfoWindowTabsHtml(infoTabRL);
  	});
  	GEvent.addListener(marker, "mouseover", function() {  
  		marker.openInfoWindowTabsHtml(infoTabRL);
  	});
  	map.addOverlay(marker);
  	
  	// Mill Valley Store
  	marker2 = new GMarker(new GLatLng(37.906704, -122.546248));
  	GEvent.addListener(marker2, "click", function() {  
  		marker2.openInfoWindowTabsHtml(infoTabMV);
  	});
  	GEvent.addListener(marker2, "mouseover", function() {  
  		marker2.openInfoWindowTabsHtml(infoTabMV);
  	});
  	map.addOverlay(marker2);
  	
  	// Fillmore Store
  	marker3 = new GMarker(new GLatLng(37.787574, -122.433491));
  	GEvent.addListener(marker3, "click", function() {  
  		marker3.openInfoWindowTabsHtml(infoTabFM);
  	});
  	GEvent.addListener(marker3, "mouseover", function() {  
  		marker3.openInfoWindowTabsHtml(infoTabFM);
  	});
  	map.addOverlay(marker3);
    }
 }
 // Create the marker and corresponding information window
function createInfoMarker(point, address) {
   var marker = new GMarker(point);
   GEvent.addListener(marker, "click",
      function() {
         marker.openInfoWindowHtml(address);
      }
   );
  return marker;
}
function showSF() {
	marker.openInfoWindowTabsHtml(infoTabRL);	
}
function showFM() {
	marker3.openInfoWindowTabsHtml(infoTabFM);	
}
function showMV() {
	marker2.openInfoWindowTabsHtml(infoTabMV);	
}
//search form
function showform(e) {
	if (e.value == '') e.value = 'Search';
}
function clearform(e) {
	if (e.value == 'Search') e.value = '';
}

