/*$(document).ready(function() {
	$(".tooltipBlock").each(function(){
		$(this).mouseover(function(e){
			$("body").append("<div id='tooltip'><div class='tooltipText'>" + $(this).attr("title") + "</div></div>");
			$(this).attr("rel", $(this).attr("title"));
			$(this).attr("title", "");
			$("#tooltip").css("top", e.pageY + "px");
			$("#tooltip").css("left", e.pageX + "px");
			if($("#tooltip").width() + $("#tooltip").position().left > $("body").width()){
				$("#tooltip").css("margin-left", -($("#tooltip").width() + $("#tooltip").position().left - $("body").width()) + "px");
			}
		});
		$(this).mouseout(function(){
			$("#tooltip").remove();
			$(this).attr("title", $(this).attr("rel"));
		});
	});
	initSlider();
});
function initSlider(){
	var timerInterval = 3000;
	var timer = 1000;
	
	$(".slider .sliderItem").css("opacity", 0);
	$(".slider .sliderItem").css("display", "none");
	
	var cur = 0;
	var count = $(".slider .sliderItem").size();
	
	doAnimate();
	function doAnimate(){
		$(".slider .sliderItem").eq(cur).css("display", "block");
		$(".slider .sliderItem").eq(cur).animate({
			opacity: 1
		}, timer, function() {
			cur++;
			if(cur > count-1){
				cur = 0;
			}
			
			setTimeout(function(){
				doAnimate();
				doAnimateBack();
			}, timerInterval);
		});
	}
	function doAnimateBack(){
		var prev = cur - 1;
		if(prev < 0){
			prev = count-1;
		}
		$(".slider .sliderItem").eq(prev).animate({
			opacity: 0
		}, timer, function() {
			$(this).css("display", "none");
		});
	}
}
*/


function initFadingImages(){	
	for(var i=0;i<$(".bannerItem").size();i++){
		startAnimation($(".bannerItem").eq(i), i);
	}
}
function startAnimation(obj, num){
	var cur = 0;
	var idInterval;
	
	function doBannerFading(){				
		clearInterval(idInterval);
		for(var i=0; i<$(obj).find("a").size(); i++){
			if(i == cur){				
				$(obj).find("a").eq(i).css("z-index", "10");
				$(obj).find("a").eq(i).animate({
					opacity: 1
				  }, 1000, function() {
					if(cur < $(obj).find("a").size() - 1){
						cur++;
					}
					else{
						cur=0;
					}
					setTimeout(doBannerFading, 3000);
				  });
			}
			else{
				$(obj).find("a").eq(i).css("z-index", "1");
				$(obj).find("a").eq(i).animate({
					opacity: 0
				  }, 1000, function() {
					
				  });					
			}	
		}		
	}
	doBannerFading();
}
