// scriptmaster=greg@imaja.com
// functions: makeProductInfo displayListView writePayPalButton addAttribute 
//     closetag addProductRec viewaslist

var fieldNames = "title,subtitle,description,image,url,price,upgradeprice,shipping";

var fieldnamearray = fieldNames.split(",");

// Array of title,subtitle,description,image,url,price,upgradeprice,shipping
function makeProductInfo(title,subtitle,description,image,url,price,upgradeprice,shipping) {
  this.title = title;
  this.subtitle = subtitle;
  this.description = description;
  this.image = image;
  this.url = url;
  this.price = price;
  this.upgradeprice = upgradeprice;
  this.shipping = shipping;
  // method assignment
  this.displayListView = displayListView;
}

// Array of title,subtitle,description,image,url,price,upgradeprice,shipping
function displayListView(index, includegraphics, includeupgradeprice, displayWholesalePrices) {

   // begin item row
   var twocolversion = false;
   if (twocolversion) { 
     document.write("<tr><td colspan='2'>"); 
    } else {
      document.write("<tr><td>");
	}
/*	
    document.write('<table background="http://imaja.com/images/line-blue-grad2.gif" width="100%" height="1px" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table>');
*/
    document.write("</td></tr>");

    document.write("<tr><td valign='top'>");

    if (includegraphics && this.image != "") {
      var imagestr = "<img";
      imagestr = addAttribute(imagestr, "src", "http://www.imaja.com/" + this.image);
      if (twocolversion) {
	    //  
      } else {      
        imagestr = addAttribute(imagestr, "align", "right");
        imagestr = addAttribute(imagestr, "hspace", "3");
        imagestr = addAttribute(imagestr, "vspace", "3");
      }
      imagestr = addAttribute(imagestr, "width", "80");
      imagestr = addAttribute(imagestr, "height", "80");
      imagestr = addAttribute(imagestr, "border", "0");
      imagestr = addAttribute(imagestr, "class", "imageborder");     
      imagestr = closetag(imagestr);
      if (this.url == "") {
        document.write(imagestr);
      } else {
        document.write("<a href='" + "/" + this.url + "'>" + imagestr + "</a>");
      }
    }

   if (twocolversion) { 
      document.write("</td><td valign='top'>");
    } else {
      
	}
	
  // begin title cell

  var thetitle = "<span class='largebody'>" + this.title + "</span>";
  var itemname =  this.title;
  var selleremail = "greg@imaja.com";
  var wholesalePrice = "";
  var truncLength = 0;
  document.write("<span class='calloutmedium'>"); 
  document.write(thetitle.link("/"+this.url));
  document.write("</span>");
  document.write("<br>");
  document.write(this.subtitle);

  if (includegraphics) {
    document.write("<br><font color='#888888'>" + this.description + "</font><br clear='all'>");
  }
  
  if (includegraphics) {
    document.write("<table border='0' cellpadding='1' cellspacing='0' width='100%'><tr><td>");
  } else {
    document.write("<table border='0' cellpadding='1' cellspacing='0' width='100%'><tr><td>");
  }
  if (!displayWholesalePrices && this.price != "") {
    writePayPalButton(selleremail, this.price, itemname, this.shipping, "");
  }
  document.write("</td><td>");
  if (includeupgradeprice) {
    if (this.upgradeprice != "") {
      itemname = itemname + " Upgrade";
      writePayPalButton(selleremail, this.upgradeprice, itemname, this.shipping, "Upgrade: ");
    }
  }
  document.write("</td></tr></table>");

  if (displayWholesalePrices && this.price != "") {
    wholesalePrice = " " + this.price * 0.6; // have to add a space to make it a string
    truncLength = wholesalePrice.indexOf(".", 0) + 3;
    wholesalePrice = wholesalePrice.substring(0, truncLength);
    if (wholesalePrice.indexOf(".", 0) == wholesalePrice.length-2) {
      wholesalePrice = "" + wholesalePrice + "0";
    }
    wholesalePrice = wholesalePrice.substring(1, wholesalePrice.length);
    itemname = itemname + " Wholesale";
    writePayPalButton(selleremail, wholesalePrice, itemname, this.shipping, "<b>Wholesale: </b>");
  }

  document.write("</td></tr>");
}

