//file name parse_xml.js
//---------------------------------
var image_path_arr=Array();

var image_path_thumb_arr=Array();

var image_caption_arr=Array();

var image_caption_link_arr=Array();

var image_heading_arr=Array();

var done=false; 
//--------------

//---------------------------------------------------
function load_xml(path){
// code for IE
	if (window.ActiveXObject){

	  xmlDoc=new ActiveXObject("Msxml2.DOMDocument.3.0");

	  xmlDoc.async=false;

	  xmlDoc.load(path);

	  parse_xml();

	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument){

	  xmlDoc=document.implementation.createDocument("","",null);

	  xmlDoc.load(path);

	  xmlDoc.onload=parse_xml;

	  }
	else {

	  alert('Your browser cannot handle this script');

	  }
}
//-------------------------------------------------------------------------



function check(val,i){
	alert('going into this loop');
	//alert('val=>' + val);
	var j  = i + 1;
	/*if(val != '' || i!= ''){
	alert('inside if loop');
	var j  = i + 1;
	alert('img path=>' + image_path_arr[j])
	val = image_path_arr[j];
	alert('after assign=>'+val);	
	SLIDES.next();
	update_text('next');	
	}
	else{		
	alert('inside else loop');
	SLIDES.next();
	update_text('next');
	}*/
	
	val = image_path_arr[j];
	//j++;
	SLIDES.next();
	update_text('next');

	t=setTimeout('check('+val+','+j+')',image_time);
	alert('at the end');
	/*------------------------------------------------*/	
}
//-------------- 
function change_image(i)
{	
	/*SLIDES = new slideshow("SLIDES");

	alert('SLIDES=>'+ SLIDES );*/
	
	
	//i_no=document.getElementById('image_number').value;

	//alert("this image num previous=>" + i_no);
	document.getElementById('heading').innerHTML=image_heading_arr[i];
	//document.getElementById('heading').style.display="none";
	document.getElementById("caption").innerHTML=image_caption_arr[i];
	
	document.getElementById("caption").href=image_caption_link_arr[i];

	//document.getElementById('image_number').value=i;
	
	document.getElementById("image_position").innerHTML="Image "+(i + 1)+" of "+image_path_arr.length ;

	//onclick=SLIDES.next();update_text('next');loop_pause();
	//alert("this alert in change_image=>" + 'onclick=SLIDES.next();update_text("next");loop_pause();');
	
	/*alert("this image tag=>" + '<img src='+image_path_arr[i]+ ' id=img'+i+' onclick=SLIDES.next();update_text('+next+');loop_pause();>');
	alert("check error");*/
	//document.getElementById('image_div').innerHTML ='<img src='+image_path_arr[i]+ ' id=img'+i+'>';	
	
	var imgsrc = document.getElementById('image_link_title');
	
	//alert('imgsrc' + imgsrc.src);

	imgsrc.src = image_path_arr[i];
	loop_pause();
	

	/*alert('imgsrc2 after change=>' + imgsrc.src);

	imgsrc.onClick = check(imgsrc.src,i);*/

	//alert('image number=>' + document.getElementById('image_number').value);

	//SLIDES.current = i;

	//alert('current=>' + SLIDES.current);

	//SLIDES.src = image_path_arr[i];

	//alert('src=>' + SLIDES.src);

	
	//SLIDES.next1(this.current,this.src);
//----------------------------------------
	//this is where i have adding to move to next image instead of refreshing page.
//---------------------------------
	
/*	SLIDES.next();		
	update_text('next');*/
	
	//alert(SLIDES);
	
	//update_text('next');

	//loop_thru('');	
	
	//<INPUT TYPE="button" VALUE="next&gt;" onClick="SLIDES.next();update_text('next');loop_pause()">
	
	//strkk = setTimeout("location.reload(true);",3000);	
	
}
//-----------------------------------------------------------------

