// JavaScript Document
function Photo(i,t,d,s,pl)
{
        this.id = i;
        this.title = t;
        this.desc = d;
        this.sizes = s;
        this.th = new Image();
        this.th.src = "./images/th" + i + "x.jpg";              // Preload image
}

// Sizing and pricing
var SIZES = ['8"x10"','11"x14"','16"x20"','20"x24"']
var S8x10=0; var S11x14=1; var S16x20=2; var S20x24=3;
var PRICES = new Array(SIZES.length);
PRICES[S8x10] = new Array();  PRICES[S8x10][false]  =  95; PRICES[S8x10][true]  = 200;
PRICES[S11x14] = new Array(); PRICES[S11x14][false] = 195; PRICES[S11x14][true] = 350;
PRICES[S16x20] = new Array(); PRICES[S16x20][false] = 295; PRICES[S16x20][true] = 495;
PRICES[S20x24] = new Array(); PRICES[S20x24][false] = 395; PRICES[S20x24][true] = 630;
var PIC_START = 0;
var PIC_ROWS = 3;
var PIC_COLS = 2;
var PICTURES = [114,106,103, 110,101,115, 107,108,109, 105,113,118, 102,104,111, 112,116,117, 204,202,203, 201,205];
var RANDOM_PICS = [118,110,115,106,101,103,105,202,204];
var RANDOM_FRAMED = [114,110,115,106,103,101];

var photos = new Array(
        new Photo(101,'Skyline from Queen Anne Hill','',[false,true,true,true]),
        new Photo(102,'Days End','Cowboys returning home after a long day\s work.<br>(Winthrop, 1978)',[false,true,false,false]),
        new Photo(103,'Ferry at Kirkland','An incredible shot of a ferry docked in Kirkland with a couple of UW sculls in the foreground.',[false,true,true,true]),
        new Photo(104,'Hobie Cats','',[false,true,false,false]),
        new Photo(105,'Horses in Poetic Motion','Horses in the rising mists of a frosty autumn dawn, the sun breaking through the overcast and the rolling landscape create a near perfect composition.<br>(Woodinville, 1960)',[false,true,true,true]),
        new Photo(106,'Lake Washington Mist','The cold January dawn, unlimited visibility - the wispy sky, mists rising from the lake, and frozen dew glistening the branches.<br>(Seattle, January 1962)',[false,true,true,true]),
        new Photo(107,'La Conner Boats','Fishing boats in the mist.<br>(La Conner, 1957)',[false,false,true,false]),
        new Photo(108,'La Conner Bridge','Rainbow Bridge &amp; fishing boats.<br>(La Conner, 1957)',[false,false,true,false]),
        new Photo(109,'La Conner Nets','(LaConner, 1957)',[false,false,true,false]),
        new Photo(110,'Perfection','Overhead shot of the championship U of W 8-man crew.',[false,true,true,true]),
        new Photo(111,'Queen Anne Sculpture','View of Seattle &amp; Mt. Rainier from Kerry Park on Queen Anne Hill.<br>(Seattle, 1983)',[false,true,false,false]),
        new Photo(112,'Ranch Cat','(1975)',[false,true,true,false]),
        new Photo(113,'Sailing on Lake Washington','(1965)',[false,false,false,false]),
        new Photo(114,'Quintessential Seattle','(1977)',[true,true,true,true]),
        new Photo(115,'Seattle Spring','Sparkling sunlight and shadows of a crisp morning in June.<br>(Seattle, June 1964)',[false,true,true,true]),
        new Photo(116,'Serenity','A quiet nautical abstract from the Montlake Bridge.<br>(Seattle, 1957)',[false,false,false,false]),
        new Photo(117,'UW Scullers','U of W crews work out on a spring evening.<br>(Seattle, 1970)',[false,false,true,false]),
        new Photo(118,'Windermere Cup','',[false,false,true,true]),
        new Photo(201,'Floating Bridge Sunrise','',[false,true,false,false]),
        new Photo(202,'Mt. Shuksun','',[false,true,false,false]),
        new Photo(203,'Mukilteo Lighthouse','',[false,true,false,false]),
        new Photo(204,'Seattle Skyline','',[false,true,false,true]),
        new Photo(205,'UW Scullers','U of W crews work out on a spring evening.<br>(Seattle, 1970)',[false,false,true,false])
);

photos.indexFromID = function (which) {
        for (var i=0; i<this.length; i++) {
                if (which == this[i].id) return i;
        }
        return null;
}


