//Created by :Chandra Shekhar 
//Project:Matching Ads
//Created on :18 nov 2008
//Des: Being used on ad_details.php and ad_step3.php

var interval=0;

/*
Name:movenext
DESC:This function for moving images next from the array arimages and shown on elementid*/
function movenext(arimages,elementid)
{
	var curimgindex  =document.getElementById("next").value; 

	curimgindex=Number(curimgindex)+1;
	document.getElementById("next").value=curimgindex;
	if(curimgindex==arimages.length)
	{
		curimgindex=Number(0);
		document.getElementById("next").value=curimgindex;
	}

	showFrameImg(arimages,"frameimg");

	document.getElementById(elementid).innerHTML="<table height='320' width='540'><tr><td align='center'><img src='"+arimages[curimgindex]+"' border='0' class='imgborder' /></td></tr></table>";
	//alert(document.getElementById(elementid).innerHTML);
}

/*
Name:movenext_new
DESC:This function is getting called after every 3 second for slide show*/
function movenext_new()
{
	var arrNameFieldVal = document.getElementById("arrNameField").value;
	//alert(arrNameFieldVal);
	if(arrNameFieldVal == "arBigImg1")
	{
		arrUsedInJs = arBigImg1;
	}
	else if(arrNameFieldVal == "arBigImg2")
	{
		arrUsedInJs = arBigImg2;
	}
	else if(arrNameFieldVal == "arBigImg3")
	{
		arrUsedInJs = arBigImg3;
	}
	else if(arrNameFieldVal == "arBigImg4")
	{
		arrUsedInJs = arBigImg4;
	}
	else if(arrNameFieldVal == "arBigImg5")
	{
		arrUsedInJs = arBigImg5;
	}


	var curimgindex  =document.getElementById("next").value; 

	curimgindex=Number(curimgindex)+1;
	document.getElementById("next").value=curimgindex;
	if(curimgindex==arrUsedInJs.length)
	{
		curimgindex=Number(0);
		document.getElementById("next").value=curimgindex;
	}

	var curimgindex  =document.getElementById("next").value; 
	//alert("vik-->"+arrUsedInJs[curimgindex]);
	showFrameImg(arrUsedInJs,"frameimg");
	//document.getElementById("frameimg").innerHTML="<table height='300' width='250'><tr><td width=100% height=100% align='center'><img src='"+arrUsedInJs[curimgindex]+"' border='0' class='imgborder' /></td></tr></table>";
	//alert(document.getElementById("frameimg").innerHTML);
}

/*
Name:showimage
DESC:This function get called on click on any image to replace image on particular element*/
function showimage(elementid,index,arstring,arbigimage)
{
	
	value=arstring[index];
	setBackForth(arstring,value);
	//MM_showHideLayers('popimage','','hide')
	document.getElementById('popimage').style.display='none'
	showFrameImg(arbigimage,"frameimg");
	document.getElementById(elementid).innerHTML="<table height='320' width='540' border='0'><tr><td align='center'><img src='"+arstring[index]+"' border='0' class='imgborder' /></td></tr></table>";
	
}

/*
Name:moveprev
DESC:This function for moving images previouse from the array arimages and shown on elementid*/
function moveprev(arimages,elementid)
{
	//var curimgindex  =document.getElementById("prev").value;
	var curimgindex  =document.getElementById("next").value; 

	if(curimgindex==0)
	{
		curimgindex=Number(arimages.length-1);
	}
	else
	{
		curimgindex=Number(curimgindex)-1;
	}
	//document.getElementById("prev").value=curimgindex;
	//Only for testing
	document.getElementById("next").value=curimgindex;
	showFrameImg(arimages,"frameimg");
	document.getElementById(elementid).innerHTML="<table height='320' width='540'><tr><td align='center'><img src='"+arimages[curimgindex]+"' border='0' class='imgborder' /></td></tr></table>";
}

/*
Name:setBackForth
DESC:This function set the index for next and previous*/
function setBackForth(arstring,value)
{
	for(i=0;i<arstring.length;i++)
	{
		if(arstring[i]==value)
		{
			document.getElementById("next").value=i;
			document.getElementById("prev").value=i;
		}
	}
}

/*
Name:showFrameImg
DESC:This is for loading images for first time*/
function showFrameImg(arimages,elementid)
{
	var curimgindex  = document.getElementById("next").value; 
	//var curimgindex  = Number(0);
	//alert("current image index "+curimgindex+arimages[curimgindex]);

	document.getElementById(elementid).innerHTML="<table height=320 width=540><tr><td  height=100% width=100% align='center'><img src='"+arimages[curimgindex]+"' border='0' class='imgborder' /></td></tr></table>";
}

/*
Name:playWithFrame
DESC:This functions called on play button*/
function playWithFrame()
{
	showStopButton();
	clearInterval(interval); 
	autoplaytime=document.getElementById("sliderinterval").value;

	//alert("your autoplay time"+autoplaytime);
	interval=setInterval ("movenext_new()", autoplaytime );
}

/*
Name:showStopButton
DESC:Showing stop button while slide show is going on*/
function showStopButton()
{	
	//alert(document.getElementById("play").innerHTML)
	document.getElementById("play").style.display="none";
	document.getElementById("stop").style.display="block";
	//showPlayButton();
}

/*
Name:showPlayButton
DESC:Showing play button by default*/
function showPlayButton()
{
	if(document.getElementById("play")!=null){
	document.getElementById("play").style.display="block";
	document.getElementById("stop").style.display="none";
	}
}

/*
Name:stopWithFrame
DESC:Stop interval*/
function stopWithFrame()
{
	
	setTimeout('movenext_new()',500000);
	window.clearInterval(500000);
	clearInterval(interval); 
	showPlayButton();
}

