// Copyright 2008 - SilverDock LLC
// www.silverdock.com

// ----------------- START editable section
var sd_myhost = "http://asiaexports.silverdock.net";
var sd_mycid = 102;
var sd_myprods = [
	//mpid, description, link
	{mpid:"frc1032", desc:"Marble Top End Table - Carved Trim", link:"http://www.asiaexp.com/Antique-Style-Marble-Top-End-Table"},
	{mpid:"frc1040", desc:"Rustic Shoe Cabinet W Custom Hardware",       link:"http://www.asiaexp.com/Handmade-Custom-Hardware-Storage-Cabinet"},
	{mpid:"frc1047", desc:"Black / Red Lacquered Dresser",    link:"http://www.asiaexp.com/Handmade-Lacquered-Dresser-Storage-Cabinet"},
	{mpid:"frc1062", desc:"Gold Oriental Storage Cabinet",         link:"http://www.asiaexp.com/Handmade-Gold-Oriental-Storage-Cabinet"},
	{mpid:"frc1066", desc:"3-Piece Red / Gold Lacquer Cabinet",     link:"http://www.asiaexp.com/3-Piece-Red-Lacquer-Storage-Cabinet-End-Table"},
	{mpid:"frc1067", desc:"Mother of Pearl Lacquer Storage Cabinet",         link:"http://www.asiaexp.com/Mother-of-Pearl-Black-Lacquer-Storage-Cabinet"},
	{mpid:"frt1078", desc:"Teak & Rattan Console Table",           link:"http://www.asiaexp.com/Teak-Rattan-Console-Table-W-Painted-Floral-Trim"},
	{mpid:"frt1055", desc:"Carved Arabesque Storage Chest",             link:"http://www.asiaexp.com/Carved-Arabesque-Storage-Chest-Coffee-Table"},
	{mpid:"frc1102", desc:"Antiqued Red 6-Sided End Table",       link:"http://www.asiaexp.com/6-Sided-Floral-Carving-Red-End-Table"},
	{mpid:"frc1095", desc:"Antiqued Black Speckled End Table",             link:"http://www.asiaexp.com/Antique-Style-Black-Speckled-Wood-End-Table"},
	{mpid:"frc1092", desc:"Black Asian Contemporary Nightstand",              link:"http://www.asiaexp.com/Black-Wood-End-Table-Night-Stand"},
	{mpid:"frc1072", desc:"Antique Style Butterfly Cabinet",              link:"http://www.asiaexp.com/Antique-Style-Painted-Butterflies-Storage-Cabinet"},
];
var changelabelonmouseover=false;
var thumbnailwidth = 50; // in px, including border
// ------------------ END editable section

function findproduct(mpid){
	for(i in sd_myprods){
		if(sd_myprods[i].mpid==mpid){
			return sd_myprods[i];
		}
	}
	return null;
}

var sd_curmpid = null;
function add_anchor(myprod){
   if(myprod!=null){
	mybrowser = document.getElementById("sdb_thumbnails");
	myimg = sd_myhost+"/fs/"+sd_mycid+"/"+myprod.mpid+"/thumbnail.jpg";
	myhtml = "<a id='sdb__"+myprod.mpid+"' class='product' title='"+myprod.desc+"' ";
	myhtml += "onmouseover='sd_overlabel(\""+myprod.desc+"\");' onmouseout='sd_outlabel();' ";
	myhtml += "href=\"javascript:startvid('"+myprod.mpid+"');\">";
	myhtml += "<img src='"+myimg+"' alt='"+myprod.desc+"'>";
	myhtml += "</a>\n";
	mybrowser.innerHTML += myhtml;
   }
}
function sd_setnamelink(mpid){
	myprod = findproduct(mpid);
	if(myprod==null){
		desc = mpid;
		link = "#";
	}
	else{
		desc = myprod.desc;
		link = myprod.link;
	}
	myanchor = document.getElementById("sdb_label");
	myanchor.innerHTML = desc;
	myanchor.href = link;
}
var templabel = "";
function sd_overlabel(newlabel){
	if(changelabelonmouseover){
		myanchor = document.getElementById("sdb_label");
		templabel = myanchor.innerHTML;
		myanchor.innerHTML = "Change to: "+newlabel;
	}
}
function sd_outlabel(){
	if(changelabelonmouseover){
		myanchor = document.getElementById("sdb_label");
		myanchor.innerHTML = templabel;
	}
}
function startvid(mpid){
	var oldmpid = sd_curmpid;
	var olddiv = document.getElementById("sdb__"+oldmpid);
	olddiv.className = "product";
	sd_curmpid = mpid;
	var mydiv = document.getElementById("sdb__"+mpid);
	mydiv.className = "product selected";
	sd_setnamelink(mpid);
	sd_add_inscript(mpid);
	sd_startvid_try();
}
function init_video(){
	var i=0;
	var len=sd_myprods.length;
	while(i<len){
		//fill browser div with list of links
		if(sd_myprods[i]!=null){
			add_anchor(sd_myprods[i]);
			i++;
		}
		else{
			break;
		}
	}
	sd_curmpid = sd_myprods[0].mpid;
	var firstthumbnail = document.getElementById("sdb__"+sd_curmpid);
	firstthumbnail.className = "product selected";
	var thumbnails = document.getElementById("sdb_thumbnails");
	thumbnails.style.width = (i * thumbnailwidth)+'px';
	sd_setnamelink(sd_curmpid);
	sd_add_inscript(sd_curmpid);
	sd_startvid_try();
}

