// FAOS ShowCards display logic.
// =============================

function setup_showcards(){
    tt=9;                       // Number of shows
    startpoint=1;               // Where first show details start
    latest=81;                  // Latest show

// Showname
// Year
// Month (short name)
// Shortname (to identify files)

// Image names must be: SHORTNAME-Front.jpg & SHORTNAME-Rear.jpg SHORTNAME-Thumb.jpg
// Image location must be: images/showcards

// Array details:
// [1] Showname
// [2] Year
// [3] Month
// [4] Shortname (used in filename)

    showdetails =new Array(80);
    showdetails[1]="Best Little Whorehouse in Texas";
    showdetails[2]=2003;
    showdetails[3]="Jun";
    showdetails[4]="BLWIT";
    
    showdetails[11]="Carmen";
    showdetails[12]=2004;
    showdetails[13]="Jan";
    showdetails[14]="Carmen";

    showdetails[21]="Sweet Charity";
    showdetails[22]=2004;
    showdetails[23]="Jun";
    showdetails[24]="SC";
    
    showdetails[31]="Blitz";
    showdetails[32]=2005;
    showdetails[33]="Jan";
    showdetails[34]="Blitz";

    showdetails[41]="South Pacific";
    showdetails[42]=2005;
    showdetails[43]="Jun";
    showdetails[44]="SP";
    
    showdetails[51]="Jesus Christ Superstar";
    showdetails[52]=2006;
    showdetails[53]="Jan";
    showdetails[54]="JCS";
    
    showdetails[61]="Fiddler on the Roof";
    showdetails[62]=2006;
    showdetails[63]="Jun";
    showdetails[64]="FOTR";
    
    showdetails[71]="Yeomen of the Guard";
    showdetails[72]=2007;
    showdetails[73]="Jan";
    showdetails[74]="YOTG";
    
    showdetails[81]="Anything Goes";
    showdetails[82]=2007;
    showdetails[83]="Jan";
    showdetails[84]="AG"

	tpp=3;                         // thumbnails per page

    // Check if thumbs fit page exactly
    numchk=tt/tpp;
    rmdr=0;
    if (numchk != parseInt(numchk)){        // Check for integer
        rmdr=tt%tpp;                        // Find remainder
        rmdr=tpp-rmdr;                      // Thumbs not shown -> rmdr
        }
    // Find out how many pages of thumbs will be displayed -> PageCount
    PageCount=Math.ceil(numchk);            // Round up numchk

    // Clear default messages in html page
    document.getElementById("showname").innerHTML = "<br>";
    document.getElementById("showtitle").innerHTML = "";
    document.getElementById("flipside").innerHTML= "";

    setup_pages(PageCount,rmdr,tt,latest);
    }
//### SETUP DATA READY TO USE ###
// Assign Thumbnails, Pictures and Pages to arrays
function setup_pages(PageCount,rmdr,tt,latest){
    // Assign Filenames (for thumbnails)
    recent=latest;
    Filename=new Array(tt);
	for (x=1;x<=tt;x++){
    	Filename[x]="images/showcards/"+showdetails[recent+3]+"-Thumb"+".jpg";
        recent=recent-10;
        }

    // Assign Filenames (for front of showcards)
    recent=latest;
	Picture=new Array(tt);
	for (x=1;x<=tt;x++){
    	Picture[x]="images/showcards/"+showdetails[recent+3]+"-Front"+".jpg";
        recent=recent-10;
        }

    // Assign Filenames (for rear of showcards)
    recent=latest;
	Rear=new Array(tt);
	for (x=1;x<=tt;x++){
    	Rear[x]="images/showcards/"+showdetails[recent+3]+"-Rear"+".jpg";
        recent=recent-10;
        }

    // Assign Show Titles (for Mouseover & Select)
    recent=latest;
	Titles=new Array(tt);
	for (x=1;x<=tt;x++){
    	Titles[x]=showdetails[recent];
        recent=recent-10;
        }

    // Assign Show Details (for Select)
    recent=latest;
	Details=new Array(tt);
	for (x=1;x<=tt;x++){
    	Details[x]=showdetails[recent+2]+" "+showdetails[recent+1];
        recent=recent-10;
        }

    // Assign Pages
    Pages=new Array(tt);
    z=1;
    t=tpp;
	for (x=1;x<=PageCount;x++){
        for (y=z;y<=t;y++){
            Pages[z]=x;
            z++;
            }
        t=t+t;
        }

    PageID=1;
    display_thumbs(PageID);
    }

