// *** Array of items *********************************************
var itemsImg = [ '' ];

var typeArray = ['', 'silver','color','copper','plated','misc'];


var dataArray =
[
	['',''],
	['necklaces','Collier'], // 1
	['earrings','Boucle'], // 2
	['bracelets','Bracelet'], // 3
	['rings','Bague'], // 4
	['parures','Ensemble'], // 5
	['trinkets','Trinket'], // 6
	['pendants','Pendant'], // 7
	['custom','Custom'], // 8
	['test','Test'], // 9
	['','']
];

var dataTitles =
[
	[''],
	['Necklaces'],
	['Earrings'],
	['Bracelets'],
	['Rings'],
	['Parures'],
	['Trinkets'],
	['Pendants'],
	['Custom Work'],
	['Test'],
	['']
];

var dataNames =
[
	[''],
	['necklaces'],
	['earrings'],
	['bracelets'],
	['rings'],
	['parures'],
	['trinkets'],
	['pendants'],
	['custom Work'],
	['test'],
	['']
];

var rightImgName =
[
	[''],
	['necklaces'],
	['earrings'],
	['bracelets'],
	['rings'],
	['parures'],
	['trinkets'], // trinklets
	['pendants'],
	['default'], // custom work
	['default'],
	['']
];

var itemsGen = 
[
 '',
 '<p>Those elegant and whimsical braided crocheted necklaces are entirely hand made using fine silver, colored or metal plated wire and a crochet needle or a wooden wire knitting spool.</p><p>Most of the necklaces are finely finished with Sterling silver adjustable clasps.</p>', // Necklaces
 '<p></p>', // Earrings
 '<p></p>', // Bracelets
 '<p></p>',	// Rings
 '<p></p>', // Parures
 '<p></p>',	// Trinklets
 '<p>Some pendants are entirely handmade using fine silver, colored or metal plated wire, and a crochet neddle or a wooden wire knitting pool.</p><p> Others are made of sea glass pieces, sea shell, stones, gemstones, bone or wood wrapped with fine silver or sterling silver, copper or colored wire.</p><p>They are also handcrafted with PMC.</p>', // Pendants
 '<p></p>', // Custom Work
 '<p></p>', 
 '<p></p>',
 ''
];

var dataCat = 0;
var dataType = 0;
var dataColl = 'None';
var dispObj = top.Display;

var array = self.location.href.split("?");

if (array.length > 1)
{
	var argArr = array[1].split('&');
	for (i = 0; i < argArr.length; i++)
	{
		var args = argArr[i].split('=');
		if (args[0] == 'type')
		{
			if (args.length > 1)
			{
				dataType = args[1];
			}
			else
			{
				dataType = 0;
			}
		}
		else if (args[0] == 'cat')
		{
			if (args.length > 1)
			{
				dataCat = args[1];
			}
			else
			{
				dataCat = 0;
			}
			
			if (dataCat >= dataArray.length)
				dataCat = 0;
		}
		else if (args[0] == 'coll')
		{
			if (args.length > 1)
			{
				dataColl = args[1];
			}
			else
			{
				dataColl = 'None';
			}
		}
	}
}

var xmlDoc;

function getCategory()
{
	var array = [];
	var index = 0;
	
	for (i = 1; i < 8; i++)
	{
		strQuery = '//Joaillerie/'+dataArray[i][1]+'[@coll="'+dataColl+'"]';
		var node = top.xmlDoc.selectSingleNode(strQuery);
		if (node)
		{
			array[index] = [dataTitles[i],i];
			index++;
		}
	}

	return array;
}

