/* Function for circilar scroll. ROHIT*/
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function topcarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, topcarousel_itemList.length);
	carousel.add(i, mycarousel_getItemHTML(topcarousel_itemList[idx - 1]));
    //carousel.add(i, mycarousel_getItemHTMLTOP(topcarousel_itemList[idx - 1]));
};

function topcarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function thirdcarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, thirdcarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(thirdcarousel_itemList[idx - 1]));
};

function thirdcarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};


function browsedcarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, browsedcarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(browsedcarousel_itemList[idx - 1]));
};

function browsedcarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function mycarousel_getItemHTML(item)
{	

	if(item.path!="")	
	{
	    //return '<a href="'+item.path+'" ><img src="' + item.url + '"  width="83" height="141" alt="' + item.title + '" title="' + item.title + '" /><br>'+item.sorttitle+'</a>';
		return '<a href="'+item.path+'" onmouseover="Tip(\'' + item.title + '\',CENTERMOUSE,\'true\',OFFSETX, 5,OFFSETY, 20, OPACITY, 80, FADEIN,500)" onmouseout="UnTip()" ><img src="' + item.url + '"  width="83" height="141" alt="" title="" /></a>';
	}
	else
		return '<img src="' + item.url + '"  width="83" height="141" alt="' + item.title + '" title="' + item.title + '"  />';
	
};

function mycarousel_getItemHTMLTOP(item)
{	
	if(item.path!="")	
	    return '<a href="'+item.path+'" ><img src="' + item.url + '"  width="83" height="141" alt="' + item.title + '" title="' + item.title + '" onmouseover=showProdInfo(this,event,"'+ escape(item.title)+'")  onmouseout="hideProdInfo()" /></a>';
	else
		return '<img src="' + item.url + '"  width="83" height="141" alt="' + item.title + '" title="' + item.title + '" onmouseover=showProdInfo(this,event,"'+item.title+'")  onmouseout="hideProdInfo()" />';
	
};


/* End of the function of circular scroll.*/