function writePayPalButton(selleremail, price, itemname, shipping, labeltext)
{
    //  document.write("<br>"); bgcolor='#eeeeee'
  document.write("<table width='100%' cellpadding='2' cellspacing='1' border='0'><tr><td align='right'  valign='middle'>");

  document.write("<p>" + labeltext + "$" + price + "</p>");

  document.write("</td><td valign='middle' halign='left'>");

  document.write('<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin:0px;">');
  document.write('<input type="hidden" name="cmd" value="_cart">');
  document.write('<input type="hidden" name="business" value="' + selleremail + '">');
  document.write('<input type="hidden" name="item_name" value="' + itemname + '">');
  document.write('<input type="hidden" name="amount" value="' + price + '">');
  if (shipping != "") {
    document.write('<input type="hidden" name="shipping" value="' + shipping + '">');
  }
//  document.write('<input type="hidden" name="image_url" value="https://imaja.com/secure/logo-imaja-paypal.jpg">');
  document.write('<input type="hidden" name="return" value="http://www.imaja.com/store/paymentsuccess.html">');
  document.write('<input type="hidden" name="cancel_return" value="http://www.imaja.com/store/paymentcancelled.html">');
  document.write('<input type="hidden" name="cn" value="Optional Special Instructions">');
//  document.write('<input type="image" src="http://www.imaja.com/images/AddToCartSm.jpg" border="0" name="submit" alt="Add to Cart">');
  document.write('<input type="submit" class="ppbutton" value="Add to Cart" name="submit" alt="Add to Cart">');
  document.write('<input type="hidden" name="add" value="1">');
  document.write('</form>');
  
  document.write("</td></tr></table>");

}

function addAttribute(tagstring, attrname, attrvalue) {
  tagstring = tagstring + " " + attrname + "='" + attrvalue + "'";
  return tagstring;
}

function closetag(str) {
  return str + ">";
}

var gProductRecs = new Array(40);
var gProductRecCount = 0;

function addProductRec(title, subtitle, description, image, url, price, upgradeprice, shipping)
{
  gProductRecs[gProductRecCount] = new makeProductInfo(title, subtitle, description, image, url, price, upgradeprice, shipping);
  gProductRecCount++;
}


// template
// addProductRec(  title, subtitle, description, image, url, price, upgradeprice, shipping  );

// <img height='56' width='70' src='blisspaint/images/MW4.5MiceLogo.gif' align='right'>
addProductRec(  "Systems Mirror Vol. 1", "Content Management Systems report", "Imaja has been deeply involved in evaluating web content management systems and is about to release a compendium of information related to this research phase. Now taking advance orders.", "", "", "29.95", "29.95", "");

// <font color='red'>NEW VERSION 2.4:</font> 
//  <font color='red'><b>NEW</b></font>

addProductRec(  "Bliss Paint", "Interactive animation system", "Create dazzling light shows for live music or video, trigger animations with MIDI and sound input, generate QuickTime.", "blisspaint/images/BlissPaintCDCover.jpg", "blisspaint/index.html", "149.95", "20.00", "");

addProductRec(  "Bliss Bundle", "Animation system of all six Bliss packages", "The Bliss Bundle includes all six Bliss packages: Bliss Paint, Bliss Saver, Waves of Bliss, Space Garden Meditations, Geometric Bliss and Bliss Gallery.", "blisspaint/images/BlissPaintCDCover.jpg", "blisspaint/index.html", "265.79", "", "");

addProductRec(  "Space Garden Meditations", "Fantastic plant and geometry screen saver", "Virtual gardens of color plant shapes create a dazzling interactive display.", "sgm/images/SpaceGardenCDCover.jpg", "sgm/index.html", "49.95", "20.00", "" );

addProductRec(  "Bliss Saver", "Beautiful flowing color art screen saver toy!", "This amazing interactive animation toy and screen saver features keyboard access to animations and effects.", "blisssaver/images/BlissSaverCDCover.jpg", "blisssaver/index.html", "29.95", "20.00", ""  );