function init()
{
        updatePics();
        document.getElementById("selected").innerHTML = SPECIAL_HTML;
		setTimeout("embedPlayer()",500);
}
// Embed the player - do this dynamically so the images are all loaded up first
function embedPlayer() {
	document.getElementById("mplayer").innerHTML = '<object id="scayleaMov" '+
    'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '+
    'codebase="http://www.apple.com/qtactivex/qtplugin.cab" '+ 
    'width="402" height="265"> '+
    '<param name="src" value="./Scaylea.mov" /> '+
    '<param name="controller" value="false" /> '+
    '<param name="autoplay" value="false" /> '+
    '<param name="loop" value="false" /> '+
    '<EMBED name="scayleaMov" '+
        'height="265" '+
        'width="402" '+
        'src="./Scaylea.mov" '+
        'type="video/quicktime" '+  
        'pluginspage="www.apple.com/quicktime/download" '+
        'controller="false" '+
        'autoplay="false" '+
        'loop="false" '+
    '/> '+
    '</object> ';
	
	setTimeout("controlMovie(true)",1000);
	checkMovieEnd();
}

function checkStarted()
{
	var pos = document.scayleaMov.GetTime() - 0;
	if (pos == 0) {
		movieState = "paused";
		controlMovie(true);
	}
}

function checkMovieEnd()
{
	//alert("checkMovieEnd()");
	try {
		var mov = document.scayleaMov;
		var pos = mov.GetTime() - 0;
		var dur = mov.GetDuration() - 0;
		//document.getElementById("mstat").innerHTML = "pos="+pos+", dur="+dur;
		if (pos >= dur) {
			mov.Rewind();
			document.getElementById("movieControl").src = "./images/play-button.gif";
			movieState = "rewound";
			return;
		}
	} catch (err) {
	}
	setTimeout("checkMovieEnd()",1000);
}

var COUNT = 0;

// Check the player - only start it once the movie is playable/completely loaded
function checkPlayer()
{
	mov = document.scayleaMov;
	if (mov == null) {
		//document.getElementById("mstatus").innerText = "null/" + (++COUNT);
		setTimeout("checkPlayer()",500);
		return;
	}
	status = mov.GetPluginStatus().toLowerCase();
	//document.getElementById("mstatus").innerText = status + "/" + (++COUNT);
	if (status == "complete" || status == "playable") {
		//document.getElementById("mstatus").innerText = "";
		setTimeout("controlMovie()",1000);
		return;
	}
	setTimeout("checkPlayer()",500);
}

function updatePics()
{
        var i, j, pic, picHTML;
        
        var tbl = document.getElementById("selectorTable");
        for (i=0; i<PIC_COLS; i++) {
                for (j=0; j<PIC_ROWS; j++) {
                        pic = PIC_START + i*PIC_ROWS + j;
                        picHTML = generateImageHtml(pic);
                        tbl.rows[j].cells[i].innerHTML = picHTML;
                }
        }
}

function cycle(dir)
{
        if (dir) {
        PIC_START += PIC_ROWS;
    } else {
        PIC_START -= PIC_ROWS;
    }
    if (PIC_START < 0) PIC_START = 0;
    if (PIC_START >= PICTURES.length) PIC_START = 0;
        updatePics();
}

function generateImageHtml(which)
{
        var s = '<a href="javascript:void(0);" onclick="showPicture(' + PICTURES[which] + ');"><img src="./images/th';
        if (which < PICTURES.length) {
                s += PICTURES[which] + 'x.jpg" ';
                s += 'onmouseover=this.style.borderColor="#e6e59d" ';
                s += 'onmouseout=this.style.borderColor="white"></a>';
                return s;
        } else {
                return "";
        }                               
}

var gCurrentPhoto = 0;
var gPic = new Image();
gPic.onload = picLoaded;

function showPicture(which)
{
        gCurrentPhoto = which;
        gPic.src = "./images/" + which + ".jpg";
}

function picLoaded()
{
        var which = gCurrentPhoto;
        var s = "";
        if (which == SPECIAL_ID) {
                document.getElementById("selected").innerHTML = SPECIAL_HTML;
        } else {
                s += generatePictureHTML(which);
                s += generatePriceTable(which);
                document.getElementById("selected").innerHTML = s;
        }
        return;
}

