$(function($){
	var formLayer = $('<div id="formLayer"></div>');
	var formWin = $('<div id="formWin"></div>');
	var closeBtn = $('<p class="formCloseBtn"></p>');
	var href = $('.tfTriggerBtn').attr('href');
	$('.showInfo').hover(function(){
		var $_this = $(this);
		$(this).addClass('ticketOrder');
		$(this).click(function(e){
			e.preventDefault();
			$('body')
			.append(formLayer)
			.append(formWin);
			
			formLayer.fadeIn('slow');
			formWin.animate({top:'-1'},'slow',function(){
				if(!$.support.opacity){
				if(this.style.filter&&this.style.removeAttribute){
					this.style.removeAttribute('filter');
				}
			}
			});
			
			closeBtn.click(close);
			cheackForm($_this);
		});
	},function(){
		$(this).removeClass('ticketOrder'); 
    });
	
	function cheackForm($_this){
		var eDay = $_this.find('.eventDay').text();
		var eName = $_this.find('.eventName').text();
		var ePlace = $_this.find('.place').text();
		var eOpen = $_this.find('.open').text();
		var ePrice = $_this.find('.price').text();
		var eBand = $_this.find('.eventBand').text();
		var eDJ = $_this.find('.eventDJ').text();
		formWin.load(href + ' #ticket_form',function(){
				$('input:text[name=eventDay]').val(eDay);
				$('input:text[name=eventName]').val(eName);
				$('input:text[name=eventPlace]').val(ePlace);
				$('input:text[name=eventOpen]').val(eOpen);
				$('input:text[name=ticketPrice]').val(ePrice);
				formWin.append(closeBtn);
				closeBtn.click(close);
				
				$('.tf_customer input:text').one('focus',function(){
						$(this).val("");
				})
				.focus(function(){
						$(this).parent().addClass('focusField');
				})
				.blur(function(){
						$(this).parent().removeClass('focusField');
				});
				$('#message').focus(function(){
						$(this).parent().addClass('focusTextArea');
				})
				.blur(function(){
						$(this).parent().removeClass('focusTextArea');
				});
				$('#orderform').validationEngine({
					promptPosition:"topRight_show",
	 				ajaxSubmit: true,
	 				ajaxSubmitFile: "ticket_order",
	 				ajaxSubmitMessage:"ご予約有難う御座います、会場でお待ちしております。",
	
					failure : function() {}
				});

		});	
		
	}
	
	function close(){
		formWin.animate({top:'-605'},'frst');
		formLayer.fadeOut('slow',function(){
			formLayer.remove();
			formWin.remove();
		});
		$('.formError').remove();
	}
	
});
