var object_for_change;
var object_for_open_close;
var object_shape;
var metals_count;
var stones_count;

var rotation_status=0; //1 rotating
var assemble_status=0; //0 assembled, 1 exploded
var show_stones_status=0;
var open_close_status = new Array();
var shape_status = new Array();
var dimension_status=0; //0 off, 1 on
var dimension_text_0='';
var description_status=0; //0 off, 1 on
var desxcription_text='';
var show_description_status=0;


var comm=new Array()
comm[00]="diam";
comm[01]="emer";
comm[02]="sapp";
comm[03]="ruby";
comm[04]="tanz";
comm[21]="gldy";
comm[22]="gldw";
comm[23]="gldy";
comm[24]="gldw";
comm[25]="plat";
comm[30]="round";
comm[31]="square";
comm[32]="oval";

// Caboshons stones
comm[50]="citr";   //citrine 
comm[51]="amet";   //Amethist 
comm[52]="trmgr"; //torumaline green
comm[53]="trmmn"; //torumaline mint
comm[54]="trmpn"; //torumaline pink
comm[55]="trmpr"; //torumaline paraiba
comm[56]="garn";   // Garnet red
comm[57]="rubl";   //Rubelite
comm[58]="agat";   //Blue Agate
comm[59]="aqua";   //Aquamarine
comm[60]="emerc";   //Emerald cab


var menuobj;
//Set delay before submenu disappears after mouse moves out of it (in milliseconds)
var delay_hide=1000

var submenu=new Array()
submenu[0] ='<a href="" onClick="return change(00)">diamond</a><br>';
submenu[0]+='<a href="" onClick="return change(01)">emerald</a><br>';
submenu[0]+='<a href="" onClick="return change(03)">ruby</a><br>';
submenu[0]+='<a href="" onClick="return change(02)">sapphire</a><br>';
submenu[0]+='<a href="" onClick="return change(04)">tanzanite</a>';

submenu[1] ='<a href="" onClick="return change(21)">gold 14k yellow</a><br>';
submenu[1]+='<a href="" onClick="return change(22)">gold 14k white</a><br>';
submenu[1]+='<a href="" onClick="return change(23)">gold 18k yellow</a><br>';
submenu[1]+='<a href="" onClick="return change(24)">gold 18k white</a><br>';
submenu[1]+='<a href="" onClick="return change(25)">platinum</a>';

submenu[5] ='<a href="" onClick="return change(50)">Citrine</a><br>';
submenu[5]+='<a href="" onClick="return change(51)">Amethist</a><br>';
submenu[5]+='<a href="" onClick="return change(52)">Tourmaline Green</a><br>';
submenu[5]+='<a href="" onClick="return change(53)">Tourmaline Mint</a><br>';
submenu[5]+='<a href="" onClick="return change(54)">Tourmaline Pink</a><br>';
// submenu[5]+='<a href="" onClick="return change(55)">Tourmaline Paraiba</a><br>';
submenu[5]+='<a href="" onClick="return change(56)">Garnet</a><br>';
// submenu[5]+='<a href="" onClick="return change(57)">Rubelite</a><br>';
// submenu[5]+='<a href="" onClick="return change(58)">Blue Agat</a><br>';
submenu[5]+='<a href="" onClick="return change(59)">Aquamarine</a><br>';
submenu[5]+='<a href="" onClick="return change(60)">Emerald</a><br>';

var menu_original;
menu_original='<a href="" onClick="return original()">ORIGINAL VIEW</a>';

var rotate_menu=new Array()
rotate_menu[0]='<a href="" onClick="return rotation()">ROTATING</a>';
rotate_menu[1]='<a href="" onClick="return rotation()">STOP ROTATION</a>';

var assemble_menu=new Array()
assemble_menu[0]='<a href="" onClick="return Assemble()">EXPLODE</a>';
assemble_menu[1]='<a href="" onClick="return Assemble()">ASSEMBLE</a>';

var open_close_menu=new Array()
open_close_menu[0]='<a href="" onClick="return open_close()">OPEN</a>';
open_close_menu[1]='<a href="" onClick="return open_close()">CLOSE</a>';
open_close_menu[2]='';

var show_stones_menu=new Array()
show_stones_menu[0]='<a href="" onClick="return show_stones()">SHOW STONES</a>';
show_stones_menu[1]='<a href="" onClick="return show_stones()">HIDE STONES</a>';

