var content ;
var contentcontainer ;
var position = 1;
var rot_position = 0;
var rot_timer;
var maxY,wd, maxX, ready, slideDur=1000, destX=0, destY=0, distY, distX, per, sliding, slideStart, aniTimer, startX, startY, xcoordinate, ycoordinate,url_path_rotation;
var totProject;
var capcity = 2;
var imgScroll1 = new Image();imgScroll1.src = "/images/next.gif";
var imgScroll2 = new Image();imgScroll2.src = "/images/next-disable.gif";
var imgScroll3 = new Image();imgScroll3.src = "/images/prev.gif";
var imgScroll4 = new Image();imgScroll4.src = "/images/prev-disable.gif";
function load(cntId,rot_value,url_path,num)
{
	var tabname = document.getElementById("table-content");
	var tdcount = tabname.getElementsByTagName("td");
	var zval = tdcount.length / 3;
	var tdwidth = tdcount.length*132+"px";
	var showwidth =	document.getElementById('table-content').clientWidth;
	showwidth = tdwidth;
	//document.getElementById('table-content').style.width = showwidth;
	totProject = num - 1;

	position = 1;
	url_path_rotation = url_path;
	if(!document.getElementById)
		return;

	content = document.getElementById("content");
	contentcontainer = document.getElementById("content-container"); 

	content.visibility="hidden";
	content.style.top=0;
	content.style.left=0;
	xcoordinate=0;
	ycoordinate=0;
	maxY=(content.offsetHeight-contentcontainer.offsetHeight>0)?content.offsetHeight-contentcontainer.offsetHeight:0;
	wd=cntId?document.getElementById(cntId).offsetWidth:content.offsetWidth;
	maxX=(wd-contentcontainer.offsetWidth>0)?wd-contentcontainer.offsetWidth:0;
	content.style.visibility="visible";
	ready=true;

	//document.getElementById("slide-links").style.visibility="visible";
	document.getElementById("slideprevious").style.visibility="visible";
	document.getElementById("slidenext").style.visibility="visible";
	
	rot_timer = setInterval("do_rotation()",rot_value);
	disableAnchor(document.getElementById("slidenext"),true);
	document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
	disableAnchor(document.getElementById("slideprevious"),true);
	document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";
	
	//alert(num)
 }

function glideTo(MstartX, MstartY)
{
	content = document.getElementById("content"); 
	contentcontainer = document.getElementById("content-container");
	startX = parseInt(content.style.left);
	if(startX == "")
	{
		startX = 0;
	}
	startY = parseInt(content.style.top);
	destX = -Math.max(Math.min(MstartX, maxX), 0);
	destY = -Math.max(Math.min(MstartY, maxY), 0);
	distY = destY - startY;
	distX =  destX - startX;
	per = Math.PI/(2 * slideDur);
	sliding = false;
	slideStart = (new Date()).getTime();
	aniTimer = setInterval("doSlide()",10);
	on_slide_start(startX, startY);
  }



function doSlide() 
{
	var elapsed = (new Date()).getTime() - slideStart;
	if (elapsed < slideDur) 
	{
		var x = startX + distX * Math.sin(per*elapsed);
		var y = startY + distY * Math.sin(per*elapsed);
		shiftTo(x, y);
		on_slide(x, y);
	} 
	else
	{	// if time's up
		clearInterval(aniTimer);
		sliding = false;
		shiftTo(destX, destY);
		//content = null;
		on_slide_end(destX, destY);
	}
}

function shiftTo(x,y)
{
	 if(typeof(x) == "number")
	 {
		content.style.left=x+"px";
		content.style.top=y+"px";
	 }
}

on_slide_start = function() {}
on_slide = function() {}
on_slide_end = function() {}