function createTable()
{
	var strQuery;
	if (dataType > 0)
		strQuery = '//Joaillerie/'+dataArray[dataCat][1]+'[@type="'+typeArray[dataType]+'" and @coll="'+dataColl+'"]';
	else
		strQuery = '//Joaillerie/'+dataArray[dataCat][1]+'[@coll="'+dataColl+'"]';
	
	var elts = top.xmlDoc.selectNodes(strQuery);
	var index = 1;
	var itemsArray = [['', '', '', '']];

	for (i = 0; i < elts.length; i++)
	{
		if (dataType >= 0)
		{
			itemsArray[index] = ['','','N/A','N/A',''];

			itemsArray[index][0] = elts[i].getAttribute('item');
			itemsArray[index][1] = elts[i].getAttribute('name');
			if (top.lang && top.lang == 'fr')
			{
				if (elts[i].childNodes.length > 2)
					itemsArray[index][2] = elts[i].childNodes[2].firstChild.nodeValue;
				if (elts[i].childNodes.length > 3)
					itemsArray[index][3] = elts[i].childNodes[3].firstChild.nodeValue;
			}
			else
			{
				if (elts[i].childNodes.length > 0)
					itemsArray[index][2] = elts[i].childNodes[0].firstChild.nodeValue;
				if (elts[i].childNodes.length > 1)
					itemsArray[index][3] = elts[i].childNodes[1].firstChild.nodeValue;
			}
			index = index + 1;
		}
	}

	top.items = itemsArray;
}

function createCollection()
{
	var strQuery;
	strQuery = '//Joaillerie/*[@coll ="'+dataColl+'"]';
	
	var elts = top.xmlDoc.selectNodes(strQuery);
	var index = 1;
	var itemsArray = [['','','','','']];

	for (i = 0; i < elts.length; i++)
	{
		itemsArray[index] = ['','','','',''];
		itemsArray[index][0] = elts[i].getAttribute('item');
		itemsArray[index][1] = elts[i].getAttribute('name');
		itemsArray[index][2] = elts[i].childNodes[0].firstChild.nodeValue;
		itemsArray[index][3] = elts[i].childNodes[1].firstChild.nodeValue;
		itemsArray[index][4] = elts[i].getAttribute('price');
		index = index + 1;
	}
	
	top.items = itemsArray;
}

function xmlLoaded()
{
	top.xmlDoc = xmlDoc;
}

function loadXML()
{
	if (top.xmlDoc)
	{
		//createTable();
		return;
	}

	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = createTable;
		xmlDoc.load("../scripts/catalog.xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) xmlLoaded()
		};

		xmlDoc.load("../scripts/catalog.xml");
	}
	else
	{
		alert('Your browser can\'t handle this script');
	}
}

function loadCollXML()
{
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = createCollection;
		xmlDoc.load("../scripts/catalog.xml");
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) createCollection()
		};

		xmlDoc.load("../scripts/catalog.xml");
	}
	else
	{
		alert('Your browser can\'t handle this script');
	}
}

function showCollImage(index)
{
	if (top.document.getElementById("itemID"))
	{
		top.document.getElementById("itemName").innerHTML = top.items[index][1];
		top.document.getElementById("itemID").innerHTML = top.items[index][0];
		top.document.getElementById("itemDesc").innerHTML = top.items[index][3];
		
		var itemImg = top.document.images['itemImg'];
		itemImg.src = '../artwork/'+dataColl+'/'+top.items[index][0]+'.jpg';
	}
}

function showCustom()
{
	if (top.Display && top.Display.isDisplayLoaded)
	{
		top.Display.document.location='gems-jewelry-customw.html';
		
		if (top.document.getElementById("imgRightCol"))
		{
			top.document.getElementById("imgRightCol").style.backgroundImage = 'url(../images/default-column-right.jpg)';
			top.document.getElementById("imgRightCol").innerHTML = '<p></p>';
		}

    itemImg = document.images['galImg'];
    itemImg.src = '../images/gallery-gallery.jpg';
	}
}