var shape_menu=new Array();
shape_menu[0] ='';

var dimension_menu='<a href="" onClick="show_dimension(); return false;">DIMENSIONS</a>';
var description_menu='<a href="" onClick="show_description(); return false;">DESCRIPTION</a>';

function show_dimension() {
 if (description_status) {
  description_status=0;
  hiddenLayer();
 }
 if (dimension_status) {
  dimension_status=0;
  hiddenLayer();
 } else {
  dimension_status=1;
  change_text(dimension);
  showLayer();
 }
}
function show_description() {
 if (dimension_status) {
  dimension_status=0;
  hiddenLayer();
 }
 if (description_status) {
  description_status=0;
  hiddenLayer();
 } else {
  description_status=1;
  change_text(description_text);
  showLayer();
 }
}


function init(p1,p2,p3,p4,p5) {
 menuobj=document.getElementById? document.getElementById("describe") : document.all? document.all.describe : document.layers? document.dep1.document.dep2 : "";
 showit(-1);
 if (p1)    {rotation_status=p1}
 if (p2)    {assemble_status=p2}
 if (p3)    {show_stones_status=p3}
 if (p5)    {show_description_status=p5}
 if (p4==0) {dimension_menu=''}
 rotate_menu[0]=menu_original+' &bull; '+rotate_menu[0]+' &bull; ';
 rotate_menu[1]=menu_original+' &bull; '+rotate_menu[1]+' &bull; ';
 if (p4>0) {
  rotate_menu[0]+=dimension_menu+' &bull; ';
  rotate_menu[1]+=dimension_menu+' &bull; ';
 }
 if (p5>0) {
  rotate_menu[0]+=description_menu+' &bull; ';
  rotate_menu[1]+=description_menu+' &bull; ';
 }
 assemble_menu[0]+=' &bull; ';
 assemble_menu[1]+=' &bull; ';
 show_stones_menu[0]+=' &bull; ';
 show_stones_menu[1]+=' &bull; ';
 if (p1>=0) {changeContent('rotate',rotation_status)}
 if (p2>=0) {changeContent('assemble',assemble_status)}
 if (p3>=0) {changeContent('showstones',show_stones_status)}
 for (i=1;i<=metals_count;i++) open_close_status[i]=0
}



function changeContent(name,new_value) {
 if (name == 'showstones') {
  menu=document.getElementById? document.getElementById('showstones') : document.all? document.all.showstones : document.layers? document.show1.document.show2 : "";
  new_value=show_stones_menu[new_value]
 }
 if (name == 'rotate') {
  menu=document.getElementById? document.getElementById('rotate') : document.all? document.all.rotate : document.layers? document.rot1.document.rot2 : "";
  new_value=rotate_menu[new_value]
 }
 if (name == 'assemble') {
  menu=document.getElementById? document.getElementById('assemble') : document.all? document.all.assemble : document.layers? document.ass1.document.ass2 : "";
  new_value=assemble_menu[new_value]
 }
 if (name == 'open') {
  menu=document.getElementById? document.getElementById('open') : document.all? document.all.open : document.layers? document.open1.document.open2 : "";
  new_value=open_close_menu[new_value]
 }
 if (name == 'dimension_') {
  menu=document.getElementById? document.getElementById('dimension_') : document.all? document.all.dimension_ : document.layers? document.dimension_1.document.dimension_2 : "";
  new_value=dimension_menu
 }
 if (name == 'description_') {
  menu=document.getElementById? document.getElementById('dimension_') : document.all? document.all.dimension_ : document.layers? document.dimension_1.document.dimension_2 : "";
  new_value=description_menu
 }
 if (name == 'shape') {
  menu=document.getElementById? document.getElementById('open') : document.all? document.all.open : document.layers? document.open1.document.open2 : "";
  new_value=shape_menu[new_value]
 }
 if (document.getElementById||document.all) {
   menu.innerHTML=new_value;
  }
  else 
   if (document.layers) {
    menu.document.write(new_value)
    menu.document.close()
   }
}



function showit(which){
thecontent=(which==-1)? "" : submenu[which]
if (document.getElementById||document.all) menuobj.innerHTML=thecontent
else if (document.layers) {
  menuobj.document.write(thecontent)
  menuobj.document.close()
 }
}


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

