$.ajaxSetup({cache: false});

jQuery(function ($) {
	var OSX = {
		container: null,
		init: function () {
			$("a.hosNews").click(function (e) {
				e.preventDefault();	
				$("#hos-modal-newsletter").modal({
					overlayId: 'hos-overlay',
					containerId: 'hos-newsletter',
					closeHTML: null,
					minHeight: 120,
					opacity: 25, 
					position: ['250px','-320px'],
					overlayClose: true,
					onOpen: OSX.open,
					onClose: OSX.close
				});
			});
		},
		open: function (d) {
			var self = this;
			self.container = d.container[0];
			d.overlay.fadeIn('fast', function () {
				$("#hos-modal-newsletter", self.container).show();
				d.container.animate(	{left: "50%", height: 120}, 'slow', function () {
						var emailNews = document.getElementById("email_newsletter").value;
						if (emailNews.length < 6 || emailNews.indexOf("@") < 1){
								var h = $("#hos-modal-data-aviso", self.container).height()
										+ 30; 
								d.container.animate({"height": h}, 250, function () {
									//$("div.close", self.container).show();
									$("#hos-modal-data-aviso", self.container).show();
								});		
							
						} else {
								var h = $("#hos-modal-data-news", self.container).height()
										+ 30; 
								d.container.animate({"height": h}, 250, function () {
									//$("div.close", self.container).show();
									$("#hos-modal-data-news", self.container).show();
								});		
						}															  
				});
			});
		},
		close: function (d) {
			var self = this; // this = SimpleModal object
			d.container.animate(
				{left: -600},
				300,
				function () {
					self.close(); // or $.modal.close();
				}
			);
		}
	};

	OSX.init();

});
