var homeLastPosition=1;
var carousel;
var timerID;
$(document).ready(function()
{
	//HOMEPAGE SLIDESHOW
	$('.slideshow').cycle({fx:'fade',speed:1000,timeout:4000,pager:'#nav2'});


	//***** For slider start from here 
	var scrollLeft=$('#scrollLeftImg');
	scrollLeft.mouseover(function()
			       {
 				 scrollDivLeft('mid');
			       }
			       );
	
	scrollLeft.mouseout(function()
			       {
                                 clearTimeout(timerLeft);
			       }
			       );

	
	
	
	var scrollRight=$('#scrollRightImg');
        scrollRight.mouseover(function()
				   {
			             scrollDivRight('mid');
				   }
				 );
	
	scrollRight.mouseout(function()
			       {
                                     clearTimeout(timerRight);
			       }
			       );
	

	
	jQuery('#mycarousel').jcarousel({
	    wrap: 'circular'
	});
	
	//****  For slider end here 
	
	homeNumOfChildren=$('.items>*').size();
	
	
	$('.spinlogo').hover(function()
	{
		$(this).find('span').slideToggle('slow');
	},function()
	{
		$(this).find('span').slideToggle();
	});
	
	

	
	$('.home_slider_navigation_right').click(function()
	{
		clearTimeout(timerID);
		homeLastPosition++;
		if(homeLastPosition>homeNumOfChildren) homeLastPosition=1;
		newstart=homeLastPosition;
        carousel = $(".items").jcarousel(
		{	
			scroll: 1,
			wrap:'circular',
			start:newstart,
			auto:0,
			//itemLoadCallback: mycarousel_initCallback()},
			// This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		timerID=setTimeout("homedonext()",4000);
                 return false;
    });
	$('.home_slider_navigation_left').click(function()
	{
		clearTimeout(timerID);
		homeLastPosition--;
		if(homeLastPosition<1) homeLastPosition=homeNumOfChildren;
		newstart=homeLastPosition;
        carousel = $(".items").jcarousel(
		{	
			scroll: 1,
			wrap:'circular',
			start:newstart,
			auto:0,
			//itemLoadCallback: mycarousel_initCallback()},
			// This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		timerID=setTimeout("homedonext()",4000);
                 return false;
    });
	
	timerID=setTimeout("homedonext()",4000);//activate next every 4 seconds for homepage slideshow
	
	
	$('.navcontainer>ul>li').hover(function()
	{
		$(this).find('ul:first').show();
	},function()
	{
		$(this).find('ul:first').hide();
	});
	
	// External links
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
	
});

function homedonext()
{
	$('.home_slider_navigation_right').trigger("click");
}

$.fn.cycle.transitions.scrollBothWays = function($cont, $slides, opts) {

	$cont.css('overflow','hidden');

	opts.before.push($.fn.cycle.commonReset);



	// custom transition fn (trying to get it to scroll forward and backward)

	opts.fxFn = function(curr, next, opts, cb, fwd) {

		

		var w = $cont.width();

		opts.cssFirst = { left: 0 };

		opts.animIn	  = { left: 0 };

		

		if(fwd){

			opts.cssBefore= { left: w, top: 0 };

			opts.animOut  = { left: 0-w };

		}else{

			opts.cssBefore= { left: -w, top: 0 };

			opts.animOut  = { left: w };

		};

		

		var $l = $(curr), $n = $(next);

		var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animOut = opts.animOut, animIn = opts.animIn;

		$n.css(opts.cssBefore);

		var fn = function() {$n.show();$n.animate(animIn, speedIn, easeIn, cb);};

		$l.animate(animOut, speedOut, easeOut, function() {

			if (opts.cssAfter) $l.css(opts.cssAfter);

			if (!opts.sync) fn();

		});

		if (opts.sync) fn();

	};
};
