(function(a){a.fn.imageScroller=function(h){var d=h||{next:"buttonNext",prev:"buttonPrev",frame:"viewerFrame",width:100,timer:null,speed:null,child:"a",auto:true};var c=a("#"+d.next);var o=a("#"+d.prev);var q=a("#"+d.frame);var g=d.width;var i=d.child;var m=d.auto;var f=d.timer?parseInt(d.timer,10):3000;var j=d.speed?parseInt(d.speed,10):500;var l;q.css("width",q.find(i).length*g+"px");var n=function(){o.unbind("click",n);if(m){b();}q.animate({marginLeft:-g},j,"",function(){q.find(i+":first").appendTo(q);q.css("marginLeft",0);o.bind("click",n);if(m){k();}});};var e=function(){c.unbind("click",e);if(m){b();}q.find(i+":last").clone().show().prependTo(q);q.css("marginLeft",-g);q.animate({marginLeft:0},j,"",function(){q.find(i+":last").remove();c.bind("click",e);if(m){k();}});};c.css("cursor","hand").click(e);o.css("cursor","hand").click(n);var k=function(){l=window.setInterval(n,f);};var b=function(){window.clearInterval(l);};if(m){k();}};})(jQuery);
$(function(){
	// mainNav
    $('#header .nav:eq(0) li').each(function(){
		var rel = $(this).find('a._parent').attr('rel');
		if(rel != null && rel != 'undefined' && rel != ''){
			if($('#'+rel).html() != null && $('#'+rel).html() != '' && $('#'+rel).html() != 'undefined'){
				$('<dl class="submenu">'+$('#'+rel).html()+'</dl>').appendTo($(this));
			}			
		}
	}).hover(function(){
		$(this).find('a').addClass('hover');
		if($(this).find('.submenu dd').length > 0){
			$(this).find('.submenu').slideDown(200);
		};
		$(this).find('span').css('opacity',0.3).animate({'opacity':1},200);
	},function(){
		$(this).find('a').removeClass('hover');
		if($(this).find('.submenu dd').length > 0){
			$(this).find('.submenu').slideUp(100);
		};
	});
	// showpic-wrap	
	if($('#J_s_w_body li').length > 4){
		$("#J_s_w_wrap").imageScroller({next:'J_s_w_rbtn', prev:'J_s_w_lbtn', frame:'J_s_w_body', width:170, child:'li', auto:true});
	}
	// opacity
	$('.colnews-wrap a.logo, .colnews-wrap a.cover, .sideinfo-wrap a.logo, .sideinfo-wrap a.cover, .news-list-wrap a.logo, .special-list-wrap a.logo, .magazine-list-wrap a.logo, #J_s_w_body a.logo').mouseover(function(){
		$(this).css('opacity',0.3).animate({'opacity':1},300);
	});
	// search input-text tip
	var search_word_tip = '想找什么？输入文章标题或内容试试';
	$('.search input.text').attr('value', search_word_tip).css('color', '#b3b3b3').click(function(){
		if($(this).attr('value') == search_word_tip){
			$(this).css('color', '#555');
			$(this).attr('value', '');
		}
	}).blur(function(){
		if($(this).attr('value') == ''){
			$(this).css('color', '#b3b3b3');
			$(this).attr('value', search_word_tip);
		}		
	});
	// fav
	$('a#fav, li#act-fav a').click(function(){
		var dtitle = document.title;
		var durl = document.location.href;
		if(document.all){
			window.external.AddFavorite(durl, dtitle);
		}else if(window.sidebar){
			window.sidebar.addPanel(dtitle, durl, '');
		}else{
			alert('您的浏览器不支持快速收藏！请手工收藏！');
		}
		return false;
	});
	// fontzoom
	$('#fontzoom').hover(
		function(){
			$(this).css('opacity',0).html('<a href="javascript:void(0)" onclick="$(\'#article_content\').css(\'opacity\',0).css(\'font-size\', \'12px\').animate({\'opacity\':1},500);">小</a>&nbsp;<a href="javascript:void(0)" onclick="$(\'#article_content\').css(\'opacity\',0).css(\'font-size\', \'14px\').animate({\'opacity\':1},500);">中</a>&nbsp;<a href="javascript:void(0)" onclick="$(\'#article_content\').css(\'opacity\',0).css(\'font-size\', \'16px\').animate({\'opacity\':1},500);">大</a>').stop().animate({'opacity':1},500);
		}, 
		function(){
			$(this).css('opacity',0).html('字体大小').stop().animate({'opacity':1},500);
		}
	);
	// today
	var date = new Date();
	var week = ['日','一','二','三','四','五','六'];
	$('#today').html(date.getFullYear()+'年'+(date.getMonth()+1)+'月'+date.getDate()+'日'+' 星期'+week[date.getDay()]);	
	// article_content
	$('#article_content img').each(function(){
		$(this).load(function(){
			var w = 650;
			var _w = $(this).width();
			var _h = $(this).height();
			if(_w > w){
				$(this).css('height', (_h*w/_w) + 'px').css('width', w + 'px').attr('alt', '点击图片则放大观看');			
			}
			if($(this).parent('a').length == 0){
				$(this).wrap('<a href="'+$(this).attr('src')+'" target="_blank" title="点击图片则放大观看"></a>');
			}
	    });
	});
	// footer
	$('#top').click(function(){$('html,body').animate({scrollTop:'0px'}, 300);return false;});
	$('#copyright_year').html(date.getYear()<1900?(date.getYear()+1900):date.getYear());
});
function setmodel(value, id, siteid, q) {
	$("#typeid").val(value);
	$("#search a").removeClass();
	id.addClass('on');
	if(q!=null && q!='') {
		window.location='?m=search&c=index&a=init&siteid='+siteid+'&typeid='+value+'&q='+q;
	}
}
