$(function(){
	
	$.fn.inputcity = function(){
		
		var $panel = $('#hotTab');
		
		var $input=$;
		
		this.each(function(){
			
			
			var pos = $(this).offset();
			
			
			$(this).focus(function(){
				
				$panel.show().css({top:pos.top+$(this).outerHeight(),left:pos.left});
				
				$input = $(this);
				
				
			});
			
			
		
		});
		
		$('.hotTab li',$panel).click(function(){
			
			$('.hotData',$panel).empty().text('loading...');
			
			$(this).addClass('action').siblings().removeClass('action');
			
			var url = 'http://flight.elong.com/hotcity/flightsrc/'+($(this).index()+1)+'.html?callback=?';
			
			$.getJSON(url,function(json){
				
				var hotData = json.CityList;
				$('.hotData',$panel).empty();
				for(var i in hotData){
					$('.hotData',$panel).append('<li cityCode="'+hotData[i]['CityCode']+'">'+hotData[i]['CityNameCn']+'</li>');
				}
				
				$('.hotData li',$panel).click(function(){
					$input.val($(this).text()).attr('CityCode',$(this).attr('CityCode'));
					$panel.hide();
				});
			});
			return false;
		});
		
		$('.hotTab li:first',$panel).click();
		
		$(document).bind('click.inputcity',function(e){
			e = e || window.Event;
			if(!$(e.target).parents('#hotTab').length&&e.target!=$input.get(0))
				$panel.hide();
		});
		
	}
	
});
