var prev_index = -1; // No testimonial displayed yet. Random index will be set. function loadXMLDoc(url){ var xmlhttp; var txt,x,xx; if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4 && xmlhttp.status==200){ x=xmlhttp.responseXML.documentElement.getElementsByTagName("testimonial"); if(prev_index == -1){ // This is the first time to show since the webpage has been loaded random_index = Math.floor(Math.random() * (x.length)); // set random between 0 ~ length of xml data. }else{ if(prev_index'; xx=x[random_index].getElementsByTagName("image"); if(xx[0]){ try{ txt=txt + '' + xx[0].firstChild.nodeValue + ''; }catch(er){ txt=txt + 'xml format error: image alt'; } } txt=txt+''; txt=txt+'
'; xx=x[random_index].getElementsByTagName("testim_title"); if(xx[0]){ try{ txt=txt + ''; }catch(er){ txt=txt + 'xml format error: testimonial title'; } } xx=x[random_index].getElementsByTagName("testim_text"); if(xx[0]){ try{ txt=txt + '
' + xx[0].firstChild.nodeValue + '
'; }catch(er){ txt=txt + 'xml format error: testimonial text'; } } xx=x[random_index].getElementsByTagName("name"); if(xx[0]){ try{ txt=txt + '
' + xx[0].firstChild.nodeValue + '
'; }catch(er){ txt=txt + 'xml format error: name'; } } xx=x[random_index].getElementsByTagName("position"); if(xx[0]){ try{ txt=txt + '
- ' + xx[0].firstChild.nodeValue + '
'; }catch(er){ txt=txt + ''; } } txt=txt+'
'; function nextTestimonial(){ $("#testimonial #sliding_content").html(txt); } $("#testimonial #sliding_content").effect('slide', { direction: "left", mode: "hide"},250,nextTestimonial); $("#testimonial #sliding_content").effect('slide', { direction: "right", mode: "show"},500); } } xmlhttp.open("GET",url,true); xmlhttp.send(); t=setTimeout("loadXMLDoc('testimonial_data.php')", 4000); } $(document).ready(function(){ loadXMLDoc('testimonial_data.php'); });