addProductRec(  "Bliss Saver (French version)", "Beautiful flowing color art screen saver toy!", "<font color=red>New version 2.3.4</font>. This amazing interactive animation toy and screen saver features keyboard access to animations and effects.", "blisssaver/images/BlissSaverCDCover.jpg", "BlissSaverF.html", "29.95", "20.00", ""  );

addProductRec(  "Waves of Bliss", "Dynamic animations and plug-ins", "These animations and plug-ins extend the range of shapes and patterns for Bliss Paint. Now includes Bliss Saver engine!", "wavesofbliss/images/wavesofblissthumbnail.jpg", "wavesofbliss/index.html", "59.95", "20.00", ""  );

addProductRec(  "Geometric Bliss", "Kaleidoscopic screen saver and plug-ins", "<font color=red>New version 2.3.4</font>. These geometric animations and plug-ins add hexagon and diamond tiling patterns to Bliss Paint. Now includes Bliss Saver engine!", "geometric/images/geometricblissthumbnail.jpg", "geometric/index.html", "39.95", "20.00", ""  );

addProductRec(  "Bliss Gallery", "Animation collection", "This large collection adds hours of dazzlingly composed animations to Imaja's Bliss Paint and Bliss Saver animation programs.", "blissgallery/images/blissgallerythumbnail.jpg", "blissgallery/index.html", "19.95", "20.00", ""  );

addProductRec(  "Astral Blossom", "Fantastic Mac OS X Universal screen saver", "Snow Leopard compatible. Beautiful new color themes. Speed control. Dazzle your eyes and sooth your spirit with evolving, luminous, geometric mandala art. <font color='red'><b>NEW: 2.2</b></font>", "astralblossom/images/AstralBlossom22-iconMedium.png", "astralblossom/index.html", "9.95", "4.95", "0.00"  );

addProductRec(  "ProtoFont", "A font library browser for graphic designers", "Quick browsing and spec sheets of your font library, even if fonts are not installed in your system.", "protofont/images/ProtoFontCDCover.jpg", "protofont/index.html", "49.95", "20.00", ""  );

addProductRec(  "Imaja Font Collection #1", "A collection of original headline fonts", "These fonts will spice up your graphic design with unique flavors.", "fontcollection/images/ImajaFontCollectionCDCover.jpg", "fontcollection/index.html", "100.00", "20.00", ""  );

addProductRec(  "Imaja Reminder", "Personal calendar, address book and to-do list", "Imaja Reminder features: color-coded events, text import/export, advanced warnings, auto-rescheduling, export to HTML, a window layout manager, mailing label printing and more.", "reminder/images/ReminderCDCover.jpg", "reminder/index.html", "49.95", "20.00", ""  );

addProductRec(  "Listen", "Music ear training for students and pros (E-mail delivery)", "Listen is an effective tool for improving your musicianship, great for home, school and studio users.", "listen/images/ListenCDCover.jpg", "listen/index.html", "79.95", "40.00", ""  );

addProductRec(  "Solkattu Workshop", "Indian music notation layout", "Solkattu Workshop is a layout program for Indian rhythmic and melodic notation.", "", "solkattuworkshop/index.html", "49.95", "20.00", ""  );

addProductRec(  "Edly's Music Theory for Practical People", "A friendly illustrated approach", "This book is for anyone, teen to adult, who wants to learn what's going on inside music.", "edly/images/edlysmusictheory-80w.jpg", "edly/index.html", "27.00", "", "0.00"  );

addProductRec(  "Edly Paints the Ivories Blue", "Beginning piano book with a blues style", "This book is a blues-based, improvisation-friendly alternative piano method and supplement.", "", "ivoriesblue/index.html", "14.00", "", "0.00"  );

addProductRec(  "Chronos", "Multimedia history timeline toolkit", "Chronos provides a flexible history timeline display including popup notes, images, QuickTime movies and audio.", "chronos/images/chronos-thumbnail80px.jpg", "chronos/index.html", "49.95", "20.00", ""  );