function change_object(type,object) {
 if (type == 1) {
  object_for_change=object;
  showit(0);
 } 
 if (type == 2) {
  object_for_change=object;
  showit(1)
 }
 if (type == 3 && assemble_status<=0) {
  object_for_open_close=object;
  changeContent('open',open_close_status[object])
 }
 if (type == 4) {
  object_shape=object;
  changeContent('shape',object_shape)
 }
 
 if (type == 5) {
 // Caboshons
  object_for_change=object;
  showit(5)
 }
return false
}


function change (command) {
 if (object_for_change<=0) {alert('You have to choose object first!');return false}
 cmd=comm[command]+object_for_change;
 vmp.TriggerAnim(cmd);
 clearMenu();
 return false
}


function open_close () {
 if (assemble_status==1) {
  assemble_status=0;
  vmp.TriggerAnim('attach');
  changeContent('assemble',0);
 }
 if (object_for_open_close==0) {alert('You have to choose Metal Object first!')} 
  else {  
   if (open_close_status[object_for_open_close] == 0) {
     open_close_status[object_for_open_close]=1;
     temp="open_"+object_for_open_close;
   } else {
     open_close_status[object_for_open_close]=0;
     temp='close_'+object_for_open_close;
   }
   vmp.TriggerAnim(temp);
 }
 clearMenu();
 return false;
}

function rotation () {
 if (rotation_status == 0) {
  rotation_status=1;
  vmp.StartAnim('rotate');
  changeContent("rotate",1);
 } else {
  rotation_status=0;
  vmp.StopAnim('rotate');
  changeContent("rotate",0);
 }
 return false
}


function original () {
 vmp.TriggerAnim('original');
 return false;
}


function Assemble() {
 if (assemble_status>=0) {
  if (assemble_status==0) {
   for (i=0;i<=metals_count;i++) {
    if (open_close_status[i]) {
     return false;
    }
   }
   assemble_status=1;
   vmp.TriggerAnim('detach');
   changeContent('assemble',1);
  } else {
   assemble_status=0;
   vmp.TriggerAnim('attach');
   changeContent('assemble',0);
  }
 }
 return false;
}

function show_stones() {
 if (show_stones_status == 0) {
  vmp.TriggerAnim('showstones');
  for (i=1;i<=stones_count;i++) {
   if (shape_status[i]>-1) {
    temp=comm[shape_status[i]]+'_'+i+'_on';
    vmp.TriggerAnim(temp);
   }
  }
  show_stones_status=1;
 } else {  
  vmp.TriggerAnim('hidestones');
  for (i=1;i<=stones_count;i++) {
   if (shape_status[i]>-1) {
    temp=comm[shape_status[i]]+'_'+i+'_off';
    vmp.TriggerAnim(temp);
   }
  }
  show_stones_status=0;
 }
 changeContent('showstones',show_stones_status);
 return false;
}


function clearMenu() {
 changeContent('open',2);
 showit(-1);
}

function change_shape(shape) {
 if (shape_status[object_shape] != shape) {
  temp=comm[shape_status[object_shape]]+"_"+object_shape+"_off";
  vmp.TriggerAnim(temp);
  temp=comm[shape]+"_"+object_shape+"_on";
  vmp.TriggerAnim(temp);
  shape_status[object_shape]=shape;
 }
 showit(-1);
 changeContent('shape',0);
 return false;
}



function  init_layers()  { IE  =  (document.all); NC  =  (document.layers); Opera  =  (document.getElementById)}
function  hiddenLayer()  { init_layers(); if(IE)  eval('document.all["dimension_win"].style.visibility  = "hidden"'); if(NC)  eval('document.layers["dimension_win"].visibility  =  "hidden"');if(Opera) eval('document.getElementById("dimension_win").style.visibility  ="hidden"');}
function  showLayer()    { init_layers(); if(IE)  eval('document.all["dimension_win"].style.visibility  ="visible"'); if(NC)  eval('document.layers["dimension_win"].visibility  =   "visible"'); if(Opera) eval('document.getElementById("dimension_win").style.visibility  = "visible"')}

function change_text(new_value) {
 place=document.getElementById? document.getElementById('dimension') : document.all? document.all.dimension : document.layers? document.dimension1.document.dimension2 : "";
 if (document.getElementById||document.all) {
   place.innerHTML=new_value;
 } else if (document.layers) {
    place.document.write(new_value)
    place.document.close()
 }
}

