$(document).ready(function() {
	if ($('table.calendar td').length > 0) {
		$('table.calendar td').tooltip({ 
		    track: true, 
		    delay: 0, 
		    showURL: false, 
		    showBody: " :: ", 
		    fade: 250 
		});
	}
	
	$('#calendarHolder').cycle({ 
		fx:    'scrollHorz', 
		speed: 'slow',
		timeout: 0,
		next:   '#arrowRight',
		prev:   '#arrowLeft',
		after: onBefore
	});
	
	function onBefore(currSlide, nextSlide, opts, flag){

		var $nextSlide = nextSlide.id;
		
		$('#monthImage').attr('src','/media/calendar/titles/' + $nextSlide.toLowerCase() + '.gif');
	}
	
	//remove anything from the inputs to make it easy to type!!
	
	var inp = document.getElementsByTagName('input');
	for(var i = 0; i < inp.length; i++) {
		if(inp[i].type == 'text') {
			inp[i].setAttribute('rel',inp[i].defaultValue)
			inp[i].onfocus = function() {
				if(this.value == this.getAttribute('rel')) {
					this.value = '';
				} else {
					return false;
				}
			}
			inp[i].onblur = function() {
				if(this.value == '') {
					this.value = this.getAttribute('rel');
				} else {
					return false;
				}
			}
			inp[i].ondblclick = function() {
				this.value = this.getAttribute('rel')
			}
		}
	}

	$("#fancyNewsletters").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true, 'overlayOpacity': .65, 'frameHeight': 180, 'hideOnContentClick': false }); 
	
	
	//Make the form submit all ajax!
	//hookup the save buttons in the tables to do an ajax save so they don't leave the page.
	/*
	$('#emailerForm').submit(function(){
			var data = $('this').serialize().replace(/%5B/g, '[').replace(/%5D/g, ']');
            
            $.ajax({
                url: window.location.href,
                data: data,
                type: 'POST',
                success: function(response, responseText) {
                    $('#emailerForm').show();
                    el.parent().prepend('<p class="flashSuccess" style="display: none;">Everything saved 	succcessfully!</p>');
                },
                error: function(response, responseText) {
                    el.parent().prepend('<p class="flashError" style="display: none;">There was an error saving. Please try again.</p>');
                },
                complete: function(response, responseText) {
                    el.parent().children(':first').fadeIn('slow');
                    el.parent().children('p.flashSuccess').delay(7, function() {el.parent().children(':first').fadeOut('slow') });

});
	*/
	
	/*
	
	if ($('#arrowLeft #previous').length > 0) {
		$('#arrowLeft #previous').click(function(){
			$.get(
				'/locations/calendar/' + (parseInt($('#monthImage').attr('rel').replace('m','')) - 1) + '/' + $('#leftColumn').attr('rel') + '/',
				function(data) {
					$('#boxOne').html(data);
				}
			);
			return false;
		});
	}
	if ($('#arrowRight #next').length > 0) {
		$('#arrowRight #next').click(function(){
			$.get(
				'/locations/calendar/' + (parseInt($('#monthImage').attr('rel').replace('m','')) + 1) + '/' + $('#leftColumn').attr('rel') + '/',
				function(data) {
					$('#boxOne').html(data);
				}
			);
			return false;
		});
	}*/
});