function generatePictureHTML(which)
{
        var idx = photos.indexFromID(which);
        var photo = photos[idx];
        //var s = '<a href="detail.html?id=' + photo.id + '">' + photo.title + '</a><br><img src="./images/' + which + '.jpg"><br><a href="detail.html?id=' + photo.id + '">' + photo.title + '</a>';
        var s = '<b>' + photo.title + '</b><br><img id="mainPhoto" src="./images/' + which + '.jpg"><br><b>' + photo.title + '</b>';
        s += '<div id="desc">' + photo.desc + '</div>';
        return s;
}

function rollover(img,hi)
{
        //alert(ARROWS[img][hi].src);
        document.getElementById(img).src = ARROWS[img][hi].src;
}

function randomPic()
{
        var s = "";
        var which = Math.floor(Math.random()*RANDOM_PICS.length);
        try {
        s += '<img style="border:solid #ffffff 1px; margin-bottom:5px;" src="./images/' + RANDOM_PICS[which] + 'x200.jpg"><br><em>' + photos[photos.indexFromID(RANDOM_PICS[which])].title + '</em>';
        } catch (err) {
                alert(which);
        }
        return s;
}

function randomFramed()
{
        var s = "";
        var which = Math.floor(Math.random()*RANDOM_FRAMED.length);
        try {
        s += '<img style="border:solid #ffffff 1px; margin-bottom:5px;" src="./images/' + RANDOM_FRAMED[which] + 'x200f.jpg"><br><em>' + photos[photos.indexFromID(RANDOM_FRAMED[which])].title + '</em>';
        } catch (err) {
                alert(which);
        }
        return s;
}

var img0 = new Image(); img0.src = "./images/lt-arrow.gif";
var img1 = new Image(); img1.src = "./images/lt-arrowh.gif";
var img2 = new Image(); img2.src = "./images/rt-arrow.gif";
var img3 = new Image(); img3.src = "./images/rt-arrowh.gif";
var ARROWS = new Array();
ARROWS["cycleLeft"] = [img0,img1];
ARROWS["cycleRight"] = [img2,img3];

// Some HTML to advertise a special
var SPECIAL_HTML =
        '<h2>Seafair Special!</h2>' +
        '<div style="font-size:13px; font-weight:bold;">For a limited time, SeattleGallery.com is offering Josef\'s classic shot of the Blue Angels\' final pass over the Seafair hydroplane course in 1978 at a substantial savings*.<br />' +
        '<img src="./images/114.jpg" /><br /><em><strong>Quintessential Seattle</strong></em><br /><br /><strong>Photographs <u>signed by Josef</u> &amp; available framed or unframed:</strong>' +
    '<table id="priceTable" align="center">' +
    '<tr align="right"><td align="center"><strong>Size</strong></td><td><strong>Unframed</strong></td><td><strong>Framed**</strong></td></tr>' +
    '<tr align="right"><td align="center">8"x10"</td><td>$80</td><td>$170</td></tr>' +
    '<tr align="right"><td align="center">11"x14"</td><td>$165</td><td>$300</td></tr>' +
    '<tr align="right"><td align="center">16"x20"</td><td>$250</td><td>$420</td></tr>' +
    '<tr align="right"><td align="center">20"x24"</td><td>$335</td><td>$535</td></tr>' +
    '</table>' +
    '<div style="margin:5px 0 0 15px; font-size:11px; text-align:left;">*Approximately <b>15%</b> off regular prices. Prices shown do not include sales tax and shipping &amp; handling.<div style="margin-top:5px;">**Framing may take up to 3 weeks.</div></div>' +
    '<div style="text-align:left; margin-top:10px; font-weight:bold;">Also available: unsigned high-quality posters of this amazing shot for $35 (regularly $55).</div>' +
        '</div>';
var SPECIAL_ID = 114;

function generatePriceTable(which)
{
        var photo = photos[photos.indexFromID(which)];
        var s = '';
        
        s += '<div style="font-weight:bold; padding-top:20px;">Availability</div>';
        s += '<table id="priceTable" align="center">';
        s += '<tr align="right"><td align="center">Size</td><td>Unframed</td><td>Framed*</td></tr>';
        for (var i=0; i<SIZES.length; i++) {
                s += '<tr align="right"><td align="center"><strong>' + SIZES[i] + '</strong></td>';
                if (photo.sizes[i]) {
                        s += '<td>$' + PRICES[i][false] + '</td>';
                        s += '<td>$' + PRICES[i][true] + '</td>';
                } else {
                        s += '<td><em>n/a</em></td><td><em>n/a</em></td>';
                }
                s += '</tr>';
        }
        s += '</table>';
        s += '<div style="margin-top:10px; font-size:11px; text-align:left;">**Framing may take up to 3 weeks.</div>';
        return s;
}





