﻿$(document).ready( function() {
	var cx = 0 , cy = 0;
function locate() {
	cx = event.x?event.x:event.pageX;
	cy = event.y?event.y:event.pageY;
	if ( typeof(cx) == "undefined" ) {
		cx = 0;
	}
	if ( typeof(cy) == "undefined" ) {
		cy = 0;
	}
	if ( $.browser.msie ) {
		if ( $.browser.version != "8.0" ) {
			cx += document.documentElement.scrollLeft;
			cy += document.documentElement.scrollTop;
		}
	}
	else if ( $.browser.safari ) {
		cx += document.body.scrollLeft;
		cy += document.body.scrollTop;
	}
}
	//浮动图片
	var floatpic_map = "";

 floatpic_map = "<div id='floatpic' style='position:absolute;width:200px;height:150px;z-index:150;top:0;left:0;border:1px #D3E3EA solid;background:#FFF;padding:10px;display:none;'>";
 floatpic_map = floatpic_map + '<div style="font-size:12px;margin:10px 0 0 0;text-align:left;"></div>';
	floatpic_map = floatpic_map + '<div style="font-size:12px;margin:10px 0 0 0;text-align:left;" id="pic1"><img id="pica"/></div>';
	floatpic_map = floatpic_map + '<div style="font-size:12px;margin:10px 0 0 0;text-align:left;" id="pic2"></div>';
	floatpic_map = floatpic_map + '</div>'; 
	$(document.body).append(floatpic_map);
	
	var showfloating = true , floatshowing = false , lastfloatobj = "" , locateallow = false;
	var allcanshow = true , hidepic = "";
	$(".pic img:first").mouseover( function() {
		if ( allcanshow ) {
			showfloatpic($(this));
		}
	} ).mousemove( function() {
		if ( allcanshow ) {
			movefloatpic();
		}
	} ).mouseout( function() {
		if ( allcanshow ) {
			hidefloatpic($(this));
		}
	} );
	
	function checklocate(getwidth,getheight) {
		locate();
		if ( cx + 20 + getwidth > document.documentElement.clientWidth + document.documentElement.scrollLeft + document.body.scrollLeft ) {
			cx = cx + document.documentElement.scrollLeft + document.body.scrollLeft - 30 - getwidth;
		}
		if ( cy + 20 + getheight > document.documentElement.clientHeight + document.documentElement.scrollTop + document.body.scrollTop ) {
			cy = document.documentElement.clientHeight + document.documentElement.scrollTop + document.body.scrollTop - 20 - getheight;
		}
	}
	function showfloatpic(obj) {
		
		var cs1 = obj.attr("rel").split(",")[0];
		var cs2 = obj.attr("rel").split(",")[1];
		//$("#pica").src=cs1;
		$("#pic2").text(""+cs2+"");
		$("#floatpic").css( { "left" : 220 + "px" , "top" : 220 + "px" } ).show();
		var img = new Image();
		img.src = cs1;
		if ( img.complete ) {
			$("#pica").attr("src",cs1).show();
		}
		img.onload = function() {
			$("#pica").attr("src",cs1).show();
		}
	}
	function movefloatpic() {
		checklocate(document.getElementById("floatpic").offsetWidth,document.getElementById("floatpic").offsetHeight);
		$("#floatpic").css( { "left" : cx + 20 + "px" , "top" : (cy-100) +  "px" } );
	}
	function hidefloatpic(obj) {
		$("#floatpic img").attr("src","").hide();
		$("#floatpic div:first").empty();
		$("#floatpic").hide();
	}
	

} );
