$(document).ready(function() {
	// AJAX
	$.fn.ajax = function() {
		$('.ajax').ajaxStart(function() {
			$(this).html('<img src="/images/loading-bar.gif" alt="ajax loading" />');
		});
		$('.ajax').ajaxStop(function() {
			$(this).html('');
		});
	}
	$.fn.ajax();
	
	// WAIT
	$.fn.wait = function(time, type) {
              time = time || 1000;
              type = type || "fx";
              return this.queue(type, function() {
                  var self = this;
                  setTimeout(function() {
                      $(self).dequeue();
                  }, time);
              });
          };

	
	
	// CONTACT FORM
	$.fn.contactForm = function() {
		$('form#contact input#submit').click( function(event)
		{
			event.preventDefault();
			
			// get form data
			var name 			= $('form#contact input#name').val();
			var email 		= $('form#contact input#email').val();
			var subject		= $('form#contact select#subject').val();
			var info			= $('form#contact textarea#info').val();
			var spamcode_id 		= $('form#contact input#spamcode-id').val();
			var spamcode_code 	= $('form#contact input#spamcode-input').val();
			
			// send form data & get return data
			$('div#content').load('/index/contactajax/', 
															{ 'name'						:name, 
																'email'					:email, 
																'subject'				:subject, 
																'info'					:info, 
																'spamcode[id]'		:spamcode_id, 
																'spamcode[input]'	:spamcode_code },
																function() {
																	$.fn.contactForm(); 
																}
														);
		});
	}
	$.fn.contactForm();
	
	// LINKS - options: background color, background transparency, iframe width/height
	$('a.overlay-iframe').click( function(event)
	{
		event.preventDefault();
	
		// add overlay & display
		$('body').prepend('<div id="overlay"></div>');
		$('div#overlay').css({ 'position':'absolute', 'left':'0', 'top':'0', 'width':'100%', 'height':'100%', 'background':'#000000', 'z-index':'100', 'text-align':'center', 'color':'#ffffff' }).fadeTo('fast', 0.7);
		
		// get iframe source
		var src = $(this).attr('href');
		
		// add iframe & display
		$('body').prepend('<div id="overlay-details"><img class="close" src="/images/close_button.jpg" alt="Close overlay" /><iframe id="overlay-details" src="' + src + '"></iframe></div>');
		$('div#overlay-details').css({ 'position':'absolute', 'left':'0', 'top':'0', 'width':'100%', 'height':'100%', 'z-index':'200', 'text-align':'center' });
		$('div#overlay-details iframe').css({ 'width':'75%', 'height':'75%', 'z-index':'200', 'margin-top':'10em', 'display':'none' });
		//$('div#overlay-details iframe').show('clip', { direction: "horizontal" }, 1000);
		$('div#overlay-details iframe').fadeIn(1000);
		$('div#overlay-details img.close').css({ 'float':'right', 'margin':'1em 1em 0em 0em' });
		
		
		// remove overlay & iframe onclick
		$('div#overlay-details img.close').click( function()
		{	
			// remove overlay & iframe
			$('div#overlay').remove();
			$('div#overlay-details').remove();
			
			
		});
	});
	
	// ABOUT
	$('ul.gallery li').hover(function() {
	$(this).css({'z-index' : '10'});
	$(this).find('img').addClass('hover').stop()
		.animate({
			marginTop: '-110px', 
			marginLeft: '-110px', 
			top: '50%', 
			left: '50%', 
			width: '175px', 
			height: '175px',
			padding: '20px' 
		}, 200);
	
	} , function() {
	$(this).css({'z-index' : '0'});
	$(this).find('img').removeClass('hover').stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '8', 
			left: '8', 
			width: '150px', 
			height: '150px', 
			padding: '0px'
		}, 400);
	});
	
	// DEMO ABOUT GALLERY
	$('ul.gallery li:first').mouseover();

	// RESET GALLERY
	//$('ul#gallery').mouseenter( function() {
	     // $('ul#gallery li img:first').mouseout();
	//});
	
	
	
	// BLOG details overlay - need to combined with above overlay
	/*$('a.overlay').click( function(event)
	{
		event.preventDefault();
	
		// add overlay & display
		$('body').prepend('<div id="overlay"></div>');
		$('div#overlay').css({ 'position':'absolute', 'left':'0', 'top':'0', 'width':'100%', 'height':'100%', 'background':'#000000', 'z-index':'100', 'text-align':'center', 'color':'#ffffff' }).fadeTo('fast', 0.7);
		
		// get iframe source
		var src = $(this).attr('title');
		if (src == '')
		{
			var src = $(this).attr('href');
		}
		
		// add iframe & display
		$('body').prepend('<div id="overlay-details"><img class="close" src="/images/close_button.jpg" alt="Close overlay" /><span class="ajax"></span><div id="overlay-page"></div></div>');
		$('div#overlay-details').css({ 'position':'absolute', 'left':'0', 'top':'0', 'width':'100%', 'height':'100%', 'z-index':'200', 'text-align':'center' });
		$('div#overlay-page').css({ 'width':'75%', 'height':'75%', 'z-index':'200', 'margin':'auto', 'margin-top':'10em', 'background':'#ffffff', 'text-align':'left', 'overflow':'auto', 'padding':'1em' });
		$('div#overlay-details img.close').css({ 'float':'right', 'margin':'1em 1em 0em 0em' });
		
		// ajax in page
		$.fn.ajax();
		$('div#overlay-page').load(src);
		
		// blog message submission
		$('form#message input#submit').click( function(event)
		{
			event.preventDefault();
			
		});
		
		// remove overlay & iframe onclick
		$('div#overlay-details img.close').click( function()
		{	
			// remove overlay & iframe
			$('div#overlay').remove();
			$('div#overlay-details').remove();
			
			
		});
	});
	*/
	
	
	/*
	// debug layer //
	$('body').prepend('<div id="debug"><div id="debug-details"></div><div id="debug-nav"><img src="/images/test/error_sm.png" alt="Test Status" /></div></div>');
	$('div#debug')
			.css({ 'position':'absolute', 'top':'0px', 'left':'0px', 'background':'#000', 'color':'#fff', 'width':'100%' })
			.fadeTo('fast', 0.3);
	$('div#debug-details').hide();
	$('div#debug-nav').css({ 'text-align':'right', 'padding':'0.5em' });

	// show full debug details
	$('div#debug').toggle(
		function() {
			$('div#debug-details').slideDown('fast');
			$('div#debug').fadeTo('fast', 0.7);
		},
		function() {
			$('div#debug-details').slideUp('fast');
			$('div#debug').fadeTo('fast', 0.4);
		}
	);

	// mouse guide
	$.fn.hoverMe = function() {
		$('div#debug-details table tr').hover(
			function() {
				$(this).fadeTo('fast', 1);
			},
			function() {
				$(this).fadeTo('fast', 0.4);
			}
		);
	}

	// ajax in error checking details
	$('div#debug-details').load('/scripts/debug.php', '', $.fn.hoverMe);
	*/
	
	
	

});

