$().ready(function(){
	$(".slideshow").slideshow();
	$(".alert-message .close").click(function(){
		$(this).parent().hide();
	});
});
var Betabears =  new Object();
Betabears.init_login_link = function(o) {
	$(o).attr("href",loginUrl+"?service="+encodeURIComponent(window.location.href));
}

$.fn.slideshow = function() { 
	var length = 0;
	var active_index = 0;
	var slide;
	var $this;
	var $images;
	var $nav;
	return this.each(function(){
		$this = $(this);
		$images = $this.find('.images');
		length = $images.find('DIV').length;
		
		for (i = 0; i < length; i++){
			
			$this.find('.slideshow-nav').append("<span class='"+(i==0?"active":"")+"' index="+i+">"+(i+1)+"</span>"); 
		}
		$this.find('.slideshow-nav span').click(function(){
			var next_index = parseInt($(this).attr("index"));
			if(active_index==next_index)
				return;
			stop();
			slideSwitch(next_index);
		});
		start();
	});
	
	function stop(){
		clearTimeout(slide);
	}
	
	function start(){
		slide=setTimeout(function(){slideSwitch(active_index+1)},3000);
	}
	
	function slideSwitch(next_index) {
		var $active = $images.find('DIV:eq('+active_index+')');
		var $active_nav = $this.find('.slideshow-nav span:eq('+active_index+')');
		
		
		if(next_index==length)
			next_index = 0;
		
	    var $next =  $images.find('DIV:eq('+next_index+')');
	    var $next_nav = $this.find('.slideshow-nav span:eq('+next_index+')');
	    $active.addClass('last-active');
	    

    	$next_nav.addClass('active');
    	$active_nav.removeClass('active');
	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 500, function() {

	            $active.removeClass('active last-active');
	            active_index = next_index;
	            stop();
	            start();
	        });
	        
	}
	
}; 

function addToFavorite(sURL, sTitle) {
	try {
		if(window.sidebar){
			window.sidebar.addPanel(sTitle, sURL, "");

		}else if(window.external){
			window.external.AddFavorite(sURL, sTitle);
		}else if(window.opera && window.print){
			return true;
		}else{
			alert("您所使用的浏览器暂不支持此功能，建议使用Ctrl+D进行添加.");
		}
	} catch (e) {
		alert("您所使用的浏览器暂不支持此功能，建议使用Ctrl+D进行添加.");
	}
}



