// *** Copyright (c)2002 Jim Massey. All rights reserved  ***********
// *** massey@stlouis-shopper.com **************
// *** No Warranty - certified to work with nothing ***

// ** for the reader.xul doc reader for kiosk project **

var current_list_name = 0;
var slide_show_count = 0;

function new_Page(uri, list) {
 if (uri == null) {
   var site = document.getElementById(list).getAttribute("value");
   document.getElementById("display1").setAttribute("src", site);
 } else {
   document.getElementById("display1").setAttribute("src", uri);
 }
   document.getElementById("display1").focus();
}

// **** Fillup the toolbar with stuff from reader-properties.js ****
function add_menu_item() {

 if (default_uri != "false") document.getElementById("display1")
	.setAttribute("src", default_uri);

 if (add_menus == "true") {
 	var tempItem = document.getElementById("main-toolbar").appendChild(
	       document.createElement("menulist"));
    	 tempItem.setAttribute("label", "Main Menu");
      	 tempItem.setAttribute("flex", "0");
	 tempItem.setAttribute("id", "main-menu");
	 tempItem.setAttribute("tooltiptext", menuItems[0]);
	  var popupItem = document.getElementById("main-menu").
	     appendChild(document.createElement("menupopup"));
	for (var i = 1; i < menuItems.length; i++) {
 	  tempItem.appendItem(menuItems[i])
	      .setAttribute("oncommand", menuItemsValue[i]);
	}
 }

	add_menuList();

	if (SlideShow_create == "true") {
	  slide_show_count = 0;
	  if (SlideShow.length >= slide_show_count + 1) SlideShow_forward();
	  if (SlideShow_create_menu == "true") SlideShow_menu();
	  if (SlideShow_cycle_count >= 1) SlideShow_auto();
	  if (SlideShow_toggle_wanted == "true") SlideShow_toggleBtn();
	}

	add_buttons();

	if (SlideShow_create_shortmsg == "true") {
		var tempItem = document.getElementById("reader-window");
		var tempItemA = document.createElement("text");
		tempItemA.setAttribute("id", "short-msg");
		tempItemA.setAttribute("value", SlideShow_short_msg);
		var tempItemB = document.getElementById("main-toolbar");
		tempItem.insertBefore(tempItemA, tempItemB);
	}

}

function add_menuList() {
	var i = 0;
    if ( add_menus == "true" ) {
	ArrayTemplabel = "menuListLabel";
      for (i = 0; i < menuLists.length; i++) {
	 var tempItem = document.getElementById("main-toolbar").appendChild(
	       document.createElement("menulist"));
    	 tempItem.setAttribute("label", menuLists[i]);
      	 tempItem.setAttribute("flex", "1");
	 tempItem.setAttribute("id", menuLists[i]);
	var popupItem = document.getElementById(menuLists[i]).
	    appendChild(document.createElement("menupopup"));
	 var Test1 = "TestMenu";
	 popupItem.setAttribute("oncommand", menuListsAction[i]);
	 tempItem.appendItem(menuListsLabel[i], "http://agnes/");
      }
    }

}

function new_Uri(list) {
alert(list);
 var site = document.getElementById(list).getAttribute("value");
   document.getElementById("display1").setAttribute("src", site);

}

function add_buttons() {

 if (new_buttons == 'true') {
  for ( var i = 0; i < toolbarButtonsLabel.length; i++) {
	  if (toolbarButtonsSRC[i]) {
   var tempItem = document.getElementById("main-toolbar").appendChild(
	       document.createElement("image"));
     tempItem.setAttribute("src", toolbarButtonsSRC[i]);
      tempItem.setAttribute("onclick", toolbarButtonsAction[i]);
    } else if (toolbarButtonsLabel[i]) {
     var tempItem = document.getElementById("main-toolbar").appendChild(
	       document.createElement("button"));
     tempItem.setAttribute("label", toolbarButtonsLabel[i]);
      tempItem.setAttribute("oncommand", toolbarButtonsAction[i]);
    }
      tempItem.setAttribute("tooltiptext", toolbarButtonsLabel[i]);
  }
 }
}



function xpi_install(name, src) 
{  
	var Aname=(name);
	var xpi={'Mozilla Application' : src};
	InstallTrigger.install(xpi);
}

// ****** Slide Show Functions ****************

function SlideShow_menu() {
	var tempItem = document.getElementById("main-toolbar")
	   .appendChild(document.createElement("menulist"));
    	 tempItem.setAttribute("label", SlideShow[0]);
      	 tempItem.setAttribute("flex", "1");
	 tempItem.setAttribute("id", "slideshow-menu");
	 tempItem.setAttribute("crop", "left");
	 tempItem.setAttribute("tooltiptext", SlideShow[0]);
	 var popupItem = document.getElementById("slideshow-menu").
	     appendChild(document.createElement("menupopup"));
	for (var i = 1; i < SlideShow.length; i++) {
	  //var tempUri = "new_Page('" + SlideShow[i] + "')";  // ** HACK **
	  var tempUri = "SlideShow_menu_choice(" + i + ");";
	 if (SlideShowLabel[i] != null) {
	    tempItem.appendItem(SlideShowLabel[i])
	       .setAttribute("oncommand", tempUri);
	 } else {
	   tempItem.appendItem(SlideShow[i])
	      .setAttribute("oncommand", tempUri);
	 }
	   
	}
}

function SlideShow_menu_choice(count) {
	slide_show_count = count;
	new_Page(SlideShow[count]);
}

function SlideShow_forward() {
	
	if (slide_show_count >= SlideShow.length) {
	  slide_show_count = 1;
	} else {
	  slide_show_count++;
	  if (slide_show_count >= SlideShow.length) { slide_show_count = 1;}
	}
	//alert("Forward Count: " + slide_show_count);
	  new_Page(SlideShow[slide_show_count]);
	
}

function SlideShow_back() {
	if (slide_show_count >= 2) {
	  slide_show_count--;
	//alert("Back Count: " + slide_show_count);
	  new_Page(SlideShow[slide_show_count]);
	}
}

function SlideShow_auto() {
    SlideShow_interval = setInterval("SlideShow_forward()", 
	                              SlideShow_cycle_count);
	
}

function SlideShow_toggleBtn() {

var tempItem = document.getElementById("main-toolbar").appendChild(
	       document.createElement("button"));
	tempItem.setAttribute("label", "Stop Slide Show");
	tempItem.setAttribute("id", "SlideShowToggleBtn");
      	tempItem.setAttribute("oncommand", "SlideShow_toggle()");
      	tempItem.setAttribute("tooltiptext", "Starts/Stops Slide Show");

}

function SlideShow_toggle() {
	if (document.getElementById("SlideShowToggleBtn")
	     .getAttribute("label") == "Stop Slide Show") {
	 	clearInterval(SlideShow_interval);
		alert("Slide Show Paused");
		 document.getElementById("SlideShowToggleBtn")
		    .setAttribute("label", "Start Slide Show");
	} else {
	  	document.getElementById("SlideShowToggleBtn")
		    .setAttribute("label", "Stop Slide Show");
	  	SlideShow_auto();
	}
}
	 