function mycarousel_initCallback(carousel)
{

/* For start and stop. ROHIT */
	
    jQuery('#mycarousel-start').bind('click', function() {
        //carousel.next();
		carousel.startAuto();
		document.getElementById("mycarousel-start-img").className = "playr";
		document.getElementById("mycarousel-stop-img").className = "pause";
		return false;
    });
	
    jQuery('#mycarousel-stop').bind('click', function() {
        //carousel.prev();
		carousel.stopAuto();
		document.getElementById("mycarousel-start-img").className = "play";
		document.getElementById("mycarousel-stop-img").className = "pauser";
        return false;
    });
	
	jQuery('#mycarousel-start-brws').bind('click', function() {
        //carousel.next();
		carousel.startAuto();
		document.getElementById("mycarousel-start-brws-img").className = "playr";
		document.getElementById("mycarousel-stop-brws-img").className = "pause";
        return false;
    });
	
    jQuery('#mycarousel-stop-brws').bind('click', function() {
        //carousel.prev();
		carousel.stopAuto();
		document.getElementById("mycarousel-start-brws-img").className = "play";
		document.getElementById("mycarousel-stop-brws-img").className = "pauser";
        return false;
    });
	
	jQuery('#mycarousel-start-top').bind('click', function() {
        //carousel.next();
		carousel.startAuto();
		document.getElementById("mycarousel-start-top-img").className = "playr";
		document.getElementById("mycarousel-stop-top-img").className = "pause";
        return false;
    });
	
    jQuery('#mycarousel-stop-top').bind('click', function() {
        //carousel.prev();
		carousel.stopAuto();
		document.getElementById("mycarousel-start-top-img").className = "play";
		document.getElementById("mycarousel-stop-top-img").className = "pauser";
        return false;
    });
/* End for start and stop.*/

	// Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto();
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto();
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

/* Function to hide and show label on top image. ROHIT*/
function showProdInfo(obj,event,lable)
{
	//alert("Sai.");
	var ele = event.target;
	var posCnt = 0;
	if(navigator.appName=="Netscape")
	{
		posCnt = obj.offsetLeft+75;
	}
	else
	{
		while (obj = obj.offsetParent) {
			posCnt += obj.offsetLeft+2;
		}
	}
	document.getElementById("prodInfo").style.display = "block";
	document.getElementById("prodInfo").style.position = "absolute";
	document.getElementById("prodInfo").style.left = posCnt+"px";
	document.getElementById("prodInfo").style.top = "20px";
	document.getElementById("lableTD").innerHTML = "<font size='2' color='pink'>"+lable+"</font>";
}

function hideProdInfo()
{
	document.getElementById("prodInfo").style.display = "none";
}

function buttonchange(id1,flag)
{	
/*	if(flag == 0)
	{
		if(id1.className=="play")
			id1.className = "playr";
		else
			id1.className = "play";
	}
	else
	{
		if(id1.className=="pause")
			id1.className = "pauser";
		else
			id1.className = "pause";
	}*/
}



/* End of function to hide and show lable on top menu.*/


jQuery(document).ready(function() {
	
	
	if(document.getElementById("topcarousel"))
	{
		
		//alert("topcarousel");
		
		// Barkat: Please do not remove 
		topcarousel_itemList;
		//alert(browsedcarousel_itemList.length);
		if(topcarousel_itemList.length > 7)
		{
			//scrl = 7
			scrl = 1
		}
		else
		{
			scrl = 0;//browsedcarousel_itemList.length
		}
		// Barkat: Please do not remove 
		
		jQuery('#topcarousel').jcarousel({
			auto: 5,
			scroll: scrl,
			wrap: 'circular',
			animation: 1000,
			initCallback: mycarousel_initCallback,
			itemVisibleInCallback: {onBeforeAnimation: topcarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: topcarousel_itemVisibleOutCallback}
			
			//initCallback: mycarousel_initCallback,
			
		});
	}
	
	
	if(document.getElementById("mycarousel"))
	{
		
				//alert("mycarousel");
		mycarousel_itemList;
		//alert(browsedcarousel_itemList.length);
		if(mycarousel_itemList.length > 7)
		{
			//scrl = 7
			scrl = 1
		}
		else
		{
			scrl = 0;//browsedcarousel_itemList.length
		}
		// Barkat: Please do not remove 	
	
		
		
		jQuery('#mycarousel').jcarousel({
		    auto: 5,
			wrap: 'circular',
			scroll: scrl,
			animation: 1000,
			initCallback: mycarousel_initCallback,
			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
		});
	
	}
		
	
	
	if(document.getElementById("browsedcarousel"))
	{
		//alert("browsedcarousel");
		// Barkat: Please do not remove 
		browsedcarousel_itemList;
		//alert(browsedcarousel_itemList.length);
		if(browsedcarousel_itemList.length > 7)
		{
			//scrl = 7
			scrl = 1
		}
		else
		{
			scrl = 0;//browsedcarousel_itemList.length
		}
		// Barkat: Please do not remove 	
		
		jQuery('#browsedcarousel').jcarousel({
			auto: 5,
			scroll: scrl,
			//visible: 2 ,
			wrap: 'circular',
			animation: 1000,
			initCallback: mycarousel_initCallback,
			itemVisibleInCallback: {onBeforeAnimation: browsedcarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: browsedcarousel_itemVisibleOutCallback}
    });
	
	}
	if(document.getElementById("third-carousel"))
	{
				//alert("third-carousel");
				
		thirdcarousel_itemList;
		//alert(browsedcarousel_itemList.length);
		if(thirdcarousel_itemList.length > 5)
		{
			scrl = 1
		}
		else
		{
			scrl = 0;//browsedcarousel_itemList.length
		}
		// Barkat: Please do not remove 		
		jQuery('#third-carousel').jcarousel({
			vertical: true,
			//visible:4,
			auto: 5,
			scroll: scrl,
			wrap: 'last',
			animation: 2000,
			initCallback: mycarousel_initCallback,
			itemVisibleInCallback: {onBeforeAnimation: thirdcarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: thirdcarousel_itemVisibleOutCallback}
		});
	
	}
});
