// JavaScript Document
// include.js
// Madeline Salocks



function makeRequest() {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}

	return http_request;
}


var http_xml = makeRequest();
var listing;
var whichxml;


function sndReq(fn) {
	
	listing = "";

    if (fn != "") {
		whichxml = fn;
		http_xml.open('GET', 'xml/all.xml', true);
		http_xml.onreadystatechange = handleResponse; 
		http_xml.send(null);
    }
}

function sndReq_other_sponsors(fn) {

		listing = "";

    //if (fn != "") {
		whichxml = fn;
		http_xml.open('GET', 'xml/other_sponsors.xml', true);
		http_xml.onreadystatechange = handleResponse; 
		http_xml.send(null);
    //}
}


function sortby_rname(a, b) {
    var x = a.rname.toLowerCase();
    var y = b.rname.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function restaurant_obj(rn, ph, u, addr, cty, zip, desc, par, damt, damtd, sp, logo) {
    this.rname = rn;
    this.phone = ph;
    this.url = u;
	this.street_addr = addr;
	this.city = cty;
	this.zip = zip;
	this.description = desc;
	this.participant = par;
	this.donor_amt = damt;
	this.donor_amt_disp = damtd;
	this.special = sp;
	this.logo = logo;
}

function sponsor_obj(rn, ph, u, addr, cty, zip, desc, par, damt, damtd, sp, logo) {
    this.rname = rn;  /* rname is a holdover from the restaurants lists - change later */
    this.phone = ph;
    this.url = u;
	this.street_addr = addr;
	this.city = cty;
	this.zip = zip;
	this.description = desc;
	this.participant = par;
	this.donor_amt = damt;
	this.donor_amt_disp = damtd;
	this.special = sp;
	this.logo = logo;
}



function handleResponse() {
var title_city;
var title;
var restaurants;
var area;
var counter;

	if (http_xml.readyState == 4) {
		var xmldoc = http_xml.responseXML;
		//alert(whichxml);
		if (whichxml == 'other') {
			
			sponsors = xmldoc.getElementsByTagName('sponsor');
			title = "Sponsors";
			
			var sponsors_arr = new Array();
	
			for (counter=0; counter < sponsors.length; counter++) {
				var sponsor = sponsors[counter];
				sponsors_arr[sponsors_arr.length++] = new sponsor_obj(sponsor.getElementsByTagName("name")[0].firstChild.nodeValue, sponsor.getElementsByTagName("phone")[0].firstChild.nodeValue, sponsor.getElementsByTagName("url")[0].firstChild.nodeValue, sponsor.getElementsByTagName("addr_street")[0].firstChild.nodeValue, sponsor.getElementsByTagName("city")[0].firstChild.nodeValue, sponsor.getElementsByTagName("zip")[0].firstChild.nodeValue, sponsor.getElementsByTagName("description")[0].firstChild.nodeValue, sponsor.getElementsByTagName("participant")[0].firstChild.nodeValue, sponsor.getElementsByTagName("donation_amt")[0].firstChild.nodeValue, sponsor.getElementsByTagName("display_donation")[0].firstChild.nodeValue, sponsor.getElementsByTagName("special")[0].firstChild.nodeValue, sponsor.getElementsByTagName("logo")[0].firstChild.nodeValue);
			} // end for
			
			sponsors_arr.sort(sortby_rname);
			
			listing += "<table align=\"center\" width=\"675\" bgcolor=\"#ffffff\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
					listing += "<tr><td colspan=\"2\" style=\"padding-top:10px; padding-bottom:10px; text-align:center; margin:0 auto;\" class=\"highlighted_msg\">Please remember to thank sponsors for their support of Meals on Wheels.</td></tr>";
					listing += "<tr><td colspan=\"2\" style=\"text-align:left;padding-left:25px;\" valign=\"middle\"><img src='images/participant_small.jpg' alt='participant' /><span style=\"vertical-align:4px;\">participant</span>&nbsp;&nbsp;<img src='images/donor_small.jpg' alt='donor' /><span style=\"vertical-align:4px;\">donor</span></td></tr><tr><td colspan=\"2\" style=\"text-align:center; margin:0 auto; height:15px; \">&nbsp;</td></tr>";
			
			for (counter=0; counter < sponsors.length; counter++) {
				  <!-- start divider -->
				  listing += "<tr><td colspan=\"2\">";
				  listing += "<div style=\"width:625px;height:20px;border-top:solid 1px #f2ede3;margin:0 auto;\">&nbsp;</div>";
				  listing += "</td></tr>";
				  <!-- end divider -->

			      listing += "<tr style='height:200px;'>";
				  var sponsor = sponsors_arr[counter];
				  var participant_disp = "";
				  if (sponsor.participant == 'y' || sponsor.participant == 'Y') {
						participant_disp = "<img src='images/participant_small.jpg' alt='participant' style='padding-right:3px;' />";  
				  }
				  var donation = sponsor.donor_amt;
				  var donor_disp = "";
				  if (donation != '0') {
						donor_disp = "<img src='images/donor_small.jpg' alt='donor' />";  
				  }
				  var special = "";
				  if (sponsor.special != 'none') {
						special = sponsor.special;  
				  }
				  var addr_street = sponsor.street_addr;
				  var city = sponsor.city;
				  var noSpaces = /[ ]/ig;
				  var map_addr_street = addr_street.replace(noSpaces,"+"); 
				  var map_city = city.replace(noSpaces,"+");
				  
				  if (sponsor.url != "none")
				  	var sponsor_img_logo = "<a href=\"" + sponsor.url +  "\" target=\"_blank\"><img src = \"sponsor_logos/" + sponsor.logo + "\" alt=\"\" /></a>";
				  else
				  	var sponsor_img_logo = "<img src = \"sponsor_logos/" + sponsor.logo + "\" alt=\"\" />";
				 				 
				  listing +="<td align=\"left\"valign=\"top\" width=\"225\" style=\"padding-left:25px;\">" + sponsor_img_logo;
				  
				  listing += "<div style=\"margin-top:10px;\">";
				  
				   if (sponsor.url != "none")
					  listing += "<a href=\"" + sponsor.url +  "\" target=\"_blank\" class=\"r_name\">" + sponsor.rname + "</a>";
				  else
					  listing += "<span style=\"color:#333333; font-weight:bold;\">" + sponsor.rname + "</span>";
				  
				  if (addr_street == "multiple") {
					  if (sponsor.rname == "Les Schwab Tires") {
						listing += "<div class=\"curved\"><b class=\"b1 c1\"></b><b class=\"b2 c2\"></b><b class=\"b3 c3\"></b>" +
						"<b class=\"b4 c4\"></b><div class=\"boxcontent\">" + 
						"<ul id=\"menu\">" +
						"<li><a class=\"m5 five\" href=\"#nogo\">" +
      					"<b class=\"h2\">Brentwood</b><br /><span>6361 Lone Tree Way<br />925.513.3432</span>" +
     					"</a></li>" +
						"<li><a href=\"#nogo\"><b class=\"b1\"></b><b class=\"b2\"></b><b class=\"b3\"></b><b class=\"b4\"></b>" +
						"<b class=\"h2\">Martinez</b><br />" +
						"<span>3800 Alhambra Ave<br />925.370.6382</span></a></li>" +
						"<li><a href=\"#nogo\"><b class=\"b1\"></b><b class=\"b2\"></b><b class=\"b3\"></b><b class=\"b4\"></b>" +
						"<b class=\"h2\">Concord</b><br /><span>625 Contra Costa Blvd<br />925.825.5940</span>"+
						"</a></li><li><a href=\"#nogo\"><b class=\"b1\"></b><b class=\"b2\"></b><b class=\"b3\"></b><b class=\"b4\"></b>" +
						"<b class=\"h2\">Oakley</b><br /><span>89 Carol Lane<br />925.625.4532</span></a></li>" +
						"</ul>" +
						"</div><b class=\"b4 c4\"></b><b class=\"b3 c3\"></b><b class=\"b2 c2\"></b><b class=\"b1 c1\"></b></div>";
					  }
				  }
				  else {
				  listing += "<br />";
				  listing += addr_street;
				  listing += "<br />";
				  //listing += ",&nbsp;";
				  listing += sponsor.city;
				  listing += "<br />";
				  
				  listing += sponsor.phone;	
				  
				  listing += "&nbsp;<span style=\"font-size:9px;\">|</span>&nbsp;<a href=\"http://maps.yahoo.com/py/maps.py?&addr="  + map_addr_street +  "&amp;csz="  + map_city + "+CA+" + sponsor.zip + "&amp;country=us\" target=\"_blank\" class=\"map_site_link\">map</a>";
				  }
				  
				  if (sponsor.url != "none") {
					    if (addr_street != "multiple") {
							listing += "&nbsp;<span style=\"font-size:9px;\">|</span>&nbsp;";
						}
						listing += "<a href=\"" + sponsor.url +  "\" target=\"_blank\" class=\"map_site_link\">website</a>";
				  }
				  
				  listing += "</td>";
				  
				  var donor_amt_disp = "";
				  if (sponsor.donor_amt_disp == 'y' || sponsor.donor_amt_disp == 'Y') {
						donor_amt_disp = sponsor.donor_amt;  
				  }
				  
				  listing += "<td valign=\"top\" style=\"padding-left:10px;padding-right:25px;\">" + sponsor.description + "<div style=\"margin-top:5px;margin-bottom:5px;\">" + participant_disp + donor_disp + "<span class=\"donor_amt_disp\">" + donor_amt_disp + "</span></div><span class=\"highlighted_msg\">" + special +  "</span></td>";
				 
				  
				  listing += "</tr>";
			
			} // end for
						
			listing += "</table>";
			
		}
		else if (whichxml == 'all') {
			restaurants = xmldoc.getElementsByTagName('restaurant');
			title = "All Restaurants";
			
			var restaurants_arr = new Array();
	
			for (counter=0; counter < restaurants.length; counter++) {
				var restaurant = restaurants[counter];
				restaurants_arr[restaurants_arr.length++] = new restaurant_obj(restaurant.getElementsByTagName("name")[0].firstChild.nodeValue, restaurant.getElementsByTagName("phone")[0].firstChild.nodeValue, restaurant.getElementsByTagName("url")[0].firstChild.nodeValue, restaurant.getElementsByTagName("addr_street")[0].firstChild.nodeValue, restaurant.getElementsByTagName("city")[0].firstChild.nodeValue, restaurant.getElementsByTagName("zip")[0].firstChild.nodeValue, restaurant.getElementsByTagName("description")[0].firstChild.nodeValue, restaurant.getElementsByTagName("participant")[0].firstChild.nodeValue, restaurant.getElementsByTagName("donation_amt")[0].firstChild.nodeValue, restaurant.getElementsByTagName("display_donation")[0].firstChild.nodeValue, restaurant.getElementsByTagName("special")[0].firstChild.nodeValue, restaurant.getElementsByTagName("logo")[0].firstChild.nodeValue);
			} // end for
			
			restaurants_arr.sort(sortby_rname);
			
			listing += "<table align=\"center\" width=\"675\" bgcolor=\"#ffffff\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
					listing += "<tr><td colspan=\"2\" style=\"padding-top:10px; padding-bottom:10px; text-align:center; margin:0 auto;\" class=\"highlighted_msg\">Please remember to thank restaurants for their support of Meals on Wheels.</td></tr>";
					listing += "<tr><td colspan=\"2\" style=\"text-align:left;padding-left:25px;\" valign=\"middle\"><img src='images/participant_small.jpg' alt='participant' /><span style=\"vertical-align:4px;\">participant</span>&nbsp;&nbsp;<img src='images/donor_small.jpg' alt='donor' /><span style=\"vertical-align:4px;\">donor</span></td></tr><tr><td colspan=\"2\" style=\"text-align:center; margin:0 auto; height:15px; \">&nbsp;</td></tr>";
					
			
			for (counter=0; counter < restaurants.length; counter++) {
				  <!-- start divider -->
				  listing += "<tr><td colspan=\"2\">";
				  listing += "<div style=\"width:625px;height:20px;border-top:solid 1px #f2ede3;margin:0 auto;\">&nbsp;</div>";
				  listing += "</td></tr>";
				  <!-- end divider -->

			      listing += "<tr style='height:200px;'>";
				  var restaurant = restaurants_arr[counter];
				  var participant_disp = "";
				  if (restaurant.participant == 'y' || restaurant.participant == 'Y') {
						participant_disp = "<img src='images/participant_small.jpg' alt='participant' style='padding-right:3px;' />";  
				  }
				  var donation = restaurant.donor_amt;
				  var donor_disp = "";
				  if (donation != '0') {
						donor_disp = "<img src='images/donor_small.jpg' alt='donor' />";  
				  }
				  var special = "";
				  if (restaurant.special != 'none') {
						special = restaurant.special;  
				  }
				  var addr_street = restaurant.street_addr;
				  var city = restaurant.city;
				  var noSpaces = /[ ]/ig;
				  var map_addr_street = addr_street.replace(noSpaces,"+"); 
				  var map_city = city.replace(noSpaces,"+");
				  
				  if (restaurant.url != "none")
				  	var restaurant_img_logo = "<a href=\"" + restaurant.url +  "\" target=\"_blank\"><img src = \"restaurant_logos/" + restaurant.logo + "\" alt=\"\" /></a>";
				  else
				  	var restaurant_img_logo = "<img src = \"restaurant_logos/" + restaurant.logo + "\" alt=\"\" />";
				 				 
				  //listing +="<td align=\"left\"valign=\"top\" width=\"215\" style=\"padding-left:15px;\">" + restaurant_img_logo + "</td><td align=\"left\" width=\"175\" valign=\"top\" style=\"padding-left:10px;\">";
				  listing +="<td align=\"left\"valign=\"top\" width=\"225\" style=\"padding-left:25px;\">" + restaurant_img_logo;
				  
				  listing += "<div style=\"margin-top:10px;\">";
				  
				   if (restaurant.url != "none")
					  listing += "<a href=\"" + restaurant.url +  "\" target=\"_blank\" class=\"r_name\">" + restaurant.rname + "</a>";
				  else
					  listing += "<span style=\"color:#333333; font-weight:bold;\">" + restaurant.rname + "</span>";
				  				  
				  
				  listing += "<br />";
				  listing += addr_street;
				  listing += "<br />";
				  //listing += ",&nbsp;";
				  listing += restaurant.city;
				  listing += "<br />";
				  
				  listing += restaurant.phone;	
				  listing += "&nbsp;<span style=\"font-size:9px;\">|</span>&nbsp;<a href=\"http://maps.yahoo.com/py/maps.py?&addr="  + map_addr_street +  "&amp;csz="  + map_city + "+CA+" + restaurant.zip + "&amp;country=us\" target=\"_blank\" class=\"map_site_link\">map</a>";
				  
				  if (restaurant.url != "none") {
						//listing += "<div style=\"margin-top:3px;\">" + "<a href=\"" + restaurant.url +  "\" target=\"_blank\">website</a></div>"; 
						listing += "&nbsp;<span style=\"font-size:9px;\">|</span>&nbsp;<a href=\"" + restaurant.url +  "\" target=\"_blank\" class=\"map_site_link\">website</a>";
				  }
				  
				  listing += "</td>";
				  
				  var donor_amt_disp = "";
				  if (restaurant.donor_amt_disp == 'y' || restaurant.donor_amt_disp == 'Y') {
						donor_amt_disp = restaurant.donor_amt;  
				  }
				  
				  listing += "<td valign=\"top\" style=\"padding-left:10px;padding-right:25px;\">" + restaurant.description + "<div style=\"margin-top:5px;margin-bottom:5px;\">" + participant_disp + donor_disp + "<span class=\"donor_amt_disp\">" + donor_amt_disp + "</span></div><span class=\"highlighted_msg\" style=\"font-weight:normal;\">" + special +  "</span></td>";
				 
				  
				  listing += "</tr>";
			
			} // end for
						
			listing += "</table>";

			
		} // end if all
		else {
			switch(whichxml)
			{
			case 'walnutcreek':
			  area = xmldoc.getElementsByTagName("area")[0];
			  title_city = "Walnut Creek";
			  break;
			case 'moraga':
			  area = xmldoc.getElementsByTagName("area")[1];
			  title_city = "Moraga";
			  break;
			case 'pleasanthill':
			  area = xmldoc.getElementsByTagName("area")[2];
			  title_city = "Pleasant Hill";
			  break;	
			case 'sanramon':
			  area = xmldoc.getElementsByTagName("area")[3];
			  title_city = "San Ramon";
			  break;
			case 'orinda':
			  area = xmldoc.getElementsByTagName("area")[4];
			  title_city = "Orinda";
			  break;
			case 'lafayette':
			  area = xmldoc.getElementsByTagName("area")[5];
			  title_city = "Lafayette";
			  break;
			case 'antioch':
			  area = xmldoc.getElementsByTagName("area")[6];
			  title_city = "Antioch";
			  break;
			case 'brentwood':
			  area = xmldoc.getElementsByTagName("area")[7];
			  title_city = "Brentwood";
			  break;			  			  		  		  			  
			case 'oakley':
			  area = xmldoc.getElementsByTagName("area")[8];
			  title_city = "Oakley";
			  break;			  			  		  		  			  
		  	case 'concord':
			  area = xmldoc.getElementsByTagName("area")[9];
			  title_city = "Concord";
			  break;
		  	case 'pittsburg':
			  area = xmldoc.getElementsByTagName("area")[10];
			  title_city = "Pittsburg";
			  break;
		  	case 'danville':
			  area = xmldoc.getElementsByTagName("area")[11];
			  title_city = "Danville";
			  break;
		  	case 'alamo':
			  area = xmldoc.getElementsByTagName("area")[12];
			  title_city = "Alamo";
			  break;
		  	case 'martinez':
			  area = xmldoc.getElementsByTagName("area")[13];
			  title_city = "Martinez";
			  break;	
			default:
			}
			restaurants = area.getElementsByTagName("restaurant");
			title = "Restaurants in " + title_city;
			
			listing += "<table align=\"center\" width=\"675\" bgcolor=\"#ffffff\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
					listing += "<tr><td colspan=\"2\" style=\"padding-top:10px; padding-bottom:10px; text-align:center; margin:0 auto;\" class=\"highlighted_msg\">Please remember to thank restaurants for their support of Meals on Wheels.</td></tr>";
					listing += "<tr><td colspan=\"2\" style=\"text-align:left;padding-left:25px;\" valign=\"middle\"><img src='images/participant_small.jpg' alt='participant' /><span style=\"vertical-align:4px;\">participant</span>&nbsp;&nbsp;<img src='images/donor_small.jpg' alt='donor' /><span style=\"vertical-align:4px;\">donor</span></td></tr><tr><td colspan=\"2\" style=\"text-align:center; margin:0 auto; height:15px; \">&nbsp;</td></tr>";
			
			for (counter=0; counter < restaurants.length; counter++) {
					  <!-- start divider -->
				      listing += "<tr><td colspan=\"2\">";
					  listing += "<div style=\"width:625px;height:20px;border-top:solid 1px #f2ede3;margin:0 auto;\">&nbsp;</div>";
					  listing += "</td></tr>";
					  <!-- end divider -->
					  listing += "<tr style='height:200px;'>";
					  var restaurant = restaurants[counter];
					  var participant = restaurant.getElementsByTagName("participant")[0].firstChild.nodeValue;
					  var participant_disp = "";
					  if (participant == 'y' || participant == 'Y') {
							participant_disp = "<img src='images/participant_small.jpg' alt='participant' />";  
					  }
					  var donation = restaurant.getElementsByTagName("donation_amt")[0].firstChild.nodeValue;
					  var donor_disp = "";
					  if (donation != '0') {
							donor_disp = "<img src='images/donor_small.jpg' alt='donor' />";  
					  }
					  var special = "";
					  if (restaurant.getElementsByTagName("special")[0].firstChild.nodeValue != 'none') {
							special = restaurant.getElementsByTagName("special")[0].firstChild.nodeValue;  
					  }
					  else
					  {		
					  		special = "<span style='width:100px;'>&nbsp;</span>";
					  }
					  
					  var addr_street = restaurant.getElementsByTagName("addr_street")[0].firstChild.nodeValue;
					  var city = restaurant.getElementsByTagName("city")[0].firstChild.nodeValue;
					  var noSpaces = /[ ]/ig;
					  var map_addr_street = addr_street.replace(noSpaces,"+"); 
					  var map_city = city.replace(noSpaces,"+");
					  
					  var url = restaurant.getElementsByTagName("url")[0].firstChild.nodeValue;
					  if (url != "none")
				  	  		var restaurant_img_logo = "<a href=\"" + url +  "\" target=\"_blank\"><img src = \"restaurant_logos/" + restaurant.getElementsByTagName("logo")[0].firstChild.nodeValue + "\" alt=\"\" /></a>";
				      else
				  			var restaurant_img_logo = "<img src = \"restaurant_logos/" + restaurant.getElementsByTagName("logo")[0].firstChild.nodeValue + "\" alt=\"\" />";

				  //listing +="<td align=\"left\" width=\"215\" valign=\"top\" style=\"padding-left:15px;\">" + restaurant_img_logo + "</td><td align=\"left\" width=\"175\" valign=\"top\" style=\"padding-left:10px;\">"; /* background-color:pink; */
				  listing +="<td align=\"left\" width=\"225\" valign=\"top\" style=\"padding-left:25px;\">" + restaurant_img_logo; /* background-color:pink; */
				  
				  listing += "<div style=\"margin-top:10px;\">";
				  
				  if (url != "none")
					  listing += "<a href=\"" + url +  "\" target=\"_blank\" class=\"r_name\">" + restaurant.getElementsByTagName("name")[0].firstChild.nodeValue + "</a>";
				  else
					  listing += "<span style=\"color:#333333; font-weight:bold;\">" + restaurant.getElementsByTagName("name")[0].firstChild.nodeValue + "</span>";
				  
				  listing += "<br />";
				  listing += addr_street;
				  listing += "<br />";
				  //listing += ",&nbsp;";
				  listing += restaurant.getElementsByTagName("city")[0].firstChild.nodeValue;
				  listing += "<br />";
				  
				  listing += restaurant.getElementsByTagName("phone")[0].firstChild.nodeValue;	
				  listing += "&nbsp;<span style=\"font-size:9px;\">|</span>&nbsp;<a href=\"http://maps.yahoo.com/py/maps.py?&addr="  + map_addr_street +  "&amp;csz="  + map_city + "+CA+" + restaurant.getElementsByTagName("zip")[0].firstChild.nodeValue + "&amp;country=us\" target=\"_blank\" class=\"map_site_link\">map</a>";
				  if (url != "none") {
						listing += "&nbsp;<span style=\"font-size:9px;\">|</span>&nbsp;<a href=\"" + url +  "\" target=\"_blank\" class=\"map_site_link\">website</a></div>";  
				  }
				  
				  listing += "</td>";
				  
				  var donor_amt_disp = "";
				  if (restaurant.getElementsByTagName("display_donation")[0].firstChild.nodeValue == 'y' || restaurant.getElementsByTagName("display_donation")[0].firstChild.nodeValue == 'Y') {
						donor_amt_disp = restaurant.getElementsByTagName("donation_amt")[0].firstChild.nodeValue;  
				  }
				  var descr = restaurant.getElementsByTagName("description")[0].firstChild.nodeValue;
				  listing += "<td valign=\"top\" style=\"padding-left:10px;padding-right:25px;\">" + descr + "<div style=\"margin-top:5px;margin-bottom:5px;\">" + participant_disp + donor_disp + "<span class=\"donor_amt_disp\">" + donor_amt_disp + "</span></div><span class=\"highlighted_msg\" style=\"font-weight:normal;\">" + special +  "</span></td>";
				 
				  
				  listing += "</tr>";


				  				  
			}  // end for
			
						
			listing += "</table>";
					
			
		} // end not all
		
		listing += "<div style=\"width:645px;height:20px;border-top:solid 1px #f2ede3;margin:0 auto;\">&nbsp;</div>";
	
		document.getElementById("main_body").innerHTML = listing;
		document.getElementById("title").innerHTML = title;

	
	} // end if readyState
	
} //end func




//  pop:
(function($) {
  
  $.pop = function(options){
    
    // settings
    var settings = {
     pop_class : '.pop',
     pop_toggle_text : ''
    }
    
    // inject html wrapper
    function initpops (){
      $(settings.pop_class).each(function() {
        var pop_classes = $(this).attr("class");
        $(this).addClass("pop_menu");
        $(this).wrap("<div class='"+pop_classes+"'></div>");
        $(".pop_menu").attr("class", "pop_menu");
        $(this).before(" \
          <div class='pop_toggle'>"+settings.pop_toggle_text+"</div> \
          ");
      });
    }
    initpops();
    
    // assign reverse z-indexes to each pop
    var totalpops = $(settings.pop_class).size() + 1000;
    $(settings.pop_class).each(function(i) {
     var popzindex = totalpops - i;
     $(this).css({ zIndex: popzindex });
    });
    // close pops if user clicks outside of pop
    activePop = null;
    function closeInactivePop() {
      $(settings.pop_class).each(function (i) {
        if ($(this).hasClass('active') && i!=activePop) {
          $(this).removeClass('active');
          }
      });
      return false;
    }
    $(settings.pop_class).mouseover(function() { activePop = $(settings.pop_class).index(this); });
    $(settings.pop_class).mouseout(function() { activePop = null; });

    $(document.body).click(function(){ 
     closeInactivePop();
    });
    // toggle that pop
    $(".pop_toggle").click(function(){
      $(this).parent(settings.pop_class).toggleClass("active");
    });
  }

})(jQuery);


/*** 
    Simple jQuery Slideshow Script:
***/

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 10000 );
});

