//ppt slider function/
var timelag;
function slideSwitch() {
    var $active = $(".pptImg li.active");
    var $activeInd = $(".pptInd .pptIndSel");
    if ($active.length == 0) $active = $(".pptImg li:last");
    var $next = $active.next().length ? $active.next()
            : $(".pptImg li:first");
    var $nextInd = $activeInd.next().length ? $activeInd.next()
            : $(".pptInd li:first");
    $activeInd.removeClass("pptIndSel");

    $next.css({opacity: 0.0})
            .addClass("active")
            .animate({opacity: 1.0}, 1000, function() {
        $active.removeClass("active last_active");
    });

    $nextInd.addClass("pptIndSel");
    $active.addClass("last_active");
}

//
$(document).ready(function() {
    //topMEM
  //  $("#topMem").bind("mouseover", function() {
//        $("#topMemDiv").slideToggle(1000).siblings("#topMemDiv").slideUp("slow");
//    });
//    $("#topMemDiv").bind("mouseleave", function() {
//        $("#topMemDiv").hide("normal");
//    });


$(".tt").mouseover(function(){
		$(".tt #topMemDiv").css("display","block");
	}).mouseout(
	function(){
		$(".tt #topMemDiv").css("display","none");
	}
	)



    //navTab
    $(".navTabs>li").each(function(i) {
        $(this).click(function() {
            $("li.navTabsSelected").removeClass("navTabsSelected");
            $(this).addClass("navTabsSelected");
            $("ol.navTabsPanel").removeClass("navTabsPanel");
            $("#tabs-" + i).addClass("navTabsPanel");
        });
    });

    //midSlider
    // click effict
    $(".pptInd li").each(function(i) {
        $(this).click(function() {
            $(".pptInd .pptIndSel").removeClass("pptIndSel");
            $(this).addClass("pptIndSel");
            $(".pptImg li").removeClass("active");
            $(".pptImg li").eq(i).addClass("active");
        });
    });
    //slide effict
    timelag = setInterval("slideSwitch()", 5000);
    $(".hpPpt").mouseover(function() {
        clearInterval(timelag);
    }).mouseout(function() {
        timelag = setInterval("slideSwitch()", 5000);
    });
	//Header Scroll	
	$("#topNewsScroll").marquee({  
	direction: "down",  
	step: 1,  
	speed:5,
	pause: 5000
	});  
	
});

(function($) {
	$.fn.marquee = function(o) {
		
		o = $.extend({
			speed:		parseInt($(this).attr('speed')) || 30, 
			step:		parseInt($(this).attr('step')) || 1,
			direction:	$(this).attr('direction') || 'up', 
			pause:		parseInt($(this).attr('pause')) || 1000 
		}, o || {});
		var dIndex = jQuery.inArray(o.direction, ['right', 'down']);
		if (dIndex > -1) {
			o.direction = ['left', 'up'][dIndex];
			o.step = -o.step;
		}
		var mid;
		var div 		= $(this); 
		var divWidth 	= div.innerWidth(); 
		var divHeight 	= div.innerHeight(); 
		var ul 			= $("ul", div);
		var li 			= $("li", ul);
		var liSize 		= li.size();
		var liWidth 	= li.width(); 
		var liHeight 	= li.height();
		var width 		= liWidth * liSize;
		var height 		= liHeight * liSize;
		if ((o.direction == 'left' && width > divWidth) || 
			(o.direction == 'up' && height > divHeight)) {
			if (o.direction == 'left') {
				ul.width(2 * liSize * liWidth);
				if (o.step < 0) div.scrollLeft(width);
			} else {
				ul.height(2 * liSize * liHeight);
				if (o.step < 0) div.scrollTop(height);
			}
			ul.append(li.clone()); 
			mid = setInterval(_marquee, o.speed);
			div.hover(
				function(){clearInterval(mid);},
				function(){mid = setInterval(_marquee, o.speed);}
			);
		}
		function _marquee() {
			if (o.direction == 'left') {
				var l = div.scrollLeft();
				if (o.step < 0) {
					div.scrollLeft((l <= 0 ? width : l) + o.step);
				} else {
					div.scrollLeft((l >= width ? 0 : l) + o.step);
				}
				if (l % liWidth == 0) _pause();
			} else {
				var t = div.scrollTop();
				if (o.step < 0) {
					div.scrollTop((t <= 0 ? height : t) + o.step);
				} else {
					div.scrollTop((t >= height ? 0 : t) + o.step);
				}
				if (t % liHeight == 0) _pause();
			}
		}
		function _pause() {
			if (o.pause > 0) {
				var tempStep = o.step;
				o.step = 0;
				setTimeout(function() {
					o.step = tempStep;
				}, o.pause);
			}
		}
	};
})(jQuery);

