﻿
// A group of functions to iterate through the set of images.

var curr = 0;
var products = new Array();

function show_view(idx)
{
    var p = products[curr];
    document.getElementById("pic").src = p.pics[idx]; 
}

function show_view_file(file)
{
    document.getElementById("pic").src = file; 
}

function set_current_product(idx)
{
    curr = idx;
}

function add_product(product)
{
    var idx = products.length;
    products[idx] = product;
}

function Product(id, model, size, color, condition, price, pic1, pic2, pic3, alt)
{
    this.id     = id;
    this.model  = model;
    this.size   = size;
    this.color  = color; 
    this.condition = condition; 
    this.price  = "$" + price; 
    
    this.pics = new Array();
    
    this.pics[1] = pic1; 
    this.pics[2] = pic2; 
    this.pics[3] = pic3;
    
    this.alt = alt;
}

function show_product(idx)
{
    curr = idx;
    var p = products[curr];
    var big_pic = document.getElementById("pic");
    big_pic.src = p.pics[1];
    big_pic.alt = p.alt;

    document.getElementById("model").innerHTML = p.model;
    document.getElementById("size").innerHTML = p.size;
    document.getElementById("color").innerHTML = p.color;
    document.getElementById("condition").innerHTML = p.condition;
    document.getElementById("price").innerHTML = p.price;

    document.getElementById("thumb3").src  = p.pics[3] + ".t.jpg";        
    document.getElementById("thumb2").src  = p.pics[2] + ".t.jpg";        
    document.getElementById("thumb1").src  = p.pics[1] + ".t.jpg";  
    
    document.getElementById("thumb3").alt  = p.alt + " detail";
    document.getElementById("thumb2").alt  = p.alt + " back";        
    document.getElementById("thumb1").alt  = p.alt + " front"; 

    document.getElementById("item_name").value = p.model;
    document.getElementById("item_number").value = p.id;
    document.getElementById("amount").value = p.price;
    
    document.getElementById("cancel").value = "http://www.fashionsforpassion.com/display.php?prod_id=" + p.id;
    
    document.location.hash = p.model;
}

function show_hash()
{
	if (document.location.hash != "")
	{
		for (p in products)
		{
			var x = "#" + products[p].model;
			var y = document.location.hash;
			if (x == y)
			{
				show_product(p);
				break;
			}
		}
	}
	else
	{
		document.location.hash = products[curr].model;
	}
}

function show_next_product()
{
	++curr;
	curr = curr % products.length;
    show_product(curr);
}

function show_prev_product()
{
	curr += products.length - 1;
	curr = curr % products.length;
    show_product(curr);
}


