	
//////////////////////////////////////////
	

	
	//global variables
	var currentpagenumber = 0;
	var itemsperpage = 0;
	var totalnumber = 0;
	var xmlDoc;
	var client = 0; // 0 ie 1 firefox
	var numberpersection = 0;
	var arr = new Array();
	var currentitem = 0;
///////////////////////////////////////


window.addEvent('domready', function(){
	
	try //Internet Explorer
  {
  	client = 0;
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    	client = 1;
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e) {alert(e.message);client = 0;}
  }
	
	
	
 //init
	currentpagenumber = 1;
	itemsperpage = 3;
	numberpersection = 3;
	currentitem =0;
	
	loadXML('testimonials.xml');
	
	showTestimonials();
	
	

});

//////////////////////////////////////////////

//Mootool
var flag_1 = 0;
function Effect($obj)
	{
		
		
		if($($obj)== null) return false;
		
	var el = $($obj),
		color = el.getStyle('backgroundColor');
			
	$($obj).set('opacity', 1).addEvents({
		mouseenter: function(){
		_("image").innerHTML="<img id='building' src='Images/loading_wh.gif' />";
		//alert(_("1").style.height);
			//if(_("1").style.height > "105px") _highlight("1");
			
			//message("this.id: "+this.id,1);
			//alert(0);
			//alert("this.id "+this.id);
			if("1" == this.id) {highlight($("1"));_highlight($("2"));_highlight($("3"));if($("1").getElement('input')) updateImage('building',$("1").getElement('input').value);return;}
			if("2" == this.id) {highlight($("2"));_highlight($("1"));_highlight($("3"));if($("2").getElement('input')) updateImage('building',$("2").getElement('input').value);return;}
			if("3" == this.id) {highlight($("3"));_highlight($("1"));_highlight($("2"));if($("3").getElement('input')) updateImage('building',$("3").getElement('input').value);return;}
			
			
		
		},
		mouseleave: function(){
			
			//message("mouse leave",1);
			//_highlight(this);
			
		}
	});

	
	
		
	}
	

	
function highlight(obj)
{



//message("hightlight "+obj.id,1);

	
	obj.morph({
				
				'background-color': '#fff',
				'color':'#a11111',
				'border-color':'#a11111'
				
			});
			
	obj.set('tween', {
				duration: 1000,
				transition: Fx.Transitions.Sine.easeOut // This could have been also 'bounce:out'
			}).tween('height', '210px');
			
}

function _highlight(obj)
{
	
			obj.morph({
						
						'background-color': '#f9f9f9',
						'color':'#333',
						'border-color':'#cccccc'
						
					});
			
			// Resets the tween and changes the element back to its original size
			obj.set('tween', {}).tween('height', '105px');
}
	
////////////////////////////////////////////////////
	
function loading()
{
	
	_("1").innerHTML="<img src='Images/loading_wh.gif' />";
	_("2").innerHTML="<img src='Images/loading_wh.gif' />";
	_("3").innerHTML="<img src='Images/loading_wh.gif' />";
	_("image").innerHTML="<img id='building' src='Images/loading_wh.gif' />";
	
	}
	
function loadXML(xmlFile)
{
	if(client)
	{
	var d = new XMLHttpRequest();
d.open("GET", xmlFile, false);
d.send(null);
xmlDoc=d.responseXML;
	}
	else {
		
 xmlDoc.async="false";
 
 xmlDoc.onreadystatechange=verify;
 
 xmlDoc.load(xmlFile);
 
 xmlObj=xmlDoc.documentElement;
	}
 
 return true;
}
	
function verify()
{
 // 0 Object is not initialized
 // 1 Loading object is loading data
 // 2 Loaded object has loaded data
 // 3 Data from object can be worked with
 // 4 Object completely initialized
 if (xmlDoc.readyState != 4)
 {
   return false;
 }
}
	
