﻿// JavaScript Document
$(document).ready( function() {

	//编号
	/*$("#W_id").blur( function() {
		check_mb_id($(this).attr("value"),"w");
	} );*/
	$("#W_id").next().click( function() {
		check_mb_id($(this).prev().attr("value"),"w");
	} ).focus( function() {
		$(this).get(0).blur();
	} );
	function check_mb_id(value,type) {
		if ( value != "" ) {
			$.ajax( {
				type: "post",
				url: "/admin/ajax/check_mb_id.asp",
				cache: false,
				data: "value=" + value + "&type=" + escape(type),
				success: function(result) {
					if ( typeof result == "string" ) {
						if ( result == "cannot_see") {
							alert("对不起，该盘古建站编号不存在！");
							$("#W_id").attr("value","");
						}
						else if ( result == "is_not_num") {
							alert("对不起，该盘古建站编号格式不正确！");
							$("#W_id").attr("value","");
						}
						else {
							$("#W_id").attr("value",result.split(",")[0]);
							$("#searchForm").submit();
						}
					}
				}
			} );
		}
		else {
			$("#searchForm").submit();
		}
	}
	
	//行业
	var industrymar , industrymargintop = 0;
	if ( $("#navbtm .industry .keyword div:first").html() != "" && $("#Industry_id").attr("value") != "" ) {
		$("#navbtm .industry .keyword div:first").append($("#navbtm .industry .keyword div:first").html()).mouseover( function() {
			clearInterval(industrymar);
			$("#navbtm .industry .keyword div:first div:first").stop();
		} ).mouseout( function() {
			industrymar = setInterval(industrymove,2000);
		} );
		industrymar = setInterval(industrymove,2000);
	}
	function industrymove() {
		if ( parseFloat($("#navbtm .industry .keyword div:first div:first").css("margin-top").replace("px","")) <= -( ($("#navbtm .industry .keyword div:first div:first").find("br").length + 1) * 21 ) ) {
			$("#navbtm .industry .keyword div:first div:first").css("margin-top","0");
			industrymargintop = 0;
		}
		industrymargintop += 21;
		$("#navbtm .industry .keyword div:first div:first").stop().animate( { "marginTop" : (-industrymargintop) + "px" } , { queue: false, duration: 500 } );
	}
	
	//价位
	var price_map = "";
	price_map += "<ul id='float_price' style='width:68px;position:absolute;z-index:100;top:0;left:0;border:2px #D3E3EA solid;background:#FFF url(/images/industry_bg.jpg) repeat-x;display:none;cursor:default;'>";
		price_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel=''>所　有</li>";
		price_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel='0,1150'>800</li>";
		price_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel='1150,1800'>1500</li>";
		price_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel='1800'>2100</li>";
	price_map += "</ul>";
	$(document.body).append(price_map);
	
	
	$("#body").click( function() {
		if ( price_click ) {
			$("#float_price").fadeOut("fast",function() { price_click = false; });
		}
	} );
	$(".price .keyword").click( function() {
		showprice($("#P_Price").attr("value"));
	} );
	$(window).resize( function() {
		if ( price_click ) {
			$("#float_price").css( { "left" : $(".price .keyword").offset().left + "px" , "top" : ( $(".price .keyword").offset().top + 23 ) + "px"  } );
		}
	} );
	$("#float_price li").each( function() {
		if ( $(this).attr("rel") == $("#P_Price").attr("value") ) {
			if ( $(this).attr("rel") == "" ) {
				$(".price .keyword").text("所有价位");
			}
			else {
				$(".price .keyword").text($(this).text());
			}
		}
	} ).click( function() {
		$("#P_Price").attr("value",$(this).attr("rel"));
		if ( $(this).attr("rel") == "" ) {
			$(".price .keyword").text("");
		}
		else {
			$(".price .keyword").text($(this).text());
		}
		$("#float_price").fadeOut("fast",function() { price_click = false; $("#searchForm").submit(); });
	} );
	
	
	//分辨率
	var resolution_map = "";
	resolution_map += "<ul id='float_resolution' style='width:90px;position:absolute;z-index:100;top:0;left:0;border:2px #D3E3EA solid;background:#FFF url(/images/industry_bg.jpg) repeat-x;display:none;cursor:default;'>";
		resolution_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel=''>所　有</li>";
		resolution_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel='1'>800 × 600</li>";
		resolution_map += "<li style='text-align:left;height:20px;line-height:20px;padding:0 10px;' onmouseover='seaover($(this));' onmouseout='seaout($(this));' rel='2'>1024 × 768</li>";
	resolution_map += "</ul>";
	$(document.body).append(resolution_map);
	
	
	$("#body").click( function() {
		if ( resolution_click ) {
			$("#float_resolution").fadeOut("fast",function() { resolution_click = false; });
		}
	} );
	$(".resolution .keyword").click( function() {
		showresolution($("#Resolution_id").attr("value"));
	} );
	$(window).resize( function() {
		if ( resolution_click ) {
			$("#float_resolution").css( { "left" : $(".resolution .keyword").offset().left + "px" , "top" : ( $(".resolution .keyword").offset().top + 23 ) + "px"  } );
		}
	} );
	$("#float_resolution li").each( function() {
		if ( $(this).attr("rel") == $("#Resolution_id").attr("value") ) {
			if ( $(this).attr("rel") == "" ) {
				$(".resolution .keyword").text("所　有");
			}
			else {
				$(".resolution .keyword").text($(this).text().split(" ")[0]);
			}
		}
	} ).click( function() {
		$("#Resolution_id").attr("value",$(this).attr("rel"));
		if ( $(this).attr("rel") == "" ) {
			$(".resolution .keyword").text("");
		}
		else {
			$(".resolution .keyword").text($(this).text().split(" ")[0]);
		}
		$("#float_resolution").fadeOut("fast",function() { resolution_click = false; $("#searchForm").submit(); });
	} );

	
	//颜色
	var Color_id = $("#Color_id").attr("value");
	if ( Color_id != "" ) {
		$(".color .keyword img:eq(" + ( Color_id - 1 ) + ")").attr("rel",$(".color .keyword img:eq(" + ( Color_id - 1 ) + ")").attr("rel") + ",on");
	}
	$(".color .keyword img").each( function() {
		if ( $(this).attr("rel").split(",").length == 1 ) {
			$(this).fadeTo("fast",0.5).mouseover( function() {
				$(this).fadeTo("slow",1);
			} ).mouseout( function() {
				$(this).fadeTo("slow",0.5);
			} );
		}
		else {
			colorflash($(this));
			//$(this).attr("src",$(this).attr("src").replace("jpg","gif"));
		}
	} ).click( function() {
		$("#Color_id").attr("value",( 8 - $(this).nextAll().length ))
		$("#searchForm").submit();
	} ).mouseover( function() {
		$(document.body).append("<p id='colortext' style='width:27px;height:14px;line-height:14px;text-align:center;display:inline;position:absolute;z-index:100;margin:0;padding:2px 0 0 2px;background:#FFC;border:1px " + ( $(this).attr("src").split("/")[1].split(".")[0].split("_")[2] ) + " solid;top:" + ( $(this).offset().top + 23 ) + "px;left:" + ( $(this).offset().left + 18 ) + "px;'>" + $(this).attr("rel").split(",")[0] + "</p>");
	} ).mouseout( function() {
		$("#colortext").remove();
	} );
	function colorflash(obj) {
		obj.fadeTo("slow",0.5,function() {
			$(this).fadeTo("slow",1,function() {
				colorflash(obj);							 
			} );
		} );
	}

} );

