
//-----------------------------------
// Show and individual book
//-----------------------------------
if (indigo_type == "book")
{
      if (indigo_target == "bookpage")
      { document.writeln("<FORM METHOD=POST ACTION=\"http://www.indigocafe.com/bookstore/book.php\">"); }
      if (indigo_target == "bag")
      { document.writeln("<FORM METHOD=POST ACTION=\"http://www.indigocafe.com/store/addto_shoppingbag.php\">"); }

      document.writeln("<INPUT TYPE=HIDDEN NAME=AFFL_ID VALUE="+ indigo_id +">");
      document.writeln("<INPUT TYPE=HIDDEN NAME=TC VALUE="+ indigo_code +">");
     	tens = indigo_code % 100;
    	img_dir = indigo_code - tens;

    	path = "http://www.indigocafe.com/bookstore/img/" + img_dir + "/" + indigo_code + ".jpg";
	document.writeln("<INPUT TYPE=IMAGE SRC=" + path + " BORDER=1>");
	document.writeln("</FORM>");
}

//-----------------------------------
// Show the indigo "buy" button
//-----------------------------------
if (indigo_type == "button")
{
      if (indigo_target == "bookpage")
      { document.writeln("<FORM METHOD=POST ACTION=\"http://www.indigocafe.com/bookstore/book.php\">"); }
      if (indigo_target == "bag")
      { document.writeln("<FORM METHOD=POST ACTION=\"http://www.indigocafe.com/store/addto_shoppingbag.php\">"); }

      document.writeln("<INPUT TYPE=HIDDEN NAME=AFFL_ID VALUE="+ indigo_id +">");
      document.writeln("<INPUT TYPE=HIDDEN NAME=TC VALUE="+ indigo_code +">");

    	path = "http://www.indigocafe.com/store/order.jpg";    	
	document.writeln("<INPUT TYPE=IMAGE SRC=" + path + " BORDER=1>");
	document.writeln("</FORM>");
}

//-----------------------------------
// Show different book per pageview
//-----------------------------------
if (indigo_type == "pageview")
{
      var book_code = new Array();
      var book_img = new Array();
      var book_link = new Array();

      book_img[0] = new Image();
      book_img[1] = new Image();
      book_img[2] = new Image();
      book_img[3] = new Image();
      book_img[4] = new Image();
      
      book_code[0] = indigo_code1;
      book_code[1] = indigo_code2;
      book_code[2] = indigo_code3;
      if (indigo_code4) { book_code[3] = indigo_code4; }
      if (indigo_code5) { book_code[4] = indigo_code5; }
      var total_images = book_code.length;
      
	var image_index;
	var newValue = getCookie( 'bookIndex' );
 
	if  ((newValue == 'NaN') || (!newValue) || (newValue >= total_images )) 
	{  
		newValue = 1;
		setCookie( 'bookIndex', newValue, 30, '/', document.domain, '' ); 
	}
     	if (newValue == total_images) { newValue = 0; }

    	image_index = newValue;
	newValue++;
 
	setCookie( 'bookIndex', newValue, 30, '/', document.domain, '' );

      if (indigo_target == "bookpage")
      { document.writeln("<FORM METHOD=POST ACTION=\"http://www.indigocafe.com/bookstore/book.php\">"); }
      if (indigo_target == "bag")
      { document.writeln("<FORM METHOD=POST ACTION=\"http://www.indigocafe.com/store/addto_shoppingbag.php\">"); }

      document.writeln("<INPUT TYPE=HIDDEN NAME=AFFL_ID VALUE="+ indigo_id +">");
      document.writeln("<INPUT TYPE=HIDDEN NAME=TC VALUE="+ book_code[image_index] +">");
     	tens = book_code[image_index] % 100;
    	img_dir = book_code[image_index] - tens;

    	path = "http://www.indigocafe.com/bookstore/img/" + img_dir + "/" + book_code[image_index] + ".jpg";
	document.writeln("<INPUT TYPE=IMAGE SRC=" + path + " BORDER=1>");
	document.writeln("</FORM>");

}



//-----------------------------------
//-----------------------------------
function setCookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
     if ( expires )
     {
     expires = expires * 1000 * 60 * 60 * 24;
     }
     var expires_date = new Date( today.getTime() + (expires) );
     
     document.cookie = name + "=" +  escape(value)  +
     ( ( expires ) ? "; expires=" + expires_date.toGMTString() : "" ) + 
     ( ( path ) ? "; path=" + path : "" ) + 
     ( ( domain ) ? "; domain=" + domain : "" ) + 
     ( ( secure ) ? "; secure" : "" );
         
}

//-----------------------------------
// this function gets the cookie, if it exists
//-----------------------------------
function getCookie( name ) 
{	
      var start = document.cookie.indexOf( name + "=" );
      
      var len = start + name.length + 1;
      if ( ( !start ) &&
      ( name != document.cookie.substring( 0, name.length ) ) )
      {
      return null;
      }
      if ( start == -1 ) return null;
      var end = document.cookie.indexOf( ";", len );
      if ( end == -1 ) end = document.cookie.length;
return  unescape(document.cookie.substring( len, end ));
}
	
//-----------------------------------
// Animate the code
//-----------------------------------
if (indigo_type == "cycle")
{
      var image_index = 1;
      var book_code = new Array();
      var book_img = new Array();
      var book_link = new Array();
      var sTime = indigo_duration * 1000;
      var total_images;

      book_img[0] = new Image();
      book_img[1] = new Image();
      book_img[2] = new Image();
      book_img[3] = new Image();
      book_img[4] = new Image();
      
      book_code[0] = indigo_code1;
      book_code[1] = indigo_code2;
      book_code[2] = indigo_code3;
      if (indigo_code4) { book_code[3] = indigo_code4; }
      if (indigo_code5) { book_code[4] = indigo_code5; }
      total_images = book_code.length;

      for (i = 0; i < total_images; i++)
      {
            tens = book_code[i] % 100;
            img_dir = book_code[i] - tens;
            book_img[i].src = "http://www.indigocafe.com/bookstore/img/" + img_dir + "/" + book_code[i] + ".jpg";
            if (indigo_target == "bookpage")
            { book_link[i] = 
             "http://www.indigocafe.com/bookstore/book.php?TC=" + book_code[i];}
            if (indigo_target == "bag")
            { book_link[i] = 
            "http://www.indigocafe.com/store/addto_shoppingbag.php?AFFL_ID=" + indigo_id + "&TC=" + book_code[i];}
      }

      document.writeln("<a href=\"javascript:gotoIndigoCafe()\">");
      document.writeln("<img src="+ book_img[1].src +" name=\"indigobook\" border=1 width=100 height = 141 style=\"border-color: black\"></a>");
      animateIndigoBook();
}

function animateIndigoBook()
{
      image_index++;
      if (image_index == total_images) { image_index = 0; }
    	document.indigobook.src = book_img[image_index].src;
	setTimeout("animateIndigoBook()", sTime);
}

function gotoIndigoCafe()
{
	location.href = book_link[image_index];
}