var content ;
var contentcontainer ;
var position = 1;
var rot_position = 0;
var rot_timer;
var maxY,wd, maxX, ready, slideDur=600, destX=0, destY=0, distY, distX, per, sliding, slideStart, aniTimer, startX, startY, xcoordinate, ycoordinate,url_path_rotation;

//alert ("Expert Page");

//scroller for expert starts here
function expert_scroller(cntId,rot_value,url_path) {
	var tabname = document.getElementById("expert-table-content");
	var tdcount = tabname.getElementsByTagName("td");
//	var zval = tdcount.length / 3;
//	alert (zval);
//	alert ("Number of TD : "+tdcount.length);
//	alert ("Calculated Table Width : "+tdcount.length*160);
	var tdwidth = tdcount.length*160+"px";
	var showwidth =	document.getElementById('expert-table-content').clientWidth;
	showwidth = tdwidth;
//	alert (showwidth = tdwidth);
	document.getElementById('expert-table-content').style.width = showwidth;
	
	position = 1;
	url_path_rotation = url_path;
	if(!document.getElementById)
		return;

	content = document.getElementById("expert-content");
	contentcontainer = document.getElementById("expert-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("expert-slide-links").style.visibility="visible";
	document.getElementById("expert-slideprevious").style.visibility="visible";
	document.getElementById("expert-slidenext").style.visibility="visible";

	rot_timer = setInterval("expert_do_rotation()",rot_value);

	expert_disableAnchor(document.getElementById("expert-slidenext"),true);
	document.getElementById("expert-image_next").src = url_path_rotation + "blue-disable-arrow-next.gif";

	expert_disableAnchor(document.getElementById("expert-slideprevious"),true);
	document.getElementById("expert-image_previous").src = url_path_rotation + "blue-disable-arrow-prev.gif";

 }

function expert_glideTo(MstartX, MstartY) {
	content = document.getElementById("expert-content"); 
	contentcontainer = document.getElementById("expert-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("expert_doSlide()",10);
	on_slide_start(startX, startY);
  }



function expert_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);
		expert_shiftTo(x, y);
		on_slide(x, y);
	} 
	else
	{	// if time's up
		clearInterval(aniTimer);
		sliding = false;
		expert_shiftTo(destX, destY);
		//content = null;
		on_slide_end(destX, destY);
	}
}

function expert_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 expert_next_previous(str,img_url) {
	clearInterval(rot_timer);

//	alert ("Start position value: "+position);

	if(str == "next") {
		
		if(document.getElementById("expert-slideprevious").href == "") {
			expert_disableAnchor(document.getElementById("expert-slideprevious"),false);
			document.getElementById("expert-image_previous").src = url_path_rotation + "blue-arrow-prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}		
		if(position < 7) {
			position++;
			expert_glideTo(eval(position-1) * 160,0);
			expert_disableAnchor(document.getElementById("expert-slidenext"),false);
			document.getElementById("expert-image_next").src = url_path_rotation + "blue-arrow-next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position == 7) {
			expert_disableAnchor(document.getElementById("expert-slidenext"),true);
			document.getElementById("expert-image_next").src = url_path_rotation + "blue-disable-arrow-next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		
	}

	if(str == "previous") {
		if(document.getElementById("expert-slidenext").href == "")
		{
			expert_disableAnchor(document.getElementById("expert-slidenext"),false);
			document.getElementById("expert-image_next").src = url_path_rotation + "blue-arrow-next.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position > 1) {
			position--;
			expert_glideTo(eval(position-1) * 160,0);
			expert_disableAnchor(document.getElementById("expert-slideprevious"),false);
			document.getElementById("expert-image_previous").src = url_path_rotation + "blue-arrow-prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}
		if(position == 1) {
			expert_disableAnchor(document.getElementById("expert-slideprevious"),true);
			document.getElementById("expert-image_previous").src = url_path_rotation + "blue-disable-arrow-prev.gif";
//			alert ("Next Condition - Clicked position value : "+position);
		}

	}
}

function expert_do_rotation() {
//	alert ("Show Position :"+position+" - start rotation");
	if(position < 7	) {
		position++;
		expert_glideTo(eval(position-1) * 160,0);
		expert_disableAnchor(document.getElementById("expert-slideprevious"),false);
		document.getElementById("expert-image_previous").src = url_path_rotation + "blue-arrow-prev.gif";
		expert_disableAnchor(document.getElementById("expert-slidenext"),false);
		document.getElementById("expert-image_next").src = url_path_rotation + "blue-arrow-next.gif";
	}
	else {
		position = 1;
		content.style.left="0px";
		content.style.top="0px";
		expert_disableAnchor(document.getElementById("expert-slideprevious"),false);
		document.getElementById("expert-image_previous").src = url_path_rotation + "blue-disable-arrow-prev.gif";
		expert_disableAnchor(document.getElementById("expert-slidenext"),false);
		document.getElementById("expert-image_next").src = url_path_rotation + "blue-disable-arrow-next.gif";
	}

}

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

//scroller for expert ends here

