$(function(){ 
	
/*
	// Preload images
	$.preloadCssImages();
		
*/
/* 	$('#container *').pngFix();  */
    
    $('#UserEmail').focus(function(){
    	$('#name').slideDown();
    });
    
	$.validator.addMethod("spam", function(value, element) { 
		return this.optional(element) || value == 1 + 3; 
	}, "Enter the correct value for 3 + 1");

    
    $("#UserNewsletterForm").validate();
    
	// Setup modal window for all photos
	$('a[rel=slide]').fancybox({
		padding: 0, 
		titlePosition: 'outside', 
		overlayColor: '#333333', 
		overlayOpacity: .2
	});
	
	$('a.linkimg').hover(
		function(){
			
			var img = $(this).children('img');
			var margTop = parseInt(img.parent('a').css('marginTop').replace('px', ''));
			var paddTop = parseInt(img.css('paddingTop').replace('px', ''));
			var paddLeft = parseInt(img.css('paddingLeft').replace('px', ''));
			
			position = img.position();
			var left = position.left + 6;
			var top = position.top + 6;
			if(img.hasClass('imginsert')) {
				left = position.left + paddLeft + 1;
				top = position.top + paddTop;
			}

			$(this).prepend('<span class="overlay"></span>');
			$(this).children('span.overlay').width(img.width()).height(img.height()).css('left', left).css('top', top);
		},
		function(){
			$(this).children('span.overlay').remove();
		}
	);
	
	$('#galleries ul li a.galimg').hover(
		function(){
			var img = $(this).children('img');
			position = img.position();
			var left = position.left + 6;
			var top = position.top + 6;
			$(this).prepend('<span class="overlay" style="line-height: '+img.height()+'px">'+ $(this).attr('title') +'</span>');
			$(this).children('span.overlay').width(img.width()).height(img.height()).css('left', left).css('top', top);
		},
		function(){
			$(this).children('span.overlay').remove();
		}
	);
	
	$('a.jobinfo').hover(
		function(){
			var descbox = $(this).siblings('div.job.description');
			var p = $(this).parent('td').position();
			
			descbox.css('left', '185px').css('top', p.top + 3).fadeIn();
			
			
			
		},
		function(){
			var descbox = $(this).siblings('div.job.description');
			descbox.fadeOut();
		}
	);
	
	$('table.calendar div.cell-data a').hover(
		function(){
			var id = $(this).attr('rel');
			$('a[rel='+id+']').addClass('hover');
		},
		function(){
			var id = $(this).attr('rel');
			$('a[rel='+id+']').removeClass('hover');
		}
	);
	
	function closeModal(click){
		$(click).click(function(){
			$('#modal').remove();
			$('body div.overlay').remove();
		});
	}
	
	$('table.calendar div.cell-data a').click(function(){
		
		var id = $(this).attr('rel');
		$('body').append('<div id="modal" style="display: none"><a class="close">Close</a><div class="inner"></div></div>');
		$('body').append('<div class="overlay" style="display: none"></div>');
		$('body div.overlay').width($(window).width()).height($(window).height());
		$('#modal .inner').load($(this).attr('href'));
		var modalHeight = $('#modal').height();
		$('div.overlay').fadeIn();
		$('#modal').fadeIn('slow');

		closeModal('body div.overlay');
		closeModal('#modal a.close');
		
		return false;
		
	});
	
});