function parse_xml(){

var total=xmlDoc.getElementsByTagName('image').length;

for(i=0;i<total;i++){

            x=xmlDoc.getElementsByTagName('image')[i];

            var maindiv = document.getElementById('thumbmaindiv');

            path=x.getElementsByTagName('location')[0].childNodes[0].nodeValue;

            thumb_path=x.getElementsByTagName('location_thumb')[0].childNodes[0].nodeValue;

            caption=x.getElementsByTagName('caption')[0].childNodes[0].nodeValue;

            caption_link=x.getElementsByTagName('caption_link')[0].childNodes[0].nodeValue;

            headline=x.getElementsByTagName('heading')[0].childNodes[0].nodeValue;            

            image_path_arr[i]=path;

            image_path_thumb_arr[i]=thumb_path;

            image_caption_arr[i]=caption;

            image_caption_link_arr[i]=caption_link;

            image_heading_arr[i]=headline;

            var  nd1 = document.createElement("div");
			//maindiv.style.clear= "both";
			//nd1.style.clear= "both";
			nd1.style.cssFloat="left";
			nd1.style.display="inline";
			nd1.style.padding = "5";
			nd1.style.width ="80";
			nd1.style.height ="60";
			nd1.style.border="0px solid #415757";
			var nd = document.createElement("div");			

            nd.setAttribute("id","thumbmaindiv"+i);
			//nd.style.cssText = 'left:50px; top:50px; right:300px;';
			//nd1.style.position = "relative";
			//nd1.style.cssFloat = 'left';
			
			//alert("here"+nd1.style.properties);

			//alert('nd style=>' + nd.style.position);

			//alert('nd style=>' + nd.style.float);


			/*var subdiv = document.getElementById('thumbmaindiv'+i);
			//<div id="heading" style="position:relative;float:left">
			
			alert('subdiv style=>' + subdiv.style);
			
			/*subdiv.style.position = relative;
			
			alert('postion=>' + subdiv.style.position);*/
			
			//nd.style.display = "block";            


            nd.innerHTML ='<img border=1 width=70 height=54 src="'+image_path_thumb_arr[i]+'" id="'+'img'+i+'" onClick=change_image('+i+');>'; 

			maindiv.appendChild(nd1);
			
			nd1.appendChild(nd);

}

done=true;

return;
}
//----------------------------------------------------------------------
function update_text(opt){ 
	
	i_no=document.getElementById('image_number').value;
	
	//alert('image number getElementById previous in update_text function=>' + i_no);
	if(opt=='next'){

				if(i_no==(image_path_arr.length-1)){

							i_no=0;

				}else{

							i_no++;

				}

	}else if(opt=='previous'){

				if(i_no==0){

							i_no=(image_path_arr.length-1)

				}else{

							i_no--;   

				}

				

	}else if(opt=='new'){

				i_no=0;
	}
	document.getElementById('image_number').value=i_no;
	//alert('image number getElementById after in update_text function=>' + i_no);

	document.getElementById('heading').innerHTML=image_heading_arr[i_no];

	document.getElementById("caption").innerHTML=image_caption_arr[i_no];
    
	//document.getElementById("caption").href=image_caption_link_arr[i_no];

    document.getElementById("navig").href=image_caption_link_arr[i_no];
	//document.getElementById("image_position").innerHTML=image_caption_arr[i_no];
	//"Image "+(i_no+1)+" of "+image_path_arr.length ;
	
	
}//closed function update_text(opt);
 
//----------------------------------------------------------------
function loop_thru(param){
	
			if(param=='new'){
				       clearTimeout(t);  

                        update_text('new');

                        SLIDES.goto_slide(0);
            }else{
						
                        SLIDES.next();

                        update_text('next');

            }            
            t=setTimeout("loop_thru()",image_time);
}
//-------------------------------------------------------------------------- 

function loop_pause()
{
            clearTimeout(t);  
}
//--------------------------------------------------------------