addProductRec(  "September", "Art and music anthology (VHS video)", "This non-narrative video is an anthology of several years of work by Imaja.", "media/september/images/septembercdcover.jpg", "media/september/index.html", "19.95", "", "4.00"  );

addProductRec(  "Rainwater", "Art and music CD-ROM experience", "Over 200 paintings, drawings, digital art and a 36 minute ambient textural soundscape. For Mac OS 9 or Mac OS X wih Classic.", "media/rainwater/images/rainwatercdcover.jpg", "media/rainwater/index.html", "39.95", "20.00", ""  );

addProductRec(  "PicScan", "Dynamic slideshows and thumbnails for Mac OS X Universal and Mac OS 9", "Power-user interactive slideshow and thumbnail image browser for your photos or artwork. <font color='red'><b>NEW: 2.1.1</b></font>", "picscan/images/PicScan-cdcover.jpg", "picscan/index.html", "19.95", "10.00", ""  );

addProductRec(  "Texplore", "Fast text editing with macros for web page authoring", "Texplore is a fast text editor that has a simple macro system with a set of HTML macros for Web page editing. It also makes reading text documents on your screen easier with it's smooth auto-scrolling capabilities.", "texplore/images/texplore-cdcover.jpg", "texplore/index.html", "20.00", "5.00", ""  );

addProductRec(  "Train Trip November", "Landscape photography and original music with guitar and electronics. <font color='red'>DVD Video</font>", "A cross-country train trip, captured in these fascinating landscape images with an original soundtrack of guitar, synthesizers and ambient soundscapes.", "media/traintripnovember/images/TrainTripNovember-cover100s.jpg", "media/traintripnovember/index.html", "39.95", "", "4.00" );

addProductRec(  "Altered States", "Four decades of light shows with music <font color='red'>DVD Video</font>", "Glenn McKay's legendary light shows with music by the Jefferson Airplane, Knox Bronson, Dean Evenson and Greg Jalbert.", "media/alteredstates/alteredstatescdcover.jpg", "media/alteredstates/index.html", "39.95", "", "4.00" );

addProductRec(  "No Strings Attached", "Glenn McKay's brilliant light art. <font color='red'>VHS Video</font>", "Short visual poems evoke deep space and one's inner voice as music of Celtic harp, North Indian sarod, and contemporary cello and synthesizers gently sound.", "media/nostringsattached/nostringsattached-80w.jpg", "media/nostringsattached/index.html", "39.95", "", "4.00" );

addProductRec(  "Design Portfolio", "Graphic, web and database", "From graphic design to database design and programming, Imaja offers consulting services.", "webportfolio/images/thumbnail.jpg", "webportfolio/index.html", "", "", "" );

addProductRec(  "Imaja Art Gallery", "Paintings, drawings and digital art", "Complex layered images are showcased in the online gallery.", "artwork/images/artwork-thumbnail.jpg", "artwork/index.html", "", "", "" );

addProductRec(  "Guitar July", "Music CD", "Imaja - Greg Jalbert journeys through guitar instrumentals and songs with influences from world music, jazz, folk, dance grooves.", "images-products/guitar-july-080.jpg", "guitarjuly/index.html", "16.95", "", "2.00"  );

addProductRec(  "October Sound Paintings", "Music CD", "Live improvisations by Greg Jalbert on keyboard synthesizers and Rob Lonsdale on guitar synthesizer. ", "octobersoundpaintings/October-Sound-Paintings-100.jpg", "octobersoundpaintings/index.html", "16.95", "", "2.00"  );

addProductRec(  "Long Sun Work Day", "Music CD", "Exuberant electronic/dance music by Imaja - Greg Jalbert on keyboard synthesizers.", "images-products/long-sun-work-day-100.jpg", "longsunworkday/index.html", "16.95", "", "2.00"  );

addProductRec(  "Goldfish Sage Flower", "Music CD", "Live improvisations by Greg Jalbert on keyboard synthesizers and Rob Lonsdale on guitar and drum. This comes from one of several sessions where Jalbert and Lonsdale were performing music to accompany a visual light projections by Glenn McKay, pioneer light artist from the 1960's. This recording was made in the mid-1990's in Sausalito, California.", "goldfishsageflower/Goldfish-Sage-Flower-150px.jpg", "goldfishsageflower/index.html", "16.95", "", "2.00"  );

