// JavaScript Document

ajax1 = new NV_ajax();

function do_testimonial(thetype) {
	T_sitearea = thetype;
	
	ajax1.start2way('../includes/generate_testimonials.php?oldid=0&site_area=' + T_sitearea + '','XML','show_testimonial()','');
	setInterval("ajax1.start2way('../includes/generate_testimonials.php?oldid=' + this.oldid + '&site_area=' + this.T_sitearea,'XML','show_testimonial()','');",15002);
}

var INT_fade; // Interval for the fading
var T_timeout; // Holds Timeout for starting the fade after 8 seconds
var T_fadelevel = 0; // Amount of opacity
var original_bgColor = ""; // Original bgColor of the outer DIV
var original_bgImage = ""; // Original background image of the outer DIV
var oldid = 0; // the id of current snippet
var T_sitearea = "";

function get_bgcolor() {
	original_bgColor = GEBI('DIV_testimonial_outer').style.backgroundColor;
	
	if (GEBI('DIV_testimonial_outer').style.backgroundImage)
		original_bgImage = GEBI('DIV_testimonial_outer').style.backgroundImage;
}

function show_testimonial() {
	clearTimeout(this.T_timeout);
	clearInterval(this.INT_fade);
	
	var xmlDoc = ajax1.retrieveXML();
	var the_img = "";
	var the_id = "";
	var the_text = "";
	var the_realtext = "";
	var the_target = "";
	
	try {
		the_img = xmlDoc.getElementsByTagName('the_snippet').item(0).getElementsByTagName('the_img').item(0).firstChild.data;
	} catch (e) {}
	
	try {
		the_id = xmlDoc.getElementsByTagName('the_snippet').item(0).getElementsByTagName('the_id').item(0).firstChild.data;
	} catch (e) {}
	
	oldid = the_id;
	
	try {
		the_text = xmlDoc.getElementsByTagName('the_snippet').item(0).getElementsByTagName('the_text');
	} catch (e) {}
	
	try {
		the_target = the_text.item(0).getElementsByTagName('the_target').item(0).firstChild.data;
	}
	catch (e) { the_realtext = "<div id=\"DIV_testimonial_inner\" style=\"cursor:pointer;\">"; }
	
	if (the_target != "")
		the_realtext = "<div id=\"DIV_testimonial_inner\" style=\"cursor:pointer;\" onclick=\"javascript:document.location.href='" + the_target + "';\">";
	
	try {
		 the_realtext += "<div id=\"DIV_testimonial_innerTitle\">" + the_text.item(0).getElementsByTagName('title').item(0).firstChild.data + "</div>";
	} catch(e) {  }
	
	the_realtext += "<div id=\"DIV_testimonial_innerQuote\">\"" + the_text.item(0).getElementsByTagName('body1').item(0).firstChild.data.replace(/\"/g,'') + "\"</div>";
	the_realtext += "<div id=\"DIV_testimonial_innerSignature\">";
	try {
		if (the_text.item(0).getElementsByTagName('body2').item(0).firstChild.data != "")
			the_realtext += the_text.item(0).getElementsByTagName('body2').item(0).firstChild.data;
	} catch (e) { }
	
	try {
		if (the_text.item(0).getElementsByTagName('jobtitle').item(0).firstChild.data != "")
			the_realtext += "<br />" + the_text.item(0).getElementsByTagName('jobtitle').item(0).firstChild.data;
	} catch (e) { }
	try {
		if (the_text.item(0).getElementsByTagName('organizationname').item(0).firstChild.data != "")
			the_realtext += "<br />" + the_text.item(0).getElementsByTagName('organizationname').item(0).firstChild.data;
	} catch (e) { }
		the_realtext += "</div></div>";
	
	
	GEBI('DIV_testimonial').innerHTML = the_realtext;
	
	if (the_img != "") {
		GEBI('DIV_testimonial_outer').style.background = "url('../internal/" + the_img + "')";
	}
	else {
		if (original_bgImage != "")
			GEBI('DIV_testimonial_outer').style.backgroundImage = original_bgImage;
		else
			GEBI('DIV_testimonial_outer').style.backgroundColor = original_bgColor;
	}
	
	fade('DIV_testimonial',true);
	
	T_timeout = self.setTimeout("fade('DIV_testimonial',false);",13000);
}

function fade(theid,is_in) {
	
	if(/MSIE/.test(navigator.userAgent)) {
		T_fadelevel = (is_in)?0:100;
		GEBI(theid).style.filter = 'alpha(opacity=' + T_fadelevel + ');';
		
		INT_fade = setInterval("this.T_fadelevel" + ((is_in)?"+":"-") + "= 9.9; GEBI('" + theid + "').style.filter = 'alpha(opacity=' + this.T_fadelevel + ');';",100);
		
		if (is_in)
			self.setTimeout("clearInterval(this.INT_fade);GEBI('" + theid + "').style.filter = 'alpha(opacity=100);';",1001);
		else
			self.setTimeout("clearInterval(this.INT_fade);GEBI('" + theid + "').style.filter = 'alpha(opacity=0);';",1000);
	}
	else {
		T_fadelevel = (is_in)?0:0.99;
		GEBI(theid).style.opacity = T_fadelevel;
		
		INT_fade = setInterval("this.T_fadelevel" + ((is_in)?"+":"-") + "= 0.099; GEBI('" + theid + "').style.opacity = this.T_fadelevel;",100);
		
		if (is_in)
			self.setTimeout("clearInterval(this.INT_fade);GEBI('" + theid + "').style.opacity = 0.99;",1001);
		else
			self.setTimeout("clearInterval(this.INT_fade);GEBI('" + theid + "').style.opacity = 0;",1000);
	}
	
}
