﻿	$(document).ready(function(){
		fix_mb_pic(125,150);

		if($("#county").val() == ""){
			initCounty();
		}
		$("#city").change(function(){
			initCounty();
		});
		
		$(".button img").mouseover(function(){
			Swap($(this),"2");
		});
		$(".button img").mouseleave(function(){
			Swap($(this),"1");
		});
	});
	
	function initCounty(){
		$("#county").removeAttr("disabled");
		$("#county > option").remove();
		$("#county").append("<option value=\"\"> </option>");
		if( $("#city").val() == "新竹市" || $("#city").val() == "嘉義市" ){
			$("#county").attr("disabled","disabled");
		}else if( $("#city").val() == "" || $("#city").val() == " " ){
		}else{
			$.ajax({
				type: "POST",
				url: "/public/get_city.asp",
				data: "city="+$("#city").val(),
				async: false,
				error: function(){alert("鄉鎮市區資料載入錯誤！");},
				success: function(CountyData){
					arrConuties=CountyData.split(",");
					for(lop=0;lop < arrConuties.length;lop++){
						$("#county").append("<option value=\""+arrConuties[lop]+"\">"+arrConuties[lop]+"</option>");
					}
				}
			});
		}
	}
	
	function fix_mb_pic(fixW,fixH){
		var image = new Image();
		image.src = $(".pic>img").attr("src");
		width = image.width;
		height = image.height;
		if(width > fixW && height > fixH){
			fixRatioW = width / fixW;
			fixRatioH = height / fixH;
			fixRatio=fixRatioW > fixRatioH?fixRatioH:fixRatioW;
			width = Math.round(width / fixRatio);
			height = Math.round(height / fixRatio);
			
			$(".pic>img").css("width",width);
			$(".pic>img").css("height",height);
		}
		
		pic_W=parseInt($(".pic").css("width"));
		pic_H=parseInt($(".pic").css("height"));
		pic_SW=parseInt($(".pic").attr("scrollWidth"));
		pic_SH=parseInt($(".pic").attr("scrollHeight"));
		pic_SL=parseInt((pic_SW-pic_W)/2);
		pic_ST=parseInt((pic_SH-pic_H)/2);
		$(".pic").attr("scrollLeft",pic_SL);
		$(".pic").attr("scrollTop",pic_ST);
	}

	function Swap(obj,val){
		src = $(obj).attr("src");
		src_len=src.length;
		src = src.substring(0,src_len - 5) + val + src.substring(src_len - 4);
		$(obj).attr("src",src);
	}
