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

var fieldNames = "title,subtitle,description,image,url,price,upgradeprice,shipping";
var IPSIncludeDescriptions = true;
var IPSIncludePaypalButton = true;
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;
  this.displayIconView = displayIconView;
}

// 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, "title", this.title); //  + ": " + this.subtitle
      // 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 (IPSIncludeDescriptions) {
    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 (IPSIncludePaypalButton && !displayWholesalePrices && this.price != "") {
    writePayPalButton(selleremail, this.price, itemname, this.shipping, "");
  }
  document.write("</td><td>");
  if (IPSIncludePaypalButton && includeupgradeprice) {
    if (this.upgradeprice != "") {
      itemname = itemname + " Upgrade";
      writePayPalButton(selleremail, this.upgradeprice, itemname, this.shipping, "Upgrade: ");
    }
  }
  document.write("</td></tr></table>");

  if (IPSIncludePaypalButton && 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>");
} // displayListView

// Array of title,subtitle,description,image,url,price,upgradeprice,shipping
function displayIconView(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("</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", "left");
        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, "title", this.title); //  + ": " + this.subtitle
      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 truncLength = 0;
//  document.write("<span class='calloutmedium'>"); 
//  document.write(thetitle.link("/"+this.url));
//  document.write("</span>");

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


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'>
// <font color='red'>NEW VERSION 2.4:</font> 
//  <font color='red'><b>NEW</b></font>

// Build product database:

addProductRec(  "TaskInsight", "Essential Task Management: Timeline and list views, priorities, color-coding, labels, dates. (Mac OS X 10.6 or 10.7, Snow Leopard or Lion) <font color='lightgray'><b>(Version 3.0.2)</b></font>", "TaskInsight provides full featured tools for task organization, drag and drop, import/export, auto/manual sort, search filtering, customizable colors, and more...", "taskinsight/images/TaskInsight2AppIcon256.png", "taskinsight/index.html", "", "", "");

addProductRec(  "CalReader", "Calendar Readability, Filtering, Time Calculations and Export for iPhone/iPod touch/iOS <font color='lightgray'><b>(Version 2.0)</b></font>", "CalReader features useful new functions for working with your business and productivity calendars. Syncs  with iCal, MobileMe, Google and Yahoo CalDAV Calendars", "calreader/images/Icon@2x.png", "calreader/index.html", "", "", "");

addProductRec(  "Astral Blossom", "Fantastically colorful mesmerizing geometric screen saver animations (Mac OS X) <font color='lightgray'><b>(Version 2.2)</b></font>", "Beautiful new color themes. Speed control. Dazzle your eyes and sooth your spirit with evolving, luminous, geometric mandala art.", "astralblossom/images/AstralBlossom22-iconMedium.png", "astralblossom/index.html", "9.95", "4.95", "0.00"  );

addProductRec(  "The Golden E-A-R", "Renaissance to Modern Guitar Music (PDF eBook) <font color='red'><b>NEW</b></font>", "A Historically organized compilation (90 pages from the Renaissance to Modern) of the most accessible  and attractive music ever assembled between two covers... guaranteed! This is a must for any avid guitarist. Includes opus and source info, chord symbols and minimal fingering!", "goldenear/images/Gear-ColorCvr03Sq-100w.jpg", "goldenear/index.html", "16.95", "", "0.00"  );

addProductRec(  "Guitar Geometry", "shape up your playing (PDF eBook) <font color='red'><b>NEW</b></font>", "Like a swiss-army-knife, this workbook is compact, but it still contains nearly all of the tools and maps you will need, in order to reach your destination.", "guitargeometry/images/guitargeometry-square100w.jpg", "guitargeometry/index.html", "14.95", "", "0.00"  );

addProductRec(  "PicScan", "Dynamic interactive slideshows and thumbnails (Mac OS X 10.3 and earlier & Mac OS 9)", "Power-user interactive slideshow and thumbnail image browser for your photos or artwork.", "picscan/images/PicScan-cdcover.jpg", "picscan/index.html", "19.95", "10.00", ""  );

addProductRec(  "Bliss Paint", "Interactive animation system (Mac OS 9)", "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 (Mac OS 9)", "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 (Mac OS 9)", "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! (Mac OS 9)", "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! (Mac OS 9)", "<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 (Mac OS 9)", "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 (Mac OS 9)", "<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 for Bliss Paint or Bliss Saver (Mac OS 9)", "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(  "ProtoFont", "A font library browser for graphic designers (Mac OS 9)", "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 (Mac OS 9)", "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 (Mac OS 9)", "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 (Mac OS 9)", "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 (Mac OS 9)", "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(  "Texplore", "Fast text editing with macros for web page authoring (Mac OS 9)", "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 Glenn McKay's psychedelic light shows with music <font color='red'>DVD Video</font>", "This video captures McKay's main installation piece at a retrospective of four decades of his work at the San Francisco Museum of Modern Art. Glenn McKay composes four 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, inspired by visual art projections of Glenn McKay.", "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, 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(  "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", "");

// 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>");
      }
    }
  }
  
}

function viewasicongrid(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("<div >");
        gProductRecs[itemindex].displayIconView(itemindex, includegraphics, includeupgradeprice, displayWholesalePrices);
		document.write("</div>");
      }
    }
  }
  
}


// 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");