function delay(fun,sec){setTimeout(fun,sec*1000);}

//prev
function prev()
{

	
	
	loading();
	delay("goto(-1)",0.2);
	
}//end prev
	
	
	
// next
function next()
{
	
	
		loading();
		delay("goto(1)",0.2);
	
	
	
}//end next
	
	
function goto(tag)
{

	var start;
	var end;
	var mid;
	var temp;
	//alert(currentitem);
	if(tag==-1) currentitem=currentitem -itemsperpage*2;
	//alert(currentitem);
	if(currentitem<0) currentitem=currentitem +totalnumber;
	//alert(currentitem);
	if(currentitem>totalnumber) currentitem=currentitem-totalnumber;
	//	alert(currentitem);
		//remove the number first
		_("number").innerHTML = "";
		
		//show first img
		
		_("number").innerHTML += "<a href=\"javascript:prev();\" onfocus=\"javascript:this.blur()\" class=img><img src=\"Images/Prev.gif\" border=0 ></a> ";
		

		//show next img
		_("number").innerHTML += "<a href=\"javascript:next();\" onfocus=\"javascript:this.blur()\" class=img><img src=\"Images/Next.gif\" border=0  ></a>";
		
		
		var j=1;
		if(client){
			for(var i= currentitem ; j < itemsperpage+1 ; i++,j++)
				{
				
				if(i>=totalnumber) i=i-totalnumber;
				
					_(j).innerHTML = xmlDoc.getElementsByTagName("desc")[i].childNodes[1].nodeValue;
					_(j).innerHTML +="<input type=hidden id=data value='"+Get_XML_Node_Attr(xmlDoc.getElementsByTagName("item")[i],"img")+"'>";
					
				}
				currentitem = i;
			
			}
		else
			{
				for(var i= currentitem ; j < itemsperpage+1 ; i++,j++)
				{
				if(i>=totalnumber) i=i-totalnumber;
					_(j).innerHTML = xmlDoc.getElementsByTagName("item")[i].childNodes[0].text;
					//alert(Get_XML_Node_Attr(xmlDoc.getElementsByTagName("item")[i],"img"));
					_(j).innerHTML +="<input type=hidden id=data value='"+Get_XML_Node_Attr(xmlDoc.getElementsByTagName("item")[i],"img")+"'>";
					
				}
				currentitem = i;
			}
		
		
		
		
		//hightlight No.1
		highlight($("1"));_highlight($("2"));_highlight($("3"));
		//alert($("1"));
		
		updateImage('building',_("data").value);
		//_("image").innerHTML = "<img  src='"+_("data").value+"' >";
	
	
}//end goto
	
//message box
function message(msg ,sec)
{
	_("message").innerHTML = msg;
	setTimeout("removemsg()",sec*1000);
}
function removemsg(){_("message").innerHTML = "";}
	
function showTestimonials(){ 
		
	//load xml obj xmlDoc
	
	
	//set total number
	if(!client){
		totalnumber = xmlDoc.getElementsByTagName("items")[0].childNodes.length;
}
else {totalnumber = xmlDoc.getElementsByTagName("item").length;}


			if(totalnumber >2)
			{
			loading();
			Effect('1');
			Effect('2');
			Effect('3');
			goto(1);
			
		}
		else{
			//for waiting xml loading
			message("Loading...",0.5);
			setTimeout("showTestimonials()",1000);
			}
	
	
		
		
		
}//end page break
	
//base function ////////////////////////////////////////////


//
function Get_XML_Node_Attr(pNode,pAttribute){  
 try{  
 return pNode.attributes.getNamedItem(pAttribute).nodeValue;  
 }catch(e){  
  
 return false;  
 }  
}

//return object
function _(obj){return document.getElementById(obj);}


function updateImage(id,url){
   var image=new Image;
   image.src=url;
   image.onload=function(){
    document.getElementById(id).src=url;
   }
  }
	
	
	

	
	

	