function next_previous(str,img_url)
{
	clearInterval(rot_timer);
	
	if(str == "next")
	{
		
		if(document.getElementById("slideprevious").href == "")
		{
				disableAnchor(document.getElementById("slideprevious"),false);
				document.getElementById("image_previous").src = url_path_rotation + "prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}		
		if(position < totProject)
		{
			position++;
			glideTo(eval(position-1) * 132,0);
			disableAnchor(document.getElementById("slidenext"),false);
			document.getElementById("image_next").src = url_path_rotation + "next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position == totProject)
		{
			disableAnchor(document.getElementById("slidenext"),true);
			document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		
	}

	if(str == "previous")
	{
		if(document.getElementById("slidenext").href == "")
		{
			disableAnchor(document.getElementById("slidenext"),false);
			document.getElementById("image_next").src = url_path_rotation + "next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position > 1)
		{
			position--;
			glideTo(eval(position-1) * 132,0);
			disableAnchor(document.getElementById("slideprevious"),false);
			document.getElementById("image_previous").src = url_path_rotation + "prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position == 1)
		{
			disableAnchor(document.getElementById("slideprevious"),true);
			document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
	}
	
	//rot_timer = setInterval("do_rotation()",'5000');
}

function do_rotation()
{
//	alert ("Show Position :"+position+" - start rotation");
	if(position < totProject)
	{
		position++;
		glideTo(eval(position-1) * 132,0);
		disableAnchor(document.getElementById("slideprevious"),false);
		document.getElementById("image_previous").src = url_path_rotation + "prev.gif";
		disableAnchor(document.getElementById("slidenext"),false);
		document.getElementById("image_next").src = url_path_rotation + "next.gif";
	}
	else
	{
		position = 1;
		glideTo(eval(position-1) * 132,0);
		disableAnchor(document.getElementById("slideprevious"),false);
		document.getElementById("image_previous").src = url_path_rotation + "prev-disable.gif";
		disableAnchor(document.getElementById("slidenext"),false);
		document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
	}

}

function disableAnchor(obj, disable)
{
	if(disable)
	{
		var href = obj.getAttribute("href");
		obj.removeAttribute('href');
	}
	else
	{
		if(obj.id == "slidenext")
		{
			obj.setAttribute('href',"javascript:next_previous('next','" + url_path_rotation + "')");
		}
		if(obj.id == "slideprevious")
		{
			obj.setAttribute('href',"javascript:next_previous('previous','" + url_path_rotation + "')");
		}
	}
}

//script for makaan popup tab starts here

function showhide (id) {
	var d = document.getElementById(id);
		for (var i=1; i<=2; i++) {
			if (document.getElementById('reporttab0'+i)) {
				document.getElementById('reporttab0'+i).style.display='none';
				document.getElementById('reporttab0'+i+'img').src="/images/new/product-lp/reporttab0"+i+"-off.gif";
			}
		}
	if (d) {
			document.getElementById(d.id+'img').src="/images/new/product-lp/"+d.id+"-on.gif";
			d.style.display='block';
		}
}


var i=1;
var j=1;
var intervalID;
var selval = 1;

function slideshow (id){

	//document.getElementById('slidermenu').style.display='block';
//	var btnaction = document.getElementById("pause").innerHTML;

	for(var i=1; i<=2; i++) {
		if (document.getElementById('slider'+i)){
			//document.getElementById('slider'+i).style.display='none';
			//document.getElementById('showlink'+i).className='showlink';
		}
	}

	//document.getElementById('slider'+selval).style.display='block';
	//document.getElementById('showlink'+selval).className='showactive';

	if (id=="startslide"){
		//alert ("Main if condition : "+id);
		intervalID = setInterval(startslidefn, 5000);
	}

	else if (id!="startslide" && id!="pause" && id!="play" && id!="next" && id!="prev"){
		//alert ("First Else if condition : "+id);
		selval=id;
		for(var i=1; i<=2; i++) {
			if (document.getElementById('slider'+i)){
				//document.getElementById('slider'+i).style.display='none';
				//document.getElementById('showlink'+i).className='showlink';
			}
		}
		//document.getElementById("slider"+id).style.display='block';
		//document.getElementById('showlink'+id).className='showactive';
		clearInterval(intervalID)
//		document.getElementById("pause").innerHTML='play';
//		alert ("Else if Condition - Show value of i : "+i+" - Show value of id : "+id);

//		document.slidevalfrm.slideval.value="slider"+id;
	}



}

function startslidefn (){

	for(var i=1; i<=4; i++) {
		if (document.getElementById('slider'+i)){
			//document.getElementById('slider'+i).style.display='none';
			//document.getElementById('showlink'+i).className='showlink';
		}
	}

	if (j>=2) {
		//document.getElementById('slider1').style.display='block';
		//document.getElementById('showlink1').className='showactive';
//		alert ("If condition where "+j+" greater than 3");
		selval='1';
		j=1;
	}

	else {
		j++;
		//document.getElementById('slider'+j).style.display='block';
		//document.getElementById('showlink'+j).className='showactive';
		selval=j;
//		alert ("Else Condition - Show value of j : "+j);
	}

}


