//flash幻灯广告
var getFlashAdvs = function(xml,w,h,ofocus){
	var focus_width=w; //图片框的宽度 
	var focus_height=h; //图片框的高度 
	
	html = "";
	html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
	html += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"';
	html += ' width="'+ focus_width +'" height="'+ focus_height +'">'; 
	html += '<param name="allowscriptAccess" value="sameDomain"><param name="movie" value="'+ofocus+'">';
	html += '<param name="quality" value="high"><param name="bgcolor" value="#F2F2F2">'; 
	html += '<param name="menu" value="false"><param name=wmode value="opaque">'; 
	html += '<param name="FlashVars" value="bcastr_xml_url='+xml+'">'; 
	html += '<embed src="'+ofocus+'" wmode="opaque" FlashVars="bcastr_xml_url='+xml+'" menu="false"';
	html += ' bgcolor="#F2F2F2" quality="high" width="'+ focus_width +'" height="'+ focus_height +'"'
	html += 'allowscriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	return html;
}
//标签切换
function nTabs(tabObj,obj){
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");	
	for(i=0; i <tabList.length; i++){
		if (tabList[i].id == obj.id){
			document.getElementById(tabObj+"_te_"+i).className = "sli"; 
    		document.getElementById(tabObj+"_co_"+i).style.display = "block";
		}else{
			document.getElementById(tabObj+"_te_"+i).className = ""; 
			document.getElementById(tabObj+"_co_"+i).style.display = "none";
		}
	}	
}
//FLV视频播放
function getFlv(w,h,t,f){
	var PUBLIC = "http://50.yxgz.cn/Public";
	var swf_width=w //445
	var swf_height=h //301
	var texts=t //'男左女右'
	var files=f//'http://www.yxgz.cn/Files/adminFiles/jzt/ok2_3.flv'
	
	//var files='1.flv|2.flv'
	var strText = "";
	
	strText = strText+'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	strText = strText+'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ swf_width +'" height="'+swf_height +'">';
	strText = strText+'<param name="movie" value="'+PUBLIC+'/flash/vcastr22/vcastr22.swf"><param name="quality" value="high">';
	strText = strText+'<param name="menu" value="false"><param name="allowFullScreen" value="true" />';
	strText = strText+'<param name="FlashVars" value="vcastr_file='+files+'&vcastr_title='+texts+'&IsAutoPlay=0&IsContinue=1">';
	strText = strText+'<embed src="'+PUBLIC+'/flash/vcastr22/vcastr22.swf" allowFullScreen="true" FlashVars="vcastr_file='+files+'&vcastr_title='+texts+'&IsAutoPlay=0&IsContinue=1"';
	strText = strText+' menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash"';
	strText = strText+' pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	return strText;
}

//加入收藏
function AddFavorite(sURL,sTitle){
	try{
		window.external.addFavorite(sURL, sTitle);
	}catch (e){
		try
	{
		window.sidebar.addPanel(sTitle, sURL, "");
	}catch (e){
		alert("加入收藏失败，请使用Ctrl+D进行添加");
		}
	}
}
//设为首页
function SetHome(obj,vrl){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch (e){
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		}
	}
}

