var ns_result=[];


$(document).ready(function(){
	//
	$.each(ns_result, function(index, value) {
		$(".ns_l_in").append("<a href='"+value[3]+"'>"+value[2]+value[0]+"</a>");	
	});
	//
	$(".ns_l_in a:first").addClass("active");
	$(".ns_img").attr("src", ns_result[0][1]);
	//$(".ns_desc").html(ns_result[0][0]);
	$(".ns_url").attr("href", ns_result[0][3]);
	//
	var ns_size=$(".ns_l_in a").size();
	var ns_rotate = function() {
		var a_act = $(".ns_l_in .active").getIndex();
		var next_act=a_act+1;
		if(next_act==ns_size){
			var next_act=0;	
		}
		$(".ns_l_in .active").removeClass("active", "");
		$(".ns_l_in a:eq("+next_act+")").addClass("active");
		update_targets(next_act);
		/*switch(next_act){
			case 5:
				$(".ns_l_in").animate({top:"-200px"});
			break;
			case 0:
				$(".ns_l_in").animate({top:"0"});				
			break;
		}*/
		if(next_act>4) {
			$(".ns_l_in").animate({top:"-240px"});
		}else{
			$(".ns_l_in").animate({top:"0"});	
		}
    }
	//
	function update_targets(next_act){
		$(".ns_img").attr("src", $.fn.getImg(next_act));
		//$(".ns_desc").html($.fn.getTitle(next_act));
		$(".ns_url").attr("href", $.fn.getUrl(next_act));	
	}
	//
	var ns_timeOut;
	ns_timeOut=setInterval(ns_rotate, 4000);
	//
	$(".ns_top_arrow").click(function(){
		$(".ns_l_in").animate({top:"-240px"});
	});
	//
	$(".ns_bottom_arrow").click(function(){
		$(".ns_l_in").animate({top:"0"});
	});
	//
	$.fn.getIndex = function(){
		var $p=$(this).parent().children();
		return $p.index(this);
	};
	$.fn.getImg = function(a_index){
		return ns_result[a_index][1];
	};
	$.fn.getDesc = function(a_index){
		return ns_result[a_index][2];
	};
  $.fn.getTitle = function(a_index){
		return ns_result[a_index][0];
	};  
	$.fn.getUrl = function(a_index){
		return ns_result[a_index][3];
	};
	//
	$(".ns_l_in a").mouseover(function(){
		$(".ns_l_in .active").removeClass("active", "");
		$(this).addClass("active");
		var a_index = $(this).getIndex();
		update_targets(a_index);
    
	});
	//
	$(".ns_l").mouseover(function(){
		ns_timeOut=clearInterval(ns_timeOut);
	}).mouseout(function(){
		ns_timeOut=setInterval(ns_rotate, 4000);
	});
});