addProductRec(  "Chants and Praises", "Music CD", "Marimba Pacifica's juicy mix of cultures comes together here with African, Latin, Jazz and Reggae, with vital dance grooves and fabulous solos and vocals.", "images-products/chantsandpraises80.jpg", "media/index.html", "16.95", "", "2.00"  );

addProductRec(  "Groundswell", "Music CD", "Terra Nova features vocal harmony and interesting music fusing California string band and space beat world-musics, with strange voices from experimental instruments.", "images-products/groundswell80.jpg", "media/index.html", "16.95", "", "2.00"  );

addProductRec(  "Horse of Stone", "Music CD", "The Cormack and Ross band features dazzling interlocking guitars and voices with seasoned drums and saxophone, global jazz songs with delightfully cryptic lyrics.", "images-products/horseofstone80.jpg", "media/index.html", "16.95", "", "2.00"  );

addProductRec(  "The Rain Takes Off Her Clothes", "Music CD", "Tom Ross presents these juicy poems over funky world guitar grooves, global jazz songs with delightfully cryptic lyrics.", "images-products/raintakesoff80.jpg", "media/index.html", "16.95", "", "2.00"  );

addProductRec(  "Star of the Sea", "Music CD", "Stellamara's powerful yet ethereal vocals ride strong rhythms drawing on many Eastern and Middle Eastern traditions.", "images-products/starofthesea080.jpg", "media/index.html", "16.95", "", "2.00"  );

addProductRec(  "The Seven Valleys", "Music CD", "Stellamara draws us into deep meditation on world beauty and spirituality with vocals and strong rhythms drawing on many Eastern and Middle Eastern traditions.", "images-products/sevenvalleys080.jpg", "media/index.html", "16.95", "", "2.00"  );

addProductRec(  "The Vine", "Music CD", "Kitka builds dazzling bouquets of flowers with acapella vocals and a variety of guest artists, drawing on Eastern Europe traditions and modern settings.", "images-products/thevine080.jpg", "media/index.html", "16.95", "", "2.00"  );

// addProductRec( title, subtitle, description, image, url, price, upgradeprice, shipping );


function viewaslist(featurednames, includegraphics, includeupgradeprice) {
  var featuredarray = featurednames.split(",");
  var featureindex;
  var itemindex;
  var displayWholesalePrices = false;
  for (featureindex=0; featureindex < featuredarray.length; featureindex++) {
    for (itemindex=0; itemindex < gProductRecCount; itemindex++ ) {
      if (gProductRecs[itemindex].title == featuredarray[featureindex]) {
	    document.write("<table width='100%' cellpadding='2' cellspacing='0' class='producttable'>");
        gProductRecs[itemindex].displayListView(itemindex, includegraphics, includeupgradeprice, displayWholesalePrices);
		document.write("</table>");
      }
    }
  }
  
}

// examples:
// parameters: featurednames, includegraphics, includeupgradeprice
// viewaslist("Astral Blossom,Bliss Saver,Bliss Paint 2,ProtoFont,Listen", true, false);
// viewaslist("Chronos,Edly's Music Theory for Practical People", false, false);

function wholesaleList(featurednames) {
  var featuredarray = featurednames.split(",");
  document.write("<table width='100%' cellpadding='1' cellspacing='0'>");
  var featureindex;
  var itemindex;
  var displayWholesalePrices = true;
  var includegraphics = false;
  var includeupgradeprice = false;
  for (featureindex=0; featureindex < featuredarray.length; featureindex++) {
    for (itemindex=0; itemindex < gProductRecCount; itemindex++ ) {
      if (gProductRecs[itemindex].title == featuredarray[featureindex]) {
        gProductRecs[itemindex].displayListView(itemindex, includegraphics, includeupgradeprice, displayWholesalePrices);
      }
    }
  }
  document.write("</table>");
}

// examples:
// wholesaleList("Astral Blossom,Bliss Saver,Bliss Paint 2,ProtoFont,Listen");