﻿var timeout;
cache = new Object();

var t = n = count = 0;  
function showAuto()    
{    
    n = n >= (count - 1) ? 0 : n + 1;    
    $("#play_text li").eq(n).trigger('click');    
} 
jQuery.getCookie=function(name,div){
    if($.cookie(name)==0){
	  var node=$("#"+div);
	 // alert(node);
	$("#"+div).hide();
		}
	else{
		$("#"+div).show();
	}
}
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


function buildWlwzLink(site,tid){
	var linkstr;
	switch(site){
		case "fswz":linkstr = "http://wz.foshan.gov.cn/viewthread.jsp?tid=" + tid;break;
		case "nhwz":linkstr = "http://wz.nanhai.gov.cn/viewthread.jsp?tid=" + tid;break;
		case "gmwz":linkstr = "http://wz.gaoming.gov.cn/viewthread.jsp?tid=" + tid;break;
		case "sswz":linkstr = "http://wz.sanshui.gov.cn/viewthread.jsp?tid=" + tid;break;
		case "ccwz":linkstr = "http://wz.chancheng.gov.cn/viewthread.jsp?tid=" + tid;break;
		case "sdwz":linkstr = "http://wz.shunde.gov.cn/viewthread.jsp?tid=" + tid;break;
		default:linkstr = "http://wz.foshan.gov.cn/viewthread.jsp?tid=" + tid;
		}
		return linkstr;
	}
	
	function buildWlwzTitle(site,title,fname){
	switch(site){
		case "fswz":{
			var name = fname.length>5?fname.substring(0,5)+"…":fname;
			title = "[" + name + "]" + title;
			break;
			}
		case "nhwz":title = "[南海区]" + title;break;
		case "gmwz":title = "[高明区]" + title;break;
		case "sswz":title = "[三水区]" + title;break;
		case "ccwz":title = "[禅城区]" + title;break;
		case "sdwz":title = "[顺德区]" + title;break;
		default:{
			var name = fname>5?fname.substring(0,5):fname;
			title = "[" + name + "]" + title;
			break;
			}
		}
		return title;
	}
	