//////////////////////////////////////////////////

var added_scripts = new Array();
function sd_add_inscript(mpid){
   myprod = findproduct(mpid);
   if(myprod!=null && myprod.added!=true){
        var s = document.createElement('script');
        var srcurl = sd_myhost+"/in/"+mpid+"?ap=play&autorun=false";
        var srcurl = sd_myhost+"/in/?c="+sd_mycid+"&m="+mpid+"&ap=play&autorun=false";
	if(link!=""){
		srcurl += "&bglink="+encodeURIComponent(link);
	}
        s.setAttribute("src",srcurl);
        s.setAttribute("type","text/javascript");
        document.getElementsByTagName('head')[0].appendChild(s);
	myprod.added=true;
   }
}

function sd_startvid(mpid){
	var mainvid = document.getElementById("sd__mainvid");
	//insert sd_mpid div into mainvid div
	mystyle="background-repeat:no-repeat;background-image:url("+sd_myhost+"/fs/"+sd_mycid+"/"+mpid+"/default.jpg);";
	mainvid.innerHTML = "<div id='sd_"+mpid+"' style='"+mystyle+"'></div>"
	//sdo.run
	sd_objs[mpid].run();
}

//set sd_curmpid before running this
function sd_startvid_try(){
        if(typeof sd_objs == "undefined" || typeof sd_objs[sd_curmpid] == "undefined"){
                // try 4 times a second
                setTimeout(sd_startvid_try, 250);
        }
        else{
		sd_startvid(sd_curmpid);
        }
}

////////////////////////////////////////////////////

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Mr J | http://www.huntingground.net/ */

var scrollStep=2; // pixels
var timeStep=15; //milliseconds

// scroll speed is pixels/millisecond --> scrollStep/timeStep

var timerUp="";                    
var timerDown="";              
var timerLeft="";             
var timerRight="";

function stopMe(){
  clearTimeout(timerUp);
  clearTimeout(timerDown);      
  clearTimeout(timerLeft);
  clearTimeout(timerRight);
}

function toTop(id){
  document.getElementById(id).scrollTop=0;
}   

function toBottom(id){
  document.getElementById(id).scrollTop=document.getElementById(id).scrollHeight;
}

function toLeft(id){
  document.getElementById(id).scrollLeft=0;
}                

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth;
}

function scrollDivUp(id){
  clearTimeout(timerUp);               
  document.getElementById(id).scrollTop-=scrollStep;
  timerUp=setTimeout("scrollDivUp('"+id+"')",timeStep);
}            

function scrollDivDown(id){
  clearTimeout(timerDown);
  document.getElementById(id).scrollTop+=scrollStep;
  timerDown=setTimeout("scrollDivDown('"+id+"')",timeStep);
}

function scrollDivLeft(id){
  clearTimeout(timerRight);
  document.getElementById(id).scrollLeft+=scrollStep;
  timerRight=setTimeout("scrollDivLeft('"+id+"')",timeStep);
}

function scrollDivRight(id){
  clearTimeout(timerLeft);
  document.getElementById(id).scrollLeft-=scrollStep;
  timerLeft=setTimeout("scrollDivRight('"+id+"')",timeStep);
}

////////////////////////////////////////////////////

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.push() - Add an element to the end of an array, return the new length
if( typeof Array.prototype.push==='undefined' ) {
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
}


