$(document).ready(function() {
		getTIMETABLEview(plocal, pline, plineNum, pkey, ptime);

		$('a.sort').click(function(){
			$('a.sort').each(function(){
				$(this).removeClass("now");
			});
			$(this).addClass("now");
		});


		// 검색
		$('#btn-sch').bind("click", function () {
			if(!$('#keyword').val()){
				alert('검색하실 지하철 역명을 입력하세요.');
				$('#keyword').focus();
				return false;
			}
			if($('#keyword').val().length<2){
				alert('검색하실 지하철 역명은 두자 이상입니다.');
				$('#keyword').val('').focus();
				return false;
			}

			jQuery.ajax({
				type: "post",
				url: "./timeSEARCH.php",
				cache: true,
				data:
					{
						subway	: $('#keyword').val()
					},
				dataType : "text",
				success: function(text) {
					var p = text.split("/");

					if(p[0] == 'N'){
						alert('검색된 쿠폰데이터가 존재하지 않습니다.');
						$('#keyword').val('').focus();
						return false;
					}
					else {
						plocal		= p[0];
						pline		= p[1];
						plineNum	= p[2];

//						document.getElementById('subwayPicker').setStation(p[3]);

						getTIMETABLEview(plocal, pline, plineNum, '', '');

						if (!ie6) {
							var destination = $('#time').offset().top;
							$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 700, function() {
								window.location.hash = './index.php#time';
							});
						}
					}
				}
			});
		});
		$('#keyword').keydown(function (e) {
			if(e.keyCode == 13){
				$('#btn-sch').click();
			}
		});

		// ie6 png background, png image alpha load
		if (ie6) {
			DD_belatedPNG.fix('.png24');
			DD_belatedPNG.fix('#cpShowWrap .station-w img');
		}
		// 검색 폼 label ctrl
		$('#tschFrm .keyword').focusin(function(){
			$(this).css('opacity', 100);
		});
		$('#tschFrm .keyword').focusout(function(){
			_val = $(this).val();
			if(!_val) {
				$(this).css('opacity', 0);
			} else {
				$(this).css('opacity', 100);
			}
		});

		// 셀렉트박스 
		$('#hourChoiceShow').mouseenter(function(){
			$('.tab-time-w').css('zIndex',5);
			$(this).find('ul').show();
			$(this).find('.ctrl').addClass('now-ctrl'); 
		});
		$('#hourChoiceShow').mouseleave(function(){
			$('.tab-time-w').css('zIndex',0);
			$(this).find('ul').hide();
			$(this).find('.ctrl').removeClass('now-ctrl');
		});
		$('#hourChoiceShow li > a').click(function(){
			_txt = $(this).text();
			$('#hourChoiceShow').find('p').text(_txt);
			$(this).parents('div:first').find('ul').hide();
			$(this).parents('div:first').find('.ctrl').removeClass('now-ctrl');
			return false;
		});

	$('.gnb li a.anchorLink').click(function(event){
		$('.gnb li').each(function(){
			$(this).removeClass("now");
		});
		$(event.target.parentNode).addClass("now");
	});

	if (!ie6) $("a.anchorLink").anchorAnimate();

	$('#layerCpNulltime').hide();
	$('#layerCpNullsearch').hide();
	$('#showBG').hide();

	if(!plocal){
		//$('#showBG').show();
		//$('#layerCpNulltime').show();
	}
});
