
/***************  templates/main/object.Weather.js  ***************/
function Weather(id, location, /*optional*/ source) {

	var that = this;
	var source = source || 'yahoo';
	var socketVars = {
		template: 'feed.weather.php'
	};
	var weatherFeedUrl = prepSocketCall('core', 'callTemplate', socketVars);
	weatherFeedUrl += '&source=' + source;
	var tempContainer = document.getElementById(id);

	if (!tempContainer) {
		throw new Error();
	}
	switch(source) {
		case 'yahoo':
			weatherFeedUrl += '&loc=' + location;
			break;
		default:
			break;
	}

	var printWeather = function(response) {
		var cent = response.getElementsByTagName('cent')[0].childNodes[0].nodeValue;
		var fahr = response.getElementsByTagName('fahr')[0].childNodes[0].nodeValue;
		var text = response.getElementsByTagName('text')[0].childNodes[0].nodeValue;
		var sunrise = response.getElementsByTagName('sunrise')[0].childNodes[0].nodeValue;

		spaceEl = document.createTextNode(' ');

		spanCentEl = document.createElement('span');
		spanCentEl.className = 'temperature';
		spanCentEl.appendChild(document.createTextNode(cent+'\u00B0')); //&deg;
		spanCentUnitEl = document.createElement('span');
		spanCentUnitEl.className = 'unit';
		spanCentUnitEl.appendChild(document.createTextNode('C'));
		spanCentEl.appendChild(spanCentUnitEl);

		spanTextEl = document.createElement('span');
		spanTextEl.className = 'text';
		spanTextEl.appendChild(document.createTextNode(text));

		if (tempContainer.childNodes.length>=1) { //IE6 needs >= instead of ==
			tempContainer.replaceChild(spanCentEl, tempContainer.childNodes[0]);
		} else {
			tempContainer.appendChild(spanCentEl);
		}
		tempContainer.appendChild(spaceEl);
		tempContainer.appendChild(spanTextEl);
	}

	this.init = function() {
		HTTP.getXML(weatherFeedUrl, printWeather);
	}
}
/***************  templates/main/header.JavaScript.js  ***************/
/**
 * Creates a hover-tooltip for HTML DOM elements (such as images).  In the case of an image,
 * this hover-tooltip will override that which is automatically generated from the image's
 * title attribute.  This is useful when used with lightbox, for example.
 *
 * @param {Element} elem an HTML DOM element
 * @param {String} tooltip the tooltip to be displayed
 * 
 * Usage:
 * 	<a href="imagepath" title="imagetitle" onmouseover="condorjs.toggleTitle(this, 'Click to zoom')"></a>
 */
condor.toggleTitle = function(elem, tooltip) {
	elem.origTitle = elem.title ? elem.title : "";
	elem.tooltip = tooltip ? tooltip : "";
	elem.onmouseover = function() {this.title = this.tooltip};
	elem.onfocus = function() {this.title = this.origTitle};
	elem.onmouseout = elem.onfocus;
	elem.onmouseover();
}


/**
 * Adds mouseover/hover functionality to specified elements by adding and removing a "mouseover" class.
 * 
 * @param {Element} elem an HTML DOM element
 * 
 * Usage:
 * 	<styles>
 * 	li.mouseover, li:hover {
 * 		background-color: green;
 * 	}
 * 	</style>
 * 	<li onmouseover="condorjs.mouseover_init(this)">		
 */		
condor.mouseover_init = function(elem) {
	if(!/MSIE (5|6)/.test(navigator.userAgent)) 
	// No need to add mouseover events. Browser probably already understands :hover
	{
		elem.onmouseover = null;
		return;
	}

	elem.onmouseover = function() {addClass(this, 'mouseover');}
	elem.onmouseout = function() {removeClass(this, 'mouseover');}
}


/**
 * Takes an image URL and shows the image with lightbox.
 * Lightbox needs to be initialised on the page, but no requirements are placed on the HTML.
 * Suitable for images whose URLs are known; for Toolbox images you should instead use
	
 * 
 * @param {String} imgURL the image URL
 */
condor.popLightbox = function(imgURL) {
	var elem = document.createElement("a");
	elem.rel = "lightbox";
	elem.href = imgURL;
	myLightbox.start(elem); /* myLightbox is a global variable declared by Lightbox */
}

