/******************************************预加载区*/
$(function(){
	//$("img.img_w316_h236").LoadImage(true,316,236);

/*
	var d = $.dialog.defaults;
	d.skin = ['default', 'chrome', 'facebook', 'aero'];
	d.effect = true;
	d.fixed = true;
	d.showTemp = 500000;
*/

});

//中文版简繁转换函数 需要transform.js转换库支持
function s2t(){
	document.body.innerHTML = document.body.innerHTML.s2t();
	document.title = document.title.s2t();
}
function t2s(){
	document.body.innerHTML = document.body.innerHTML.t2s();
	document.title = document.title.t2s();
}

/******************************************图片预加载 缩放 插件*/
jQuery.fn.LoadImage=function(scaling,width,height,loadpic){
	if(loadpic==null) loadpic="images/imgload.gif";
	return this.each(function(){
		var t=$(this);
		var src=$(this).attr("src")
		var img=new Image();
		//alert("Loading")
		img.src=src;
		//自动缩放图片
		var autoScaling=function(){
			if(scaling){
				if(img.width>0 && img.height>0){
					if(width<=0){
						if(height<img.height){
							t.height(height);
							t.width((img.width/img.height)*height);
						}
						else{
							t.height(img.height);
							t.width(img.width);
						}
					}
					else if(height<=0){
						if(width<img.width){
							t.width(width);
							t.height((img.height/img.width)*width);
						}
						else{
							t.height(img.height);
							t.width(img.width);
						}
					}
					else if(img.width/img.height>=width/height){
						if(img.width>width){
							t.width(width);
							t.height((img.height*width)/img.width);
						}else{
							t.width(img.width);
							t.height(img.height);
						}
					}
					else{
						if(img.height>height){
							t.height(height);
							t.width((img.width*height)/img.height);
						}
						else{
							t.width(img.width);
							t.height(img.height);
						}
					}
				}
			}
			else{
				t.width(width);
				t.height(height);
			}
		}
		//处理ff下会自动读取缓存图片
		if(img.complete){
			//alert("getToCache!");
			autoScaling();
			return;
		}
		$(this).attr("src","");
		var loading=$("<img alt=\"加载中\" title=\"图片加载中\" src=\""+loadpic+"\" />");

		t.hide();
		//t.after(loading);
		$(img).load(function(){
			autoScaling();
			loading.remove();
			t.attr("src",this.src);
			t.show();
			//alert("finally!")
		});

	});
}

/*验证字符串长度范围*/
function betweenLength(str,_min,_max){
	return (str.length>=_min&&str.length<=_max);
}

$(function(){

	/*
	$.each($('#servmap area'),function(){
		$.dialog({
			id: 'tips' + $(this).attr('mid'),
			icon: 'tips',
			skin: 'facebook',
			border: false,
			fixed: true,
			title: false,
			show: false,
			content: $(this).attr('name')
		});
		$(this)
			.click(function(){return false;})
			.mouseover(function(event){
				var dia = $.dialog.get('tips' + $(this).attr('mid'));
				dia.show();
			})
			.mouseout(function(){
				var dia = $.dialog.get('tips' + $(this).attr('mid'));
				dia.hide();
			})
			.mousemove(function(event){
				var dia = $.dialog.get('tips' + $(this).attr('mid'));
				dia.position(event.clientX+10,event.clientY+20);
			});
	});
	*/

	$.each($("#servmap *").click(function(){return false;}), function(){
		var coords;
		if($.browser.msie){
			coords = new Array(2);
			coords[0] = 450;
			coords[1] = 100;
		}
		else{
			coords = $(this).attr('coords').split(',');
			coords[0] = parseInt(coords[0])+30;
			coords[1] = parseInt(coords[1])-10;
		}
		$(this).tooltip({
			tip: '.tooltip',
			effect: 'fade',
			fadeOutSpeed: 100,
			predelay: 400,
			position: ['top', 'left'],
			offset: [coords[1], coords[0]]
		});
	});

});
