// JavaScript Document

var myXML ="_xml/environment_tips.xml";

$(function() {
	var loadXML =  new LoadXML(myXML);
	loadXML.ajaxGet();
});

function LoadXML(myXML) {
	var self = this;
	//load xml file
	
	this.ajaxGet = function() { 
		$.get(myXML, function(data){ self.parseXML(data); });
	}
	
	this.parseXML = function(data) {
		var tipText = new Array();
		//[0].childNodes[num].length;
		var i = 0;
		$(data).find('tip').each(function() {
			tipText[i] = $(this).text();
			//images[i] = data.childNodes[0].childNodes[num].firstChild.nodeValue;
			i++;
		});
		self.display(tipText);
		
		$('.cycleTip').bind('mouseenter', function() {
			$(this).css({ color: '#ffffff', background: 'url(images/cycleTip_o.gif) no-repeat' });
		});
		
		$('.cycleTip').bind('mouseleave',function() {
			$(this).css({ color: '#64A715', background: 'url(images/cycleTip.gif) no-repeat' });
		});
		
		$('.cycleTip').click(function() {
			self.display(tipText);
		});
	}
	
	this.display = function(tipText) {
		//write to the thumbs div
		var num = Math.floor((Math.random() * 36));
		var tip = $("#tip");
		tip.hide();
		tip.fadeIn(750).html(tipText[num]); 
	}
	
}