//价位
var price_click = false;
function showprice() {
	if ( !price_click ) {
		$("#float_price").css( { "left" : $(".price .keyword").offset().left + "px" , "top" : ( $(".price .keyword").offset().top + 23 ) + "px"  } );
		$("#float_price").fadeIn("fast",function() {
			price_click = true;
		} );
	}
}

//分辨率
var resolution_click = false;
function showresolution() {
	if ( !resolution_click ) {
		$("#float_resolution").css( { "left" : $(".resolution .keyword").offset().left + "px" , "top" : ( $(".resolution .keyword").offset().top + 23 ) + "px"  } );
		$("#float_resolution").fadeIn("fast",function() {
			resolution_click = true;
		} );
	}
}

function seaover(obj) {
	obj.css( { "background" : "#0B325D" , "color" : "#FFF" } );
}
function seaout(obj) {
	obj.css( { "background" : "" , "color" : "" } );
}



function checkWid() {
	var value = $("#W_id").attr("value") , type = "w";
	if ( value != "" ) {
		$.ajax( {
			type: "post",
			url: "/admin/ajax/check_mb_id.asp",
			cache: false,
			data: "value=" + value + "&type=" + escape(type),
			success: function(result) {
				if ( typeof result == "string" ) {
					if ( result == "cannot_see") {
						alert("对不起，该盘古建站编号不存在！");
						$("#W_id").attr("value","");
					}
					else if ( result == "is_not_num") {
						alert("对不起，该盘古建站编号格式不正确！");
						$("#W_id").attr("value","");
					}
					else {
						$("#W_id").attr("value",result.split(",")[0]);
						$("#searchForm").submit();
					}
				}
			}
		} );
	}
	return false;
}