var content ;
var content1 ;
var contentcontainer ;
var contentcontainer1 ;
var position = 1;
var position1 = 1;
var rot_position = 1;
var rot_position1 = 1;
var rot_timer;
var rot_timer1;
var maxY,maxY1,wd,wd1, maxX, maxX1, ready,ready1, slideDur=1000,slideDur1=1000, destX=0, destX1=0,destY=0,destY1=0, distY,distY1, distX,distX1, per,per1, sliding,sliding1, slideStart,slideStart1, aniTimer,aniTimer1, startX, startY, startX1, startY1, xcoordinate,xcoordinate1, ycoordinate,ycoordinate1,url_path_rotation,url_path_rotation1;

function loadcontent()                //To decide which function will call at onload 
{
	if(0)
	{
		load('tab-con',2800,'ts/');
	}
	else if(0)
	{
		load1('tab-con1',2800,'ts/');
	}
	else
	{
	return ;
	}
}

/*---------------------------------------FOR HOT PRODUCTS-----------------------------------*/
function load(cntId,rot_value,url_path)
{
	clearInterval(rot_timer1);
	position = 0;
	url_path_rotation = url_path;
	if(!document.getElementById)
		return;

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

	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("salin").style.visibility="visible";
	rot_timer = setInterval("do_rotation()",rot_value);
 }
 
 function glideTo(MstartX, MstartY)
{
	content = document.getElementById("content"); 
	contentcontainer = document.getElementById("con-con");
	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 slide(id,img_url)
{
	clearInterval(rot_timer);
	position = id;
	glideTo(eval(id-1) * 0,0);
	for(var z=1;z<=0;z++)
	{
		if(id == z)
		{
			document.getElementById("slide" + id).src = img_url + "slide-on.gif";
		}
		else
		{
			document.getElementById("slide" + z).src = img_url + "slide-off.gif";
		}
	}
	if(id == 0)
	{
		disableAnchor(document.getElementById("slidenext"),true);
		document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
		disableAnchor(document.getElementById("spre"),false);
		document.getElementById("ipre").src = url_path_rotation + "prev.gif";
	}
	if(id == 1)
	{
		disableAnchor(document.getElementById("spre"),true);
		document.getElementById("ipre").src = url_path_rotation + "prev-disable.gif";
		disableAnchor(document.getElementById("slidenext"),false);
		document.getElementById("image_next").src = url_path_rotation + "next.gif";
	}
	if(position > 1  && position < 0)
	{
		disableAnchor(document.getElementById("slidenext"),false);
		document.getElementById("image_next").src = url_path_rotation + "next.gif";
		disableAnchor(document.getElementById("spre"),false);
		document.getElementById("ipre").src = url_path_rotation + "prev.gif";
	}
}

function npre(str,img_url)
{
	clearInterval(rot_timer);
	if(str == "next")
	{
		if(document.getElementById("spre").href == "")
		{
			if(position != 0)
			{
				disableAnchor(document.getElementById("spre"),false);
				document.getElementById("ipre").src = url_path_rotation + "prev.gif";
			}
		}
		if(position < 0)
		{
			position++;
			glideTo(eval(position-1) * 0,0);
			disableAnchor(document.getElementById("slidenext"),false);
			document.getElementById("image_next").src = url_path_rotation + "next.gif";
		}
		if(position == 0)
		{
			disableAnchor(document.getElementById("slidenext"),true);
			document.getElementById("image_next").src = url_path_rotation + "next-disable.gif";
		}
		
	}
	if(str == "pre")
	{
		if(document.getElementById("slidenext").href == "")
		{
			disableAnchor(document.getElementById("slidenext"),false);
			document.getElementById("image_next").src = url_path_rotation + "next.gif";
		}
		if(position > 1)
		{
			position--;
			glideTo(eval(position-1) * 0,0);
			disableAnchor(document.getElementById("spre"),false);
			document.getElementById("ipre").src = url_path_rotation + "prev.gif";
		}
		if(position == 1)
		{
			disableAnchor(document.getElementById("spre"),true);
			document.getElementById("ipre").src = url_path_rotation + "prev-disable.gif";
		}

	}
	for(var z=1;z<=0;z++)
	{
		if(position == z)
		{
			document.getElementById("slide" + position).src = img_url + "slide-on.gif";
		}
		else
		{
			document.getElementById("slide" + z).src = img_url + "slide-off.gif";
		}
	}

}

function do_rotation()
{
	if(position < 0)
	{
		position++;
		glideTo(eval(position-1) * 0,0);
	}
	else
	{
		position = 1;
		content.style.left="0px";
		content.style.top="0px";
	}
	for(var z=1;z<=0;z++)
	{
		if(position == z)
		{
			document.getElementById("slide" + position).src = url_path_rotation + "slide-on.gif";
		}
		else
		{
			document.getElementById("slide" + z).src = url_path_rotation + "slide-off.gif";
		}
	}
}

function disableAnchor(obj, disable)
{
	if(disable)
	{
		var href = obj.getAttribute("href");
		obj.removeAttribute('href');
	}
	else
	{
		if(obj.id == "slidenext")
		{
			obj.setAttribute('href',"Javascript:npre('next','" + url_path_rotation + "')");
		}
		if(obj.id == "spre")
		{
			obj.setAttribute('href',"Javascript:npre('pre','" + url_path_rotation + "')");
		}
	}
}


/*---------------------------------------FOR NEW PRODUCTS-----------------------------------*/

function load1(cntId,rot_value,url_path)
{
	clearInterval(rot_timer);
	position1 = 0;
	url_path_rotation1 = url_path;
	if(!document.getElementById)
		return;

	content1 = document.getElementById("content1"); 
	contentcontainer1 = document.getElementById("con-con1"); 

	content1.visibility="hidden";
	content1.style.top=0;
	content1.style.left=0;
	xcoordinate1=0;
	ycoordinate1=0;
	maxY1=(content1.offsetHeight-contentcontainer1.offsetHeight>0)?content1.offsetHeight-contentcontainer1.offsetHeight:0;
	wd1=cntId?document.getElementById(cntId).offsetWidth:content1.offsetWidth;
	maxX1=(wd1-contentcontainer1.offsetWidth>0)?wd1-contentcontainer1.offsetWidth:0;
	content1.style.visibility="visible";
	ready1=true;
	document.getElementById("salin1").style.visibility="visible";
	rot_timer1 = setInterval("do_rotation1()",rot_value);
 } 
 



function glideTo1(MstartX, MstartY)
{
	content1 = document.getElementById("content1"); 
	contentcontainer1 = document.getElementById("con-con1");
	startX1 = parseInt(content1.style.left);
	if(startX1 == "")
	{
		startX1 = 0;
	}
	startY1 = parseInt(content1.style.top);
	destX1 = -Math.max(Math.min(MstartX, maxX1), 0);
	destY1 = -Math.max(Math.min(MstartY, maxY1), 0);
	distY1 = destY1 - startY1;
	distX1 =  destX1 - startX1;
	per1 = Math.PI/(2 * slideDur1);
	sliding1 = false;
	slideStart1 = (new Date()).getTime();
	aniTimer1 = setInterval("doSlide1()",10);
	on_slide_start1(startX1, startY1);
}


function doSlide1() 
{
	var elapsed = (new Date()).getTime() - slideStart1;
	if (elapsed < slideDur1) 
	{
		var x = startX1 + distX1 * Math.sin(per1*elapsed);
		var y = startY1 + distY1 * Math.sin(per1*elapsed);
		shiftTo1(x, y);
		on_slide1(x, y);
	} 
	else
	{	// if time's up
		clearInterval(aniTimer1);
		sliding1 = false;
		shiftTo1(destX1, destY1);
		//content = null;
		on_slide_end1(destX1, destY1);
	}
}

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

on_slide_start1 = function() {}
on_slide1 = function() {}
on_slide_end1 = function() {}

function slider(id,img_url)
{
	clearInterval(rot_timer1);
	position1 = id;
	glideTo1(eval(id-1) * 0,0);
	for(var z=1;z<=0;z++)
	{
		if(id == z)
		{
			document.getElementById("slider" + id).src = img_url + "slide-on.gif";
		}
		else
		{
			document.getElementById("slider" + z).src = img_url + "slide-off.gif";
		}
	}
	if(id == 0)
	{
		disableAnchor1(document.getElementById("slidenext1"),true);
		document.getElementById("image_next1").src = url_path_rotation1 + "next-disable.gif";
		disableAnchor1(document.getElementById("spre1"),false);
		document.getElementById("ipre1").src = url_path_rotation1 + "prev.gif";
	}
	if(id == 1)
	{
		disableAnchor1(document.getElementById("spre1"),true);
		document.getElementById("ipre1").src = url_path_rotation1 + "prev-disable.gif";
		disableAnchor1(document.getElementById("slidenext1"),false);
		document.getElementById("image_next1").src = url_path_rotation1 + "next.gif";
	}
	if(position1 > 1  && position1 < 0)
	{
		disableAnchor1(document.getElementById("slidenext1"),false);
		document.getElementById("image_next1").src = url_path_rotation1 + "next.gif";
		disableAnchor1(document.getElementById("spre1"),false);
		document.getElementById("ipre1").src = url_path_rotation1 + "prev.gif";
	}
}



function npre1(str,img_url)
{
	clearInterval(rot_timer1);
	if(str == "next")
	{
		if(document.getElementById("spre1").href == "")
		{
			if(position1 != 0)
			{
				disableAnchor1(document.getElementById("spre1"),false);
				document.getElementById("ipre1").src = url_path_rotation1 + "prev.gif";
			}
		}
		if(position1 < 0)
		{
			position1++;
			glideTo1(eval(position1-1) * 0,0);
			disableAnchor1(document.getElementById("slidenext1"),false);
			document.getElementById("image_next1").src = url_path_rotation1 + "next.gif";
		}
		if(position1 == 0)
		{
			disableAnchor1(document.getElementById("slidenext1"),true);
			document.getElementById("image_next1").src = url_path_rotation1 + "next-disable.gif";
		}
		
	}
	if(str == "pre")
	{
		if(document.getElementById("slidenext1").href == "")
		{
			disableAnchor1(document.getElementById("slidenext1"),false);
			document.getElementById("image_next1").src = url_path_rotation1 + "next.gif";
		}
		if(position1 > 1)
		{
			position1--;
			glideTo1(eval(position1-1) * 0,0);
			disableAnchor1(document.getElementById("spre1"),false);
			document.getElementById("ipre1").src = url_path_rotation1 + "prev.gif";
		}
		if(position1 == 1)
		{
			disableAnchor1(document.getElementById("spre1"),true);
			document.getElementById("ipre1").src = url_path_rotation1 + "prev-disable.gif";
		}

	}
	for(var z=1;z<=0;z++)
	{
		if(position1 == z)
		{
			document.getElementById("slider" + position1).src = img_url + "slide-on.gif";
		}
		else
		{
			document.getElementById("slider" + z).src = img_url + "slide-off.gif";
		}
	}

}

function do_rotation1()
{
	if(position1 < 0)
	{
		position1++;
		glideTo1(eval(position1-1) * 0,0);
	}
	else
	{
		position1 = 1;
		content1.style.left="0px";
		content1.style.top="0px";
	}
	for(var z=1;z<=0;z++)
	{
		if(position1 == z)
		{
			document.getElementById("slider" + position1).src = url_path_rotation1 + "slide-on.gif";
		}
		else
		{
			document.getElementById("slider" + z).src = url_path_rotation1 + "slide-off.gif";
		}
	}
}

function disableAnchor1(obj, disable)
{
	if(disable)
	{
		var href = obj.getAttribute("href");
		obj.removeAttribute('href');
	}
	else
	{
		if(obj.id == "slidenext1")
		{
			obj.setAttribute('href',"Javascript:npre1('next','" + url_path_rotation1 + "')");
		}
		if(obj.id == "spre1")
		{
			obj.setAttribute('href',"Javascript:npre1('pre','" + url_path_rotation1 + "')");
		}
	}
}