/*在版面图中标记每篇文章的范围和高亮、显示标题*/
(function($) {
	var has_VML, create_canvas_for, add_shape_to, clear_canvas, shape_from_area,canvas_style, fader, hex_to_decimal, css3color, is_image_loaded;
	has_VML = document.namespaces;
	has_canvas = document.createElement('canvas');
	has_canvas = has_canvas && has_canvas.getContext;
	if(!(has_canvas || has_VML)) {
		$.fn.maphilight = function() { return this; };
		return;
	}
	//如果已有"canvas"标签
	if(has_canvas) {
		fader = function(element, opacity, interval) {
			if(opacity <= 1) {
				element.style.opacity = opacity;
				window.setTimeout(fader, 10, element, opacity + 0.1, 10);
			}
		};	
		hex_to_decimal = function(hex) {return Math.max(0, Math.min(parseInt(hex, 16), 255));};
		css3color = function(color, opacity) {return 'rgba('+hex_to_decimal(color.substr(0,2))+','+hex_to_decimal(color.substr(2,2))+','+hex_to_decimal(color.substr(4,2))+','+opacity+')';};
		create_canvas_for = function(img) {
			var c = $('<canvas style="width:'+img.width+'px;height:'+img.height+'px;"></canvas>').get(0);
			c.getContext("2d").clearRect(0, 0, c.width, c.height);
			return c;
		};
		add_shape_to = function(canvas, shape, coords, options) {
			var i, context = canvas.getContext('2d');
			context.beginPath();
			if(shape == 'rect') {
				context.rect(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]);
			} else if(shape == 'poly') {
				context.moveTo(coords[0], coords[1]);
				for(i=2; i < coords.length; i+=2) {
					context.lineTo(coords[i], coords[i+1]);
				}
			} else if(shape == 'circ') {
				context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2, false);
			}
			context.closePath();
			if(options.fill) {
				context.fillStyle = css3color(options.fillColor, options.fillOpacity);
				context.fill();
			}
			if(options.stroke) {
				context.strokeStyle = css3color(options.strokeColor, options.strokeOpacity);
				context.lineWidth = options.strokeWidth;
				context.stroke();
			}
			if(options.fade) {
				fader(canvas, 0);
			}
		};
		clear_canvas = function(canvas, area) {
			canvas.getContext('2d').clearRect(0, 0, canvas.width,canvas.height);
		};
	} else {
		if(!document.documentMode || document.documentMode<8) {document.createStyleSheet().addRule("v\\:*", "behavior: url(#default#VML); antialias: true;"); }
		if(document.documentMode && document.documentMode>=8) {document.writeln('<?import namespace="v" implementation="#default#VML" ?>');}
		document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
		create_canvas_for = function(img) {return $('<var style="zoom:1;overflow:hidden;display:block;width:'+img.width+'px;height:'+img.height+'px;"></var>').get(0);};
		add_shape_to = function(canvas, shape, coords, options) {
			var fill, stroke, opacity, e;
			fill = '<v:fill color="#'+options.fillColor+'" opacity="'+(options.fill ? options.fillOpacity : 0)+'" />';
			stroke = (options.stroke ? 'strokeweight="'+options.strokeWidth+'" stroked="t" strokecolor="#'+options.strokeColor+'"' : 'stroked="f"');
			opacity = '<v:stroke opacity="'+options.strokeOpacity+'"/>';
			if(shape == 'rect') {
				e = $('<v:rect filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+coords[0]+'px;top:'+coords[1]+'px;width:'+(coords[2] - coords[0])+'px;height:'+(coords[3] - coords[1])+'px;"></v:rect>');
			} else if(shape == 'poly') {
				e = $('<v:shape filled="t" '+stroke+' coordorigin="0,0" coordsize="'+canvas.width+','+canvas.height+'" path="m '+coords[0]+','+coords[1]+' l '+coords.join(',')+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+canvas.width+'px;height:'+canvas.height+'px;"></v:shape>');
			} else if(shape == 'circ') {
				e = $('<v:oval filled="t" '+stroke+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(coords[0] - coords[2])+'px;top:'+(coords[1] - coords[2])+'px;width:'+(coords[2]*2)+'px;height:'+(coords[2]*2)+'px;"></v:oval>');
			}
			e.get(0).innerHTML = fill+opacity;
			$(canvas).append(e);
		};
		clear_canvas = function(canvas) {
			$(canvas).empty();
		};
	}
	shape_from_area = function(area) {
		var i, coords = area.getAttribute('coords').split(',');
		var href = area.getAttribute('href');
		href = href.slice(0, href.indexOf(".htm"));
		href = href.substring(href.indexOf("content_")+8);
		for (i=0; i < coords.length; i++) { coords[i] = parseFloat(coords[i]); }
		return [area.getAttribute('shape').toLowerCase().substr(0,4), coords,href];
	};
	
	is_image_loaded = function(img) {
		if(!img.complete) { return false; } // IE
		if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { return false; } // Others
		return true;
	}

	canvas_style = {
		position: 'absolute',
		left: 0,
		top: 0,
		padding: 0,
		border: 0
	};
	
	$.fn.maphilight = function(opts) {
		opts = $.extend({}, $.fn.maphilight.defaults, opts);
		return this.each(function() {
			var img, wrap, options, map, canvas, mouseover;
			img = $(this);
			if(!is_image_loaded(this)) { return window.setTimeout(function() { img.maphilight(); }, 200); }
			options = $.metadata ? $.extend({}, opts, img.metadata()) : opts;
			map = $('map[name="'+img.attr('usemap').substr(1)+'"]');
			if(!(img.is('img') && img.attr('usemap') && map.size() > 0 && !img.hasClass('maphilighted'))) { return; }
			wrap = $('<div>').css({display:'block',background:'url('+this.src+')',position:'relative',padding:0,width:this.width,height:this.height});
			img.before(wrap).css('opacity', 0).css(canvas_style).remove();
			if($.browser.msie) { 			
				if(!document.documentMode || document.documentMode<8) {img.css('filter', 'Alpha(opacity=0)'); }
				if(document.documentMode && document.documentMode>=8) {img.css('-ms-filter', 'progid:DXImageTransform.Microsoft.Alpha(Opacity=0)');}
			}
		
			wrap.append(img);			
			canvas = create_canvas_for(this);
			$(canvas).css(canvas_style);
			canvas.height = this.height;
			canvas.width = this.width;
			mouseover = function(e) {
				var shape = shape_from_area(this);
				var ifedifm = false;
				var thisedifm = "";
				for(i=0;i<edid.length;i++){
					if(shape[2]==edid[i]){
					ifedifm = true;
					thisedifm = edifm[i];
					break;
				}
			}
			if(ifedifm){
				$("#float").html(thisedifm);
				pageX = e.clientX + $(window).scrollLeft();
				pageY = e.clientY + $(window).scrollTop();
				boxX = $('#float').outerWidth(true); 
				boxY = $('#float').outerHeight(true); 
				//alert(pageX+"-"+pageY+"-"+boxX+"-"+boxY);
				if ((cX - e.clientX) < (boxX + 35)){floatX = pageX - boxX - 15;}else{floatX = pageX + 15;}
				if ((cY - e.clientY) < (boxY + 10)){floatY = pageY - boxY - 10;}else{floatY = pageY + 10;}	
				$('#float').css({top: floatY, left: floatX});
				$('#float').show();
			}
			var oldcoords=shape[1];
			var newcoords=new Array;
			if(shape[0]!="poly"){newcoords = oldcoords;}
			else{
				var minX,minY,maxX,maxY;
				minX=maxX=oldcoords[0];
				minY=maxY=oldcoords[1];
				for(i=2;i<oldcoords.length; i+=2){
					if(minX>oldcoords[i]){minX=oldcoords[i];};
					if(maxX<oldcoords[i]){maxX=oldcoords[i];};
					if(minY>oldcoords[i+1]){minY=oldcoords[i+1];};
					if(maxY<oldcoords[i+1]){maxY=oldcoords[i+1];};
				}
				newcoords = [minX,minY,maxX,minY,maxX,maxY,minX,maxY];
			}
					
			add_shape_to(canvas, shape[0], oldcoords, $.metadata ? $.extend({}, options, $(this).metadata()) : options);
		};
			
			
		if(options.alwaysOn) {
			$(map).find('area[coords]').each(mouseover);
		} else {
			$(map).find('area[coords]').mouseover(mouseover).mouseout(function(e) { clear_canvas(canvas); $('#float').hide(); });
		}
		img.before(canvas); // if we put this after, the mouseover events wouldn't fire.
		img.addClass('maphilighted');
			});
		};
		$.fn.maphilight.defaults = {
			fill: true,
			fillColor: 'ffff00',
			fillOpacity: 0.3,
			stroke: true,
			strokeColor: 'ff0000',
			strokeOpacity: 0,
			strokeWidth: 0,
			fade: true,
			alwaysOn: false
	};
})(jQuery);
