$(document).ready(function() {
//	$('.ncticker_element').animate({ right: "300px" }, 1000);
	var child_cnt = ($('.ncticker').children().length);
	var elem_dis=1;
	var small_elem_dis=6;
	var cur_chld=0,small_cur_chld=0, chl_width=592,small_chl_width=84;
	$('.ncticker').css({width: chl_width*child_cnt});
	$('.small_ncticker').css({width: small_chl_width*child_cnt});

//////////// 
	$('.goleft').click(function(e) {
		cur_chld++;
		if(cur_chld>=small_elem_dis)
		small_cur_chld++;
		move_layer(cur_chld,small_cur_chld,e);
		clearInterval(timeintarval);
	})

	$('.goright').click(function(e) {
		cur_chld--;
		if(cur_chld>=small_elem_dis)
		small_cur_chld--;
		move_layer(cur_chld,small_cur_chld,e);
		clearInterval(timeintarval);
	})

	$('.goimage').click(function(e) {
	id_arr=$(this).html().match(/id="?img([0-9]+)"?/);
	cur_chld=id_arr[1];
	move_layer(cur_chld,small_cur_chld,e);
		clearInterval(timeintarval);
	})

	//
	function move_layer_auto()
	{
		cur_chld++;
		if(cur_chld>=small_elem_dis)
		small_cur_chld++;
		move_layer(cur_chld,small_cur_chld,"");
	}
	sbdir="ltr";
	timeintarval=setInterval(move_layer_auto, 6*1000);
	function move_layer(cur_chld1,small_cur_chld1,e)
	{
		
		leftpx=-(chl_width*cur_chld1);
		//alert(cur_chld+"hh"+small_cur_chld);
		smallleftpx=-(small_chl_width*small_cur_chld1);
		$('.ncsmallticker_element img').css({"border": "none"});

		if((parseInt(cur_chld1)+parseInt(elem_dis)-1) >=child_cnt)
		{
			cur_chld=0;
			small_cur_chld=0;
			if(sbdir=='ltr')
			{
				$('.ncticker').animate({left: 0},2000);
				$('.ncsmall_ticker').animate({left: 0},2000);
				$('.ncsmallticker_element #img'+cur_chld).css({"border": "1px solid #990000"});
			}else
			{
				$('.ncticker').animate({right: 0},2000);
			}
		}else if(cur_chld<0)
		{
			
			cur_chld=child_cnt-elem_dis;
			small_cur_chld=child_cnt-small_elem_dis;
			if(sbdir=='ltr')
			{
				$('.ncticker').animate({left: -(chl_width*cur_chld)},2000);
				$('.ncsmallticker_element #img'+cur_chld).css({"border": "1px solid #990000"});
				$('.ncsmall_ticker').animate({left: -(small_chl_width*small_cur_chld)},2000);
			}else
			{
				$('.ncticker').animate({right: -(chl_width*cur_chld)},2000);
			}
		}else
		{
			if(sbdir=='ltr')
			{
				$('.ncticker').animate({left: leftpx},2000);
				$('.ncsmallticker_element #img'+cur_chld1).css({"border": "1px solid #990000"});
				$('.ncsmall_ticker').animate({left: smallleftpx},2000);
			}
			else
			{
				$('.ncticker').animate({right: leftpx},2000);
			}
		}
		//an=$('.ticker').children('div:eq('+cur_chld+')').find('a');
		//alert(an.href)
		if(e!="")
		e.preventDefault();
	}
	
})