//### DISPLAY THUMBNAILS ###
// Main thumbnail display routine
function display_thumbs(PageID){
    // Clear place holders first
    for (x=1;x<=tpp;x++){
        html='<Img src="spacer.gif" border="0" alt="" width="10" height="10">';
        document.getElementById("p"+x).innerHTML = html;
        }
    // Create array for thumbs in the PageID
    Thumbs=new Array(tpp)
    for (x=1;x<=tt;x++){
        if (Pages[x]==PageID){
            Thumbs[x]=Filename[x];
            }
        else {
            Thumbs[x]="";
            }
        }
    a1='<a href="Javascript:onClick=ShowPic(';  // Open anchor start JS
    a2=')" onMouseover="GetTitle(';             // Continu JS
    a3=')">';                                   // Close end of open
    a4='</a>';                                  // Close anchor
    y=1;
    for (x=1;x<=tt;x++){
        if (Thumbs[x]!=""){
            html='<Img src="'+Thumbs[x]+'" border="0" alt="">';
            document.getElementById("p"+y).innerHTML = a1+x+a2+x+a3+html+a4;
            y++;
            }
        }
    display_navigation(PageID);
    }

//### NAVIGATION ###
// Back and Next navigation logic
function display_navigation(PageID){
    Back="No";
    Next="No";
    // Define Font colours when Back and Next are not links
    f1='<FONT color="#C0C0C0">';
    f2='</FONT>';
    if (PageID-1>0 && PageID-1<PageID){
        Back="Yes";
        }
    if (PageID+1<=PageCount && PageID+1>PageID){
        Next="Yes";
        }
    if (Back == "Yes"){
        NewPageID=PageID-1;
        document.getElementById("back").innerHTML="<a href='Javascript:onClick=display_thumbs("+NewPageID+")'>&#171; Back</a>";
        }
    else {
        document.getElementById("back").innerHTML=f1+"&#171; Back"+f2;
        }
    if (Next == "Yes"){
        NewPageID=PageID+1;
        document.getElementById("next").innerHTML="<a href='Javascript:onClick=display_thumbs("+NewPageID+")'>Next &#187;</a>";
        }
    else {
        document.getElementById("next").innerHTML=f1+"Next &#187;"+f2;
        }
    }

//### SHOW PICTURES ###
// Show pictures when a thumbnail is clicked
function ShowPic(picID){ // Called when thumbnail is clicked
    document.images['pic2view'].src = Picture[picID];
    document.getElementById("showtitle").innerHTML="<h2>"+Titles[picID]+", "+Details[picID]+"</h2>";
    document.getElementById("flipside").innerHTML='<a href="Javascript:onClick=FlipSide('+picID+')">View Rear</a>';
    }

// ### GET TITLES FOR HOVER-OVER ###
function GetTitle(picID){
    document.getElementById("showname").innerHTML=Titles[picID];
    }

// ### SWAP IMAGE FOR FLIPSIDE ###
function FlipSide(picID){
    // Get image properties & workout if its Front or Rear
    fn = document.images['pic2view'].src;
    fnl=fn.length;
    fnsubstr=fn.substring(fnl-9,fnl-4);
    // If its front, show rear and vice versa
    if (fnsubstr == "Front"){
        document.images['pic2view'].src = Rear[picID];
        document.getElementById("flipside").innerHTML='<a href="Javascript:onClick=FlipSide('+picID+')">View Front</a>';
        }
    else {
        document.images['pic2view'].src = Picture[picID];
        document.getElementById("flipside").innerHTML='<a href="Javascript:onClick=FlipSide('+picID+')">View Rear</a>';
        }
    }


