/**
 * title: tmon.js
 * purpose: Implements testomonial functionality
 */
function tmon(_para) {
	// constants
	this.TMON_SHOW_INTR = 6;
	// properties
	this.para = _para;
	this.xdat = {};
	// methods
	this.pdat = tmon_pdat;
	this.draw = tmon_draw;
	this.show = tmon_show;
}
function tmon_pdat() {
	var _obj = this;
	jQuery.ajax(
		{
			"beforeSend"	:
				function() {
					_obj.para["subj"].html(jQuery.ximg("ajax","loda.gif"));
				},
			"data"				:
				{
					"ax" : JSON.stringify(
						{
							"tmon" : {}
						}
					)
				},
			"success"			:
				function(__dx) {
					// vald
					{
						var _tmon;
						if(!__dx["code"])
							return _obj.para["subj"].html(jQuery.cmes(2,"pdat"));
						if(!(_tmon = _subarray(__dx,["mesg","tmon","mesg"])))
							return _obj.para["subj"].html(jQuery.cmes(2,"mdat"));
					}
					// tmon
					{
						_obj.xdat["tmon"] = [];
						jQuery.each(_tmon,
							function(_tidx,_tdat) {
								_obj.xdat["tmon"].push({"text":_tdat["c"],"imag":_tdat["i"],"srce":_tdat["s"]});
							}
						);
					}
					// draw
					{
						switch(_obj.para["mode"]) {
							case "page" :
								_obj.show();
								break;
							default :
								_obj.draw();
								break;
						}
					}
				},
			"error"				:
				function(__dx) {
					_obj.para["subj"].html(jQuery.cmes(2,"ajax"));
				},
			"url"					: _inix.objs["cons"].cons["URLX"] + "/ajax/pdat.php"
		}
	);
}
function tmon_draw() {
	var _obj = this;
	// draw
	{
		var _xml = "";
		if(this.xdat["tmon"].length > 0)
			_xml += '<div style="height:106px"><div xmco="tmon" bran="tmon" indx="' + (Math.floor(Math.random() * this.xdat["tmon"].length)) + '" style="display:none"></div></div>';
		this.para["subj"].html(_xml);
	}
	// even
	{
		var _dton = function() {
			$("[xmco='tmon'][bran='tmon']").fadeOut(1000,
				function() {
					var _indx;
					$(this).html('\
						<div style="height:106px">\
							<div style="float:left;width:100px">\
								<div>' + jQuery.ximg("tmon",_obj.xdat["tmon"][(_indx = (parseInt($(this).attr("indx")) + 1) % _obj.xdat["tmon"].length)]["imag"]) + '</div>\
							</div>\
							<div style="float:right;width:155px;text-align:left;padding:0 2 0 2">\
								<div xmco="tmon" bran="text">' + _obj.xdat["tmon"][_indx]["text"] + '</div>\
								<div xmco="tmon" bran="srce" style="font-style:italic">' + _obj.xdat["tmon"][_indx]["srce"] + '</div>\
							</div>\
						</div>\
						<div style="clear:both"></div>'
					).attr("indx",_indx).fadeIn(1000);
				}
			);
		};
		if($("[xmco='tmon'][bran='tmon']").size() > 0) {
			_dton();
			setInterval(
				function() {
					_dton();
				},
				this.TMON_SHOW_INTR * 1000
			);
		}
	}
}
function tmon_show() {
	// draw
	{
		var _xml = "";
		jQuery.each(this.xdat["tmon"],
			function(_tidx,_tdat) {
				_xml += '\
					<div style="border:1px solid #cccccc;border-width:0 0 1 0;padding:10 0">\
						<div>' + _tdat["text"] + '</div>\
						<div style="float:right"><b>' + _tdat["srce"] + '</b></div>\
						<div style="clear:both"></div>\
					</div>';
			}
		);
		this.para["subj"].html(_xml);
	}
}