function showItems(index)
{
	if (index > 0)
	{
	  dataCat = index;
	  dataType = 0;
		
		if (top.xmlDoc == undefined) loadXML();

		createTable();
		if (top.document.images)
		{
      itemImg = top.document.images['galImg'];
      itemImg.src = '../images/'+dataColl+'-'+rightImgName[index]+'.jpg';
		}
		
		if (top.document.getElementById("imgRightCol"))
		{
			top.document.getElementById("imgRightCol").style.backgroundImage = 'url(../images/'+rightImgName[index]+'-column-right.jpg)';
			top.document.getElementById("imgRightCol").innerHTML = itemsGen[index];
		}
			
		if (top.items && top.items.length > 1)
		{
		 	 if (top.Display && top.Display.isDisplayLoaded)
			 {
			 	top.Display.document.location='gems-jewelry.html?coll='+dataColl+'&cat='+index;
			 }
		}
		else
		{
			top.Display.document.location='gems-jewelry-noshow.html?coll='+dataColl+'&cat='+index;
		}
	}
	else
	{
		if (top.Display && top.Display.isDisplayLoaded)
		{
			top.Display.document.location='gems-jewelry-pres.html';
		}
	}
}

function preloadImages(array)
{
  var d=document;

  if(!d.images) return;

 	if(!d.MM_p) d.MM_p=new Array();
 	var i,j=d.MM_p.length;
		
 	for(i=0; i<array.length; i++)
	{
 		if (array[i].length > 0)
 		{
 				d.MM_p[j]=new Image;
 				d.MM_p[j++].src=array[i];
 		}
	}
}

function changeThumbs(type)
{
	if (window.Thumbs && window.Thumbs.isThumbsLoaded)
	{
		window.Thumbs.document.location = 'gems-thumbs.html?coll='+dataColl+'&cat=0&type='+type;
	}
}

function chgBg(obj,color)
{
	if (document.all || document.getElementById)
	{
		if (obj.style) obj.style.backgroundColor=color;
	}
	else if (document.layers)
		obj.bgColor=color;
}

function nolefttext()
{
	itemsGen = 
	[
 		'',
 		'<p></p>', // Necklaces
 		'<p></p>', // Earrings
 		'<p></p>', // Bracelets
 		'<p></p>',	// Rings
 		'<p></p>', // Parures
 		'<p></p>',	// Trinklets
 		'<p></p>', // Pendants
 		'<p></p>', // Custom Work
 		'<p></p>', 
 		'<p></p>',
 		''
	];
}

function enfrancais()
{
	top.lang = 'fr';
	dataTitles =
	[
		[''],
		['Colliers'],
		['Boucles d\'oreilles'],
		['Bracelets'],
		['Bagues'],
		['Parures'],
		['Divers'],
		['Pendentifs'],
		['Custom Work'],
		['Test'],
		['']
	];

	dataTitles =
	[
		[''],
		['Colliers'],
		['Boucles d\'oreilles'],
		['Bracelets'],
		['Bagues'],
		['Parures'],
		['Divers'],
		['Pendentifs'],
		['Custom Work'],
		['Test'],
		['']
	];

	itemsGen = 
	[
 		'',
 		'<p>Ces colliers sont enti&egrave;rement crochet&eacute;s &agrave; la main, avec du fil de m&eacute;tal (argent ou cuivre, color&eacute;, ou plaqu&eacute;), pour cr&eacute;er des mod&egrave;les raffin&eacute;s et audacieux.</p><p>La plupart des colliers et bracelets sont termin&eacute;s avec des fermoirs ajustables en argent.</p>', // Necklaces
 		'<p></p>', // Earrings
 		'<p></p>', // Bracelets
 		'<p></p>',	// Rings
 		'<p></p>', // Parures
 		'<p></p>',	// Trinklets
 		'<p>Certains de ces pendentifs sont fait &agrave; partir de pierres naturelles ou semi pr&eacute;cieuses, de cristal ou de verre d&eacute;poli par la mer, serties avec du fil de m&eacute;tal (argent ou cuivre, color&eacute; ou plaqu&eacute;).</p><p>D\'autres sont enti&egrave;rement fabriqu&eacute;s &agrave; la main en PMC (Precious Metal Clay:p&acirc;te d\'argent), ou &agrave; partir de feuille d\'argent (sterling ou v&eacute;ritable), ou de cuivre.</p>', // Pendants
 		'<p></p>', // Custom Work
 		'<p></p>', 
 		'<p></p>',
 		''
	];
}