$(function(){
		   //today news
    $(".xw_xx_top div").each(function(index){
	       var divNode=$(this);
		   divNode.mouseover(function(){
			timeout=setTimeout(function(){				  
				 $(".xw_xx_top div.xw_xx_top_1").addClass("xw_xx_top_2");
			     $(".xw_xx_top div.xw_xx_top_1").removeClass("xw_xx_top_1");
				 divNode.addClass("xw_xx_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("xw_xx_top_2");
				 $(".xw_zi").removeClass("xw_zi");
				 $(".xw_zi_full div").eq(index).addClass("xw_zi");
				 if(3==index){
					 if(cache.wlwz){
						 $("#wlwznr1").html(cache.wlwz);
						 }else{
							 
					 $.ajax({    
                         async:false,    
                         url: 'http://wz.foshan.gov.cn/ajax.jsp', 
                         type: 'get',    
                         dataType: 'jsonp',    
                         jsonp: 'callback', //默认callback   
                         data:{action:"threadsJ",fid:"87,39,38,40,23,2,7,19,21,20",size:7,inc:0,type:"lastReply"}, //请求数据   
                         timeout: 5000,
                         beforeSend: function(){},   
                         success: function (json) {  
                         if(json.status==true){
                             var wlwznr = $("#wlwznr1");
                             for(var i=0;i<7;i++){
                   		        var title = json.datas[i].subject;
                   		        title = title.length>20?title.substring(0,23)+"…":title;
                   		        title = buildWlwzTitle(json.datas[i].site,title,json.datas[i].fname);
                   		        var link = buildWlwzLink(json.datas[i].site,json.datas[i].tid);
                   		        var appendStr = "<li><a href='" + link + "' target='_blank'>"+title+"</a>"+json.datas[i].dateline.substring(5)+"</li>";
								$("#loading").hide();
                   		        $(wlwznr).append(appendStr);
                   }
				   cache.wlwz=$(wlwznr).html();
				   
               }
           },
           complete: function(XMLHttpRequest, textStatus){
                 
           },
           error: function(xhr){
               //jsonp 方式此方法不被触发
               //请求出错处理
               //alert("请求出错(请检查相关度网络状况.)");
           }
       });
					
							 }
				 }else
				  $(".xw_zi_full div").eq(index).addClass("xw_zi");
			 },300);
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
	
	//干部任免
	  $(".zpxx_top div").each(function(index){
	       var divNode=$(this);
		   divNode.mouseover(function(){
			 if(2!=index)
			timeout=setTimeout(function(){				  
				 $(".zpxx_top div.zpxx_top_1").addClass("zpxx_top_2");
			     $(".zpxx_top div.zpxx_top_1").removeClass("zpxx_top_1");
				 divNode.addClass("zpxx_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("zpxx_top_2");
				 $(".zpxx_zi").removeClass("zpxx_zi");
				 $(".zpxx_zi_full div").eq(index).addClass("zpxx_zi");
			 },300);
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
	  //government official
	   $(".xwwj_top div").each(function(index){
	       var divNode=$(this);
		   divNode.mouseover(function(){
			if(2!=index)
			timeout=setTimeout(function(){				  
				 $(".xwwj_top div.xwwj_top_1").addClass("xwwj_top_2");
			     $(".xwwj_top div.xwwj_top_1").removeClass("xwwj_top_1");
				 divNode.addClass("xwwj_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("xwwj_top_2");
				 $(".xwwj_zi").removeClass("xwwj_zi");
				 $(".xwwj_zi_full div").eq(index).addClass("xwwj_zi");
			 },300);
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
	   //government purchase
	   $(".cgjy_top div").each(function(index){
	       var divNode=$(this);
		   divNode.mouseover(function(){
			if(2!=index)
			timeout=setTimeout(function(){				  
				 $(".cgjy_top div.cgjy_top_1").addClass("cgjy_top_2");
			     $(".cgjy_top div.cgjy_top_1").removeClass("cgjy_top_1");
				 divNode.addClass("cgjy_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("cgjy_top_2");
				 $(".cgjy_zi").removeClass("cgjy_zi");
				 $(".cgjy_zi_full div").eq(index).addClass("cgjy_zi");
			 },300);
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
	   //personal service 
	   $(".zfbssx_nr_na div").each(function(index){
	       var divNode=$(this);
		   divNode.mouseover(function(){
			timeout=setTimeout(function(){				  
				 $(".zfbssx_nr_na div.zfbssx_nr_na_1bg").addClass("zfbssx_nr_na_2bg");
			     $(".zfbssx_nr_na div.zfbssx_nr_na_1bg").removeClass("zfbssx_nr_na_1bg");
				 divNode.addClass("zfbssx_nr_na_1bg");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("zfbssx_nr_na_2bg");
				 $(".xzsp").removeClass("xzsp");
				$(".xzsp_full div").eq(index).addClass("xzsp");
			 },300);
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
	   //对话民生切换js
	    $(".dhms_top div").each(function(index){
	       var divNode=$(this);
			divNode.css("cursor","pointer");
		   divNode.mouseover(function(){
			 if(3!=index)
			timeout=setTimeout(function(){
				 $(".dhms_top div.dhms_top_1").addClass("dhms_top_2");
			     $(".dhms_top div.dhms_top_1").removeClass("dhms_top_1");
				 divNode.addClass("dhms_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("dhms_top_2");
			   
			   

				if(index==0){
					  document.getElementById("dhms1").style.display="block"; 
					  document.getElementById("dhms2").style.display="none"; 
					 document.getElementById("dhms3").style.display="none"; 
				}else if(index==1){
					 document.getElementById("dhms1").style.display="none"; 
					  document.getElementById("dhms2").style.display="block"; 
					 document.getElementById("dhms3").style.display="none"; 
				}else if(index==2){
					document.getElementById("dhms1").style.display="none"; 
					  document.getElementById("dhms2").style.display="none"; 
					 document.getElementById("dhms3").style.display="block"; 
				}
			 },0);
									  
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
		   //网上信访js
	    $(".wzx_top div").each(function(index){
	       var divNode=$(this);
			divNode.css("cursor","pointer");
		   divNode.mouseover(function(){
			 if(3!=index)
			timeout=setTimeout(function(){
				 $(".wzx_top div.wzx_top_1").addClass("wzx_top_2");
			     $(".wzx_top div.wzx_top_1").removeClass("wzx_top_1");
				 divNode.addClass("wzx_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("wzx_top_2");
			   
			   

				if(index==0){
					  document.getElementById("wsxf1").style.display="block"; 
					  document.getElementById("wsxf2").style.display="none"; 
					  document.getElementById("wsxf3").style.display="none"; 
				}else if(index==1){
					  document.getElementById("wsxf1").style.display="none"; 
					  document.getElementById("wsxf2").style.display="block"; 
					  document.getElementById("wsxf3").style.display="none"; 
				}else if(index==2){
					  document.getElementById("wsxf1").style.display="none"; 
					  document.getElementById("wsxf2").style.display="none"; 
					  document.getElementById("wsxf3").style.display="block"; 
				}
			 },0);
									  
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
//建言献策
	    $(".jmz_top div").each(function(index){
	       var divNode=$(this);
			divNode.css("cursor","pointer");
		   divNode.mouseover(function(){
			 if(3!=index)
			timeout=setTimeout(function(){
				 $(".jmz_top div.jmz_top_1").addClass("jmz_top_2");
			     $(".jmz_top div.jmz_top_1").removeClass("jmz_top_1");
				 divNode.addClass("jmz_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("jmz_top_2");
			   
			   

				if(index==0){
					  document.getElementById("jyxc1").style.display="block"; 
					  document.getElementById("jyxc2").style.display="none"; 
					  document.getElementById("jyxc3").style.display="none"; 
				}else if(index==1){
					  document.getElementById("jyxc1").style.display="none"; 
					  document.getElementById("jyxc2").style.display="block"; 
					  document.getElementById("jyxc3").style.display="none"; 
				}else if(index==2){
					  document.getElementById("jyxc1").style.display="none"; 
					  document.getElementById("jyxc2").style.display="none"; 
					  document.getElementById("jyxc3").style.display="block"; 
				}
			 },0);
									  
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
		
//实用信息
	    $(".sfg_top div").each(function(index){
	       var divNode=$(this);
			divNode.css("cursor","pointer");
		   divNode.mouseover(function(){
			 if(3!=index)
			timeout=setTimeout(function(){
				 $(".sfg_top div.sfg_top_1").addClass("sfg_top_2");
			     $(".sfg_top div.sfg_top_1").removeClass("sfg_top_1");
				 divNode.addClass("sfg_top_1");
				 divNode.css("cursor","pointer");
				 divNode.removeClass("sfg_top_2");
			   
			   

				if(index==0){
					  document.getElementById("syxx1").style.display="block"; 
					  document.getElementById("syxx2").style.display="none"; 
					  document.getElementById("syxx3").style.display="none"; 
				}else if(index==1){
					  document.getElementById("syxx1").style.display="none"; 
					  document.getElementById("syxx2").style.display="block"; 
					  document.getElementById("syxx3").style.display="none"; 
				}else if(index==2){
					  document.getElementById("syxx1").style.display="none"; 
					  document.getElementById("syxx2").style.display="none"; 
					  document.getElementById("syxx3").style.display="block"; 
				}
			 },0);
									  
			}); 
		   divNode.mouseout(function(){
		      clearTimeout(timeout);						 
		});
	});
		
	  $("#fwly_2011_hhs>div").eq(1).mousemove(
			function(){
					var timeoutId=setTimeout(function(){},100);
					$("#close_apDiv>div").hide();
					clearTimeout(timeoutId);
				}
		);
		
	  $(".jypx").hover(
					   	  function(){
							 $("#apDiv1").show();},
						  function(){
		                    var timeoutId=setTimeout(function(){$("#apDiv1").hide();},100);
		                    $("#apDiv1").hover(
									function(){clearTimeout(timeoutId);},
						  			function(){$("#apDiv1").hide();});
							}
	  );
	  $(".shfu").hover(function(){
		                   $("#apDiv2").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv2").hide();},100);
		                   $("#apDiv2").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv2").hide();});
	  });
	  $(".qjjy").hover(function(){
		                   $("#apDiv3").show(); 
	                    },
						  function(){
		                    var timeoutId=setTimeout(function(){$("#apDiv3").hide();},100);
		                    $("#apDiv3").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv3").hide();});
	  });

	$(".bjyl").hover(function(){
		                   $("#apDiv4").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv4").hide();},100);
		                    $("#apDiv4").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv4").hide();});
	  });
	  $(".zffw").hover(function(){
		                   $("#apDiv5").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv5").hide();},100);
		                    $("#apDiv5").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv5").hide();});
	  });
	  $(".jtcx").hover(function(){
		                   $("#apDiv6").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv6").hide();},100);
		                    $("#apDiv6").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv6").hide();});
	  });
	  
	  $(".zzrd").hover(function(){
		                   $("#apDiv7").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv7").hide();},100);
		                    $("#apDiv7").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv7").hide();});
	  });
	  
	  $(".qykb").hover(function(){
		                   $("#apDiv8").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv8").hide();},100);
		                    $("#apDiv8").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv8").hide();});
	  });
	  
	  $(".zjbl").hover(function(){
		                   $("#apDiv9").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv9").hide();},100);
		                    $("#apDiv9").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv9").hide();});
	  });
	  
	  $(".cjsfw").hover(function(){
		                   $("#apDiv10").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv10").hide();},100);
		                    $("#apDiv10").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv10").hide();});
	  });

	  $(".jyns").hover(function(){
		                   $("#apDiv11").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv11").hide();},100);
		                    $("#apDiv11").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv11").hide();});
	  });

	  $(".bsfw_zzrd").hover(function(){
		                   $("#apDiv12").show(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv12").hide();},100);
		                    $("#apDiv12").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv12").hide();});
	  });
//flash
	   count = $("#play_list a").size();    
    $("#play_list a:not(:first-child)").hide();    
    $("#play_info").html($("#play_list a:first-child").find("img").attr('alt'));    
    $("#play_text li:first-child").css({"background":"#F00",'color':'#000'});    
    $("#play_info").click(function(){window.open($("#play_list a:first-child").attr('href'), "_blank")});    
    $("#play_text li").click(function() {    
        var i = $(this).text() - 1;    
        n = i;    
        if (i >= count) return;    
        $("#play_info").html($("#play_list a").eq(i).find("img").attr('alt'));    
        $("#play_info").unbind().click(function(){window.open($("#play_list a").eq(i).attr('href'), "_blank")})    
        $("#play_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);    
        $(this).css({"background":"#F00",'color':'#000'}).siblings().css({"background":"#000",'color':'#fff'});    
    });    
    t = setInterval("showAuto()", 2000);    
    $("#play").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 2000);});  
	  
	  
	  
	  
	  $("#hit").hover(function(){
		                   $("#apDiv1").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv1").slideUp();},300);
		                    $("#apDiv1").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv1").slideUp();});
	  });
	  $("#tip2").hover(function(){
		                   $("#apDiv2").slideDown();
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv2").slideUp();},300);
		                    $("#apDiv2").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv2").slideUp();});
	  });
	  $("#tip3").hover(function(){
		                   $("#apDiv3").slideDown(); 
						  
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv3").slideUp();},300);
		                    $("#apDiv3").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv3").slideUp();});
	  });
	  $("#tip4").hover(function(){
		                   $("#apDiv4").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv4").slideUp();},300);
		                    $("#apDiv4").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv4").slideUp();});
	  });
	  $("#tip5").hover(function(){
		                   $("#apDiv5").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv5").slideUp();},300);
		                    $("#apDiv5").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv5").slideUp();});
	  });
	  $("#tip6").hover(function(){
		                   $("#apDiv6").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv6").slideUp();},300);
		                    $("#apDiv6").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv6").slideUp();});
	  });
	  $("#tip7").hover(function(){
		                   $("#apDiv7").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv7").slideUp();},300);
		                    $("#apDiv7").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv7").slideUp();});
	  });
	  $("#tip8").hover(function(){
		                   $("#apDiv8").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv8").slideUp();},300);
		                    $("#apDiv8").hover(function(){ clearTimeout(timeoutId);
			             },
						  function(){$("#apDiv8").slideUp();});
	  });
	  $("#tip9").hover(function(){
		                   $("#apDiv9").slideDown(); 
	                    },
						  function(){
		                     var timeoutId=setTimeout(function(){$("#apDiv9").slideUp();},300);
		                    $("#apDiv9").hover(function(){ clearTimeout(timeoutId);},function(){$("#apDiv9").slideUp();});
	  });
	  
	  
	    $("#apDiv2 input").each(function(index){
			var rad=$(this);
			rad.change(function(){
								
				if($("input[name='radio2']:checked").val()==0){
				   $.cookie("radio2",0);
				}else{
				    $.cookie("radio2",1);
				}			
			});
		 					  
		});
		
		$.getCookie("radio2","text");
		
		//$.getJSON("http://19.128.116.137:8080/fsgov/reminder", null, function(json){
			//alert("json:"+json.tip);	
			//alert(json);
			//  alert("hello");
			//if(json.tip!="no change"){
			//$("#reminder").text("");
		//	$("#reminder").text(json.tip);
		//	}
	//	});
				 /*													
	if(json.result=="success"){
  		alert("谢谢你的意见！");
	}else{
	 	alert("未知异常，数据提交失败！");
	}
});*/
	  // $.get("http://19.128.116.137:8080/fsgov/reminder",null,function(data){
																	    
				//		alert(data+" result");});
	  $(".zfbssx_nr_ne_tu img").each(function(index){
			var imgNode=$(this);
			imgNode.mouseover(function(){
			     imgNode.css("cursor","pointer");	
			});
			//imgNode.mouseout(function(){
				// imgNode.css("filter","Alpha(Opacity=100)");		  
		//	});
	  });  
});
