$(document).ready(function () {
	$('#feedbackLink').click(function (e) {
		e.preventDefault();
		$.get(BASE_URL_WITH_MODULE+"reviews/feedback", function(data){
			preview.create(data);
		});
	});
	$('#requestLink').click(function (e) {
		e.preventDefault();
		$.get(BASE_URL_WITH_MODULE+"reviews/request", function(data){
			preview.create(data);
		});
	});
});

var preview = {
    item: {},
	create: function (data) {
		preview.item = $(data).modal({
			close: false,
			overlayId: 'contact-overlay',
			containerId: 'contact-container',
			onOpen: preview.open,
			onShow: preview.show,
			onClose: preview.close
		});
	},
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($.browser.mozilla) {
			$('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($.browser.safari) {
			$('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		var title = $('#contact-container .contact-title').html();
		$('#contact-container .contact-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$('#contact-container .contact-content').animate({
						height: 430
					}, function () {
						$('#contact-container .contact-title').html(title);
						$('#contact-container form').fadeIn(200, function () {
							$('#contact-container #contact-name').focus();

							// fix png's for IE 6
							if ($.browser.msie && $.browser.version < 7) {
								$('#contact-container .contact-button').each(function () {
									if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$('#contact-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
			
				$('#contact-container .contact-message').fadeOut(function () {
					$('#contact-container .contact-message').removeClass('contact-error').empty();
				});
				$('#contact-container .contact-title').html('Sending...');
				$('#contact-container form').fadeOut(200);
				$('#contact-container .contact-content').animate({
					height: '80px'
				}, function () {
					$('#contact-container .contact-loading').fadeIn(200, function () {
					
						$.ajax({
							url: $('#contact-container form').get(0).action,
							data: $('#contact-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							success: function (data) {
							//	$("#contact-container .modalClose").trigger('click');
							//	preview.create(data);
							//$('#contact-container .main-cntent').html(data);
							console.dir($("#contact-container .modalClose"));
							preview.item.dialog.data.find('.main-content').html(data);
							},
							error: preview.error
						});
					});
				});
			
		});
	},
	submit: function () {
		dialog = preview.item;
		
						$.ajax({
							url: $('#contact-container form').get(0).action,
							data: $('#contact-container form').serialize() + '&action=send',
							type: 'post',
							cache: false,
							dataType: 'html',
							success: function (data) {
							//	$("#contact-container .modalClose").trigger('click');
							//	preview.create(data);
							//$('#contact-container .main-cntent').html(data);
							//console.dir(preview.item);
							
							preview.item.dialog.data.find('.contact-content-main').empty().html(data);
							},
							error: preview.error
						});
					
	},
	close: function (dialog) {
		//$('#contact-container .contact-message').fadeOut();
		//$('#contact-container .contact-title').html('Goodbye...');
		//$('#contact-container form').fadeOut(200);
		//$('#contact-container .contact-content').animate({
		//	height: 40
		//}, function () {
		//	dialog.data.fadeOut(200, function () {
		//		dialog.container.fadeOut(200, function () {
		//			dialog.overlay.fadeOut(200, function () {
						$.modal.close();
		//			});
		//		});
		//	});
		//});
	}	
};

//	Времменно
$(document).ready(function () {
	var inner = ''
	inner += '<div style="width:550px; height:30px; background:white; padding:10px;">';
		inner += '<div style="float:left; font-size:18px;">Эта языковая версия находится в стадии разработки</div>';
		inner += '<div style="float:right; background:red; padding:3px;"><a href="#" class="modalClose"><img border=0 src="http://hotel.ua/application/views/scripts/hotel/img/reviews/rating_feedback_end.gif" /></a></div>';
	inner += '</div>';
	$('.lang_switcher_not_yet').click(function (e) {
		e.preventDefault();
		not_yet.create(inner);
//		$.get("/hotel/reviews/feedback", function(data){
//			not_yet.create(data);
//		});
	});
});
//---------------------------------------

var not_yet = {
    item: {},
	create: function (data) {
		not_yet.item = $(data).modal({
			close: false,
			overlayId: 'contact-overlay',
			containerId: 'contact-container',
			onOpen: not_yet.open,
			onShow: not_yet.show,
			onClose: not_yet.close
		});
	},
	open: function (dialog) {
		// add padding to the buttons in firefox/mozilla
		if ($.browser.mozilla) {
			$('#contact-container .contact-button').css({
				'padding-bottom': '2px'
			});
		}
		// input field font size
		if ($.browser.safari) {
			$('#contact-container .contact-input').css({
				'font-size': '.9em'
			});
		}

		var title = $('#contact-container .contact-title').html();
		$('#contact-container .contact-title').html('Loading...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$('#contact-container .contact-content').animate({
						height: 430
					}, function () {
						$('#contact-container .contact-title').html(title);
						$('#contact-container form').fadeIn(200, function () {
							$('#contact-container #contact-name').focus();

							// fix png's for IE 6
							if ($.browser.msie && $.browser.version < 7) {
								$('#contact-container .contact-button').each(function () {
									if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
										var src = RegExp.$1;
										$(this).css({
											backgroundImage: 'none',
											filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
										});
									}
								});
							}
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$('#contact-container .contact-send').click(function (e) {
			e.preventDefault();
			// validate form
			
				$('#contact-container .contact-message').fadeOut(function () {
					$('#contact-container .contact-message').removeClass('contact-error').empty();
				});
				$('#contact-container .contact-title').html('Sending...');
				$('#contact-container form').fadeOut(200);
				$('#contact-container .contact-content').animate({
					height: '80px'
				}, function () {
					$('#contact-container .contact-loading').fadeIn(200, function () {
					
					console.dir($("#contact-container .modalClose"));
					not_yet.item.dialog.data.find('.main-content').html(data);
						
					});
				});
			
		});
	},
	submit: function () {
	dialog = not_yet.item;
	not_yet.item.dialog.data.find('.contact-content-main').empty().html(data);
					
	},
	close: function (dialog) {
		//$('#contact-container .contact-message').fadeOut();
		//$('#contact-container .contact-title').html('Goodbye...');
		//$('#contact-container form').fadeOut(200);
		//$('#contact-container .contact-content').animate({
		//	height: 40
		//}, function () {
		//	dialog.data.fadeOut(200, function () {
		//		dialog.container.fadeOut(200, function () {
		//			dialog.overlay.fadeOut(200, function () {
						$.modal.close();
		//			});
		//		});
		//	});
		//});
	}	
};