var modalPopup = {
	open: function(d) {
		var self = this;
		self.container = d.container[0];
		d.overlay.fadeIn('slow', function () {
			$("#inline-popup", self.container).show();
			var title = $("#inline-popup-title", self.container);
			title.show();
			d.container.slideDown('slow');
		})
	},
	close: function (d) {
		var self = this;
		d.container.slideUp('fast', function() {
			self.close();
		});
	}
}

$(function() {

	$(".sf-menu").superfish({autoArrows: false});
	$('ul.sf-menu ul').hover(
		function() {
			var $img = $(this).parents('li:eq(0)').find('img');
			var src = $img.attr('rel');
			$img.attr({"src":src});
		},
		function() {
			var $img = $(this).parents('li:eq(0)').find('img');
			var src = $img.attr('alt');
			$img.attr({"src":src});
		}
	);

	$(".dataTable tr:even").addClass("even");
	$(".dataTable tr:odd").addClass("odd");

	$('#headlines').cycle({ 
		fx: 'scrollUp', 
		timeout: 1500, 
		delay:  -1000,
		pause: true 
	});
	
	$('#ads').cycle({ 
		fx: 'fade', 
		timeout: 6000, 
		delay:  -2000,
		pause: true,
		pager: '#carousel-nav',
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return '#carousel-nav li:eq(' + idx + ') a'; 
		} 
	});

	if ($('a.lightbox').length > 0) {
		 $('a.lightbox').fancybox({
			'overlayOpacity' : 0.7,
			'overlayColor' : '#000',
			'transitionIn' : 'none',
			'transitionOut' : 'none',
			'titlePosition' : 'over',
			'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + '<br />' + title +'</span>';
			}
		}); 
	}

	$('.rsvp').click(function() {
		var $el = $(this);
		var anchor = $el.attr('href');
		var id = anchor.split('#')[1];

		$.get(url + 'rsvp.php?id='+id, function(data){
			// create a modal dialog with the data
			$(data).modal({
				containerId: '#inline-popup',
				minHeight:80,
				opacity:45,
				escClose: false,
				closeClass : 'modalCloseImg',
				onOpen:modalPopup.open,
				onClose: modalPopup.close,
				onShow: function (d) {
					var options = { 
						url: url + "rsvp.php",
						success: function(responseText) { 
							if (responseText == 1) {
								$.modal.close();
							}
						} 
					}; 

					$("#rsvpForm").validate({
						submitHandler: function(form) {
							$(form).ajaxSubmit(options);
						}
					});
				}
			});
		});
	});
	/*
	$('.contact-us').click(function() {
		$.get(url + 'contact.php', function(data){
			// create a modal dialog with the data
			$(data).modal({
				containerId: '#inline-popup',
				minHeight:80,
				opacity:45,
				escClose: false,
				closeClass : 'modalCloseImg',
				onOpen:modalPopup.open,
				onClose: modalPopup.close,
				onShow: function (d) {
					var options = { 
						url: url + "contact.php",
						success: function(responseText) { 
							if (responseText == 1) {
								$.modal.close();
							}
						} 
					}; 

					$("#contactForm").validate({
						submitHandler: function(form) {
							$(form).ajaxSubmit(options);
						}
					});
				}
			});
		});
		return false;
	});
	*/
});
