// Define path prefixes
var imagePrefix = '';
// Define product info, sorted into pages
var bank = new Hash({
	'Page 1':[
		 /*{
			'thumb':'http://www.marjorieskourasdesign.com/images/secret_stash_8-09/Skouras_Residence&Product_009_s.jpg',
			'large':'http://www.marjorieskourasdesign.com/images/secret_stash_8-09/Skouras_Residence&Product_009_l.jpg',
			'desc':'Amethyst Honeycomb Lantern<br/>15" Diameter<br/>$1,300.00',
		},
		{
			'thumb':'http://www.marjorieskourasdesign.com/images/secret_stash_8-09/Skouras_Residence&Product_007_s.jpg',
			'large':'http://www.marjorieskourasdesign.com/images/secret_stash_8-09/Skouras_Residence&Product_007_l.jpg',
			'desc':'Pink Coral Empire Chandelier<br/>15" Diameter X 25"H<br/>$3,750.00',
		}, */
		{
			'thumb':'http://www.marjorieskourasdesign.com/images/milobaughman_sofa2_s.jpg',
			'large':'http://www.marjorieskourasdesign.com/images/milobaughman_sofa1_mid.jpg',
			'desc':'Milo Baughman Sofa<br/>84"L X 30"D<br/><br/>This was the sofa that I used for the Metropolitan Home Showcase House. The frame is by Milo Baughman, circa 1970 something, and it is upholstered in an Osborne & Little Linen and Silk Velvet. $3,900.00',
		}
	]
});
window.addEvent('domready',function(){
	// Define DIV Elements to affect
	var pageDiv = $('paages');
	var thumbsDiv = $('thumbs');
	var productTearSheet = $('tearSheetLink');
	var productDesc = $('picDesc');
	var productImage = $('productImage');
	var productDiv = $('product');
	// Javascript is on
	productTearSheet.set('html','');
	// Create page links
/*
	var pageLinks = [];
	bank.getKeys().each(function(value,index,array){	
		pageLinks.extend([new Element('a',{
			'html':value,
			'href':('#'+value).hyphenate()
		}).inject(pageDiv).addEvent('click',function(){
			loadPage(value);
		})]);
		if(value!=array.getLast()){
			pageDiv.appendText(' | ');
		}
	});
*/
	// 
	function loadProduct(large,desc,tearsheet){
		productImage.destroy();
		productImage = new Asset.image(imagePrefix+large,{
			'styles':{
				'width':329,
				'height':'auto'
			}
		}).inject(productDiv,'top');
		productDesc.set('html',desc);
		//productTearSheet.set('href',tearSheetPrefix+tearsheet);
	}
	function loadPage(page){
/*
		pageLinks.each(function(item){
			if(page==item.get('html')){
				item.setStyle('color','white');
			} else {
				item.setStyle('color','');
			}
		});
*/
		thumbsDiv.empty();
		var pageBank = bank.get(page);
		var defaultProduct = 0;
		var thumbLinkRow = new Array();
		pageBank.each(function(item,index,array){
			if(!$defined(item.visible)||item.visible){
				var thumbnaillink = new Element('a',{
					'href':'#'+page+index
				});
				var thumbnail = new Asset.image(imagePrefix+item.thumb,{
					'styles':{
						'margin-left':16,
						'margin-bottom':14,
						'float':'right',
						'border':0
					}
				}).inject(thumbnaillink).addEvent('click',function(){
					loadProduct(item.large,item.desc,item.tearsheet);
				});
				// re-ordering code
				thumbLinkRow.extend([thumbnaillink]);
				while(array.length==(index+1)&&thumbLinkRow.length<4){
					var spaceDiv = new Element('div',{ 'styles':{
						'margin-left':16,
						'margin-bottom':14,
						'display':'none',
						'float':'right',
						'height':'100px',
						'width':'80px'
					}});
					thumbLinkRow.extend([spaceDiv]);
				}
				if(thumbLinkRow.length > 3){
					for(i=thumbLinkRow.length;i>0;i--){
						thumbLinkRow[i-1].inject(thumbsDiv);
					}
					thumbLinkRow.empty();
				}
			}
			if(item.isdefault) defaultProduct = index;
		});
		var defaultProduct = pageBank[defaultProduct];
		loadProduct(defaultProduct.large,defaultProduct.desc,defaultProduct.tearsheet);
	}
/*
	function loadPage(page){
		pageLinks.each(function(item){
			if(page==item.get('html')){
				item.setStyle('color','white');
			} else {
				item.setStyle('color','');
			}
		});
		thumbsDiv.empty();
		var pageBank = bank.get(page);
		var defaultProduct = 0;
		pageBank.each(function(item,index,array){
			var thumbnaillink = new Element('a',{
				'href':'#'+page+index
			}).inject(thumbsDiv);
			var thumbnail = new Asset.image(imagePrefix+item.thumb,{
				'styles':{
					'margin-left':16,
					'margin-bottom':14,
					'float':'right',
					'border':0
				}
			}).inject(thumbnaillink).addEvent('click',function(){
				loadProduct(item.large,item.desc,item.tearsheet);
			});
			if(item.isdefault){ defaultProduct = index; }
		});
		var defaultProduct = pageBank[defaultProduct];
		loadProduct(defaultProduct.large,defaultProduct.desc,defaultProduct.tearsheet);
	}
*/
	// Load initial page
	loadPage(bank.getKeys()[0]);
});