var slideshow = function(){
	function change()
	{
		(slideshow.count < slideshow.max) 
			? slideshow.count++
			: slideshow.count = 1
		$('img[rel="slideshow"]').attr('src',slideshow.images[slideshow.count].src);
		$('img[rel="slideshow2"]').fadeOut(1000,function(){
			$('img[rel="slideshow2"]').attr('src',slideshow.images[slideshow.count].src);
			$('img[rel="slideshow2"]').show();
		});
	};
	return {
		count: 2,
		max: 3,
		images: Array(),
		baseUrl: "http://blog.wake-photography.com/images/mast-",
		init: function(interval)
		{
			$('img[rel="slideshow"]').parent().append('<img src="http://blog.wake-photography.com/images/mast-1.jpg" rel="slideshow2" style="position: absolute; top: 0; left: 0;" />');
			for (i = 1; i <= slideshow.max; i++){
				this.images[i] = new Image();
				this.images[i].src = this.baseUrl+i+".jpg";
			}
			var fader = window.setInterval(change,interval);
		}
	}
}();



var util = function(){
	return {
		init: function()
		{
			$('.commentForm h3 a').click(function(event){ event.preventDefault(); util.showForm() });
			$('.postBody p img').parent().addClass('image');
			$('.commentForm input[name="submit"]').click(function(event){util.formHandler(event,this)});
			util.inputValues();
			util.fixClasses();
		},

		fixClasses: function()
		{
			var parity = "commentOdd";
			$('.comments ol').children('li').each(function(){
				$(this).addClass(parity);
				if (parity == "commentOdd") parity = "commentEven";
				else parity = "commentOdd";
			})
		},
		
		showForm: function()
		{
			if ( $('.commentForm').css('height') == '300px' )
			{
				$('.commentForm form').slideToggle(function(){$('.commentForm').css('height','82px');});
			}
			else
			{
				$('.commentForm').css('height','300px');
				$('.commentForm form').slideToggle();
			}
		},

		formHandler: function(event,obj)
		{
			var parentTag = $(obj).parents('form');
			if($(parentTag).find('input[name="name"]').attr('value') == 'Your Name...')
			{
				event.preventDefault();
				alert('Please enter your name');
			}
			if($(parentTag).find('textarea').val() == 'Your Message...')
			{
				event.preventDefault();
				alert('Please enter your message');
			}
		},

		inputValues: function()
		{
			
			$('.commentForm input').focus(function(){ 
				if ($(this).attr('value') == 'Your Name...')
				{
					$(this).attr('value','') 
					$(this).css('color','#2a72ac');
				}
				else return;
			});
			
			$('.commentForm input').blur(function(){ 
				if ($(this).attr('value') == '')
				{
					$(this).attr('value','Your Name...') 
					$(this).css('color','#bfbfbf');
				}
				else return;
			});
			
			$('.commentForm textarea').focus(function(){ 
				if ($(this).val() == 'Your Message...')
				{
					$(this).val('');
					$(this).css('color','#4c4c4c');
				}
				else return;
			});
			
			$('.commentForm textarea').blur(function(){ 
				if ($(this).val() == '')
				{
					$(this).val('Your Message...');
					$(this).css('color','#bfbfbf');
				}
				else return;
			});

		}
	}
}();
 
 
 
$(document).ready(function() {
	slideshow.init(10000);
	util.init();
});