function AddFavorite(sURL, sTitle) {   
    try {   
        window.external.addFavorite(sURL, sTitle);   
    } catch (e) {   
        try {   
            window.sidebar.addPanel(sTitle, sURL, "");   
        } catch (e) {   
            alert("加入收藏失败，请使用Ctrl+D进行添加. Operation failed,please enter Ctrl+D to add.");   
        }   
    }   
}   

$().ready(function(){
	var $news_cont_img = $("#news_cont_img");
	var $pic = $(".news_cont_img img",$news_cont_img);
	$("#news_img_left").click(function(){
		$pic.stop(true,true);//停止所有的动画，并处于末状态
		if(!$pic.is(":animated")){ //判断是否处于动画
			$pic.each(function(){
				var $pic_prev = $(this).parent().prev(); // 获取元素的上一个相邻的节点
				if( $pic_prev.length == 0 ){ //如果 元素的上一个相邻的节点 不存在的话
					var $pic_last = $(".news_cont_img:last img",$news_cont_img);
					var w = $pic_last.width();
					var h = $pic_last.height();
					var l = $pic_last.position().left;
					var t = $pic_last.position().top;
					$(this).animate({
						width:w,
						height:h,
						left:l,
						top:t,
						opacity:0
					},220,function(){
						$(this).parent().appendTo($news_cont_img);
						init();
					});
				}else{ //如果 元素的上一个相邻的节点 存在的话
					$pic_prev = $pic_prev.children("img");
					var w = $pic_prev.width();
					var h = $pic_prev.height();
					var l = $pic_prev.position().left;
					var t = $pic_prev.position().top;
					$(this).css("opacity",1).animate({
						width:w,
						height:h,
						left:l,
						top:t
					},200);
				}
			});
		}
	});

	$("#news_img_right").click(function(){
		$pic.stop(true,true);//停止所有的动画，并处于末状态
		if(!$pic.is(":animated")){ //判断是否处于动画
			$pic.each(function(){
				var $pic_next = $(this).parent().next(); // 获取元素的下一个相邻的节点
				if( $pic_next.length == 0 ){ //如果 元素的上一个相邻的节点 不存在的话
					var $pic_first = $(".news_cont_img:first img",$news_cont_img);
					var w = $pic_first.width();
					var h = $pic_first.height();
					var l = $pic_first.position().left;
					var t = $pic_first.position().top;
					$(this).animate({
						width:w,
						height:h,
						left:l,
						top:t,
						opacity:1
					},220,function(){
						$(this).parent().prependTo($news_cont_img);
						init();
					});
				}else{ //如果 元素的上一个相邻的节点 存在的话
					$pic_next = $pic_next.children("img");
					var w = $pic_next.width();
					var h = $pic_next.height();
					var l = $pic_next.position().left;
					var t = $pic_next.position().top;
					$(this).css("opacity",1).animate({
						width:w,
						height:h,
						left:l,
						top:t
					},200);
				}
			});
		}
	});


//初始化
	function init() {
		$(".news_cont_img:eq(0) img",$news_cont_img).css({
			"z-index":"10"
		});
		$(".news_cont_img:eq(1) img",$news_cont_img).css({
			"z-index":"100"
		});
		$(".news_cont_img:eq(2) img",$news_cont_img).css({
			"z-index":"1000"
		});
		$(".news_cont_img:eq(3) img",$news_cont_img).css({
			"z-index":"100"
		});
		$(".news_cont_img:eq(4) img",$news_cont_img).css({
			"z-index":"10"
		});
		$(".news_cont_img:gt(4) img",$news_cont_img).css({
			"z-index":"1","opacity":"0"
		});
	}

	/* */
	$("#news_cont_img > .news_cont_img > img").click(function(){
		$(this).blur();
		var index = $("#news_cont_img > .news_cont_img > img").index(this);
		if(index!=2){
			if(index<2){
				$("#news_img_right").click();
			}else{
				$("#news_img_left").click();
			}
		}
		return false;
	});
	
	function TextMsg(str){
		var txt = new RegExp("[\\`,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,\\/,\\|,\\:,\\<,\\>,\\{,\\},\\(,\\),\\[,\\],\\;,\\=]");
		if(txt.test(str)){
			return false;
		}else{
			return true;
		}
	}
	
	var msg_submit = $('#ipt_submit');
	msg_submit.click(function(){
		var ipt_msg_title = $('#guest_name'),
			textarea_msg_cont = $('#guest_txtarea'),
			ipt_msg_email = $('#guest_email');
			ipt_msg_tel = $('#guest_tel');
		var reMsgEmail=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		var retelphone = /^\d{5,20}$/;
		var msg_flag = [];
		if(ipt_msg_title.val() != ''){
			msg_flag[0] = TextMsg(ipt_msg_title.val())? 1:0;
		}else{
			alert('请输入标题!Please enter title!');
			msg_flag[0] = 0;
			return false;	
		}
		if(textarea_msg_cont.val() != ''){
			if(textarea_msg_cont.val().length < 10){
				alert('内容过短!The content is too short!')
				msg_flag[1] = 0;
				return false;
			}else{
				msg_flag[1] = TextMsg(textarea_msg_cont.val())?1:0;
			}
		}else{
			alert('请输入内容!Please enter the content!');
			msg_flag[1] = 0;
			return false;
		}
		if(ipt_msg_email.val() != ''){
			if(reMsgEmail.test(ipt_msg_email.val())){
				msg_flag[2] = 1;
			}else{
				alert('邮箱地址不正确!The email seems not correct!');
				msg_flag[2] = 0;
				return false;
			}
		}else{
			alert('请输入邮箱地址!Please enter the email!');
			msg_flag[2] = 0;
			return false;
		}
		if(ipt_msg_tel.val() !=''){
			if(!retelphone.test(ipt_msg_tel.val())){
				alert("电话格式不对哦!The mobile seems not correct!");
				msg_flag[3] = 0;
				return false;
			}else{
				msg_flag[3] = 1;
			}
		}else{
			alert("请输入您的联系电话!Please enter the mobile number!");
			msg_flag[3] = 0;
			return false;
		}
		if(msg_flag[0] == 1 && msg_flag[1] == 1 && msg_flag[2] == 1 && msg_flag[3] == 1){
			document.getElementById("msg_form").submit();
		} 
	});
}) 
