// Contact form window...
window.addEvent('domready',function() {
	
	doBump(
		   '.bx2',
		   850,
		   500,
		   'FFF',
		   '000',
		   0.4,
		   10,
		   0,
		   'FFF',
		   15,
		   '444',
		   2,
		   Fx.Transitions.Back.easeOut,
		   Fx.Transitions.linear,
		   null,
		   null,
		   null,
		   null,
		   null,
		   null,
		   null,
		   bumpIconPath
		);
	
	//doBump(names, inSpeed, outSpeed, boxColor, backColor, bgOpacity, bRadius, borderWeight, borderColor, boxShadowSize, boxShadowColor, iconSet, effectsIn, effectsOut, bgImage, bgPosition, bgRepeat, noLRcommands, onloadFireEventClass, onloadFireEventDelay, callbackFunc, iconPath)	
	
});

// Self contain the jQuery stuff to avoid conflict with moo tools...
(function($) {

	$(document).ready( function () {

		if($('#s').size() > 0)
		{
			$('#s').data('original-value', $('#s').val());
			
			$('#s').focus( function () {
					if($(this).val() == $(this).data('original-value'))
						$(this).val('');
				});
			
			$('#s').blur( function () {
					if($(this).val() == '')
						$(this).val($(this).data('original-value'));
				});
		}
		
		if($('.gform_wrapper').size() > 0)
		{
			$(this).find('.gform_description').wrap('<p></p>').parents('p').css('margin', '0 0 5px -2px');
			
			$('.gform_wrapper').each( function () {
				
				$(this).find('.validation_message').each( function () {
						$(this).html($(this).html().replace('This field', 'The above field'));
					});
				
				$(this).find('form').submit( function () {
					
						$(this).find('input[type=text], textarea').each( function () {
							
								if($(this).val() == $(this).data('label-value'))
									$(this).val('');
							
							});
	
					});
				
				$(this).find('input[type=text], textarea').each( function () {
					
					var label_value = $('label[for="' + $(this).attr('id') + '"]').text().replace('*', ' *');

					if($(this).val() == '')
						$(this).val(label_value);
	
					$(this).data('label-value', label_value);
					
					$(this).focus( function () {
						
							if($(this).val() == $(this).data('label-value'))
								$(this).val('');
						
						});
					
					$(this).blur( function () {
						
							if($(this).val() == '')
								$(this).val($(this).data('label-value'));
						
						});
					
				});
				
			});
		}
		
		if($('.mini-slideshow').size() > 0)
		{
			$('.mini-slideshow').before('<div class="slideshow-control">Pause</div>');

			$('.mini-slideshow').cycle({
					fx: 'scrollHorz',
					next: '.slideshow', 
					pause: 0
				});
			
			$('.mini-slideshow img').click( function () {
					$('.slideshow-control').trigger('click');
				});
			
			$('.slideshow-control').click( function () {

					if($(this).hasClass('play'))
					{
						$('.mini-slideshow').cycle('resume');
						$(this).removeClass('play');
					}
					else
					{
						$('.mini-slideshow').cycle('pause');
						$(this).addClass('play');
					}
					
				});
		}
		
		if($('.slideshow-holder').size() > 0)
		{
			$('.slideshow-holder').hide();

			$('.slideshow-holder').each( function () {
				
				if($(this).find('.slideshow').children().size() > 1)
				{
					$(this).prepend('<div class="large-slideshow-control large-slideshow-control-prev" id="' + $(this).attr('id') + '-prev">Prev</div>');
					$(this).prepend('<div class="large-slideshow-control large-slideshow-control-next" id="' + $(this).attr('id') + '-next">Next</div>');
					$(this).prepend('<div class="slideshow-pager" id="' + $(this).attr('id') + '-pager"></div>');
					
					$(this).hover( function () {
											$(this).find('.large-slideshow-control, .slideshow-pager').fadeIn();
										},
										function () {
											$(this).find('.large-slideshow-control, .slideshow-pager').fadeOut();
										}
					);
				}

				$(this).find('.slideshow').find('img').show();
				$('.slideshow-list').css('background', 'none');
				
				$(this).find('.slideshow').cycle({
					fx: 'scrollHorz',
					next: '#' + $(this).attr('id') + '-next',
					prev: '#' + $(this).attr('id') + '-prev',
					timeout: 9000,
					pause: true,
					pager: '#' + $(this).attr('id') + '-pager'
				});
				
				$(this).find('.slideshow').cycle('pause');

				if($(this).hasClass('slideshow-selected'))
				{
					$(this).show();
					$(this).find('.slideshow').cycle('resume');
				}

			});
		}
		
		if($('#client-list').size() > 0)
		{
			$(this).find('.client-image').each( function () {
				
					$(this).data('original-margintop', $(this).css('margin-top').replace('px', ''));
					$(this).css('margin-top', 0);
					
					$(this).animate( { marginTop: $(this).data('original-margintop') }, 1000, 'easeOutBounce');

					$(this).data('original-width', $(this).width());
					$(this).data('original-height', $(this).height());
				
				});
			
			$(this).find('.client-image').hover( function () {
				
						var new_width = Math.round($(this).width() * 1.2);
						var new_height = Math.round($(this).height() * 1.2);
						
						var height_difference = new_height - $(this).height();
						var new_margin_top = $(this).data('original-margintop') - (height_difference / 2);
						
						$(this).animate( {
											width: new_width,
											height: new_height,
											marginTop: new_margin_top
										},
										150
									);
					},
					function () {
						
						$(this).animate( {
											width: $(this).data('original-width'),
											height: $(this).data('original-height'),
											marginTop: $(this).data('original-margintop')
										},
										150
									);

					}
				);

			$('#client-list-pages').cycle({
					fx: 'scrollHorz',
					next: '#client-list-next',
					prev: '#client-list-prev',
					timeout: 0,
					startingSlide: client_list_start_page
				});
		}
		

		if($('.flowplayer').size() > 0)
		{
			$('.flowplayer').each( function () {
				
				if($(this).hasClass('make-black-bg'))
				{
					$(this).parents('.middleSection').addClass('black').wrapInner('<div style="padding: 10px 0 0 0;"></div>');
					$(this).parents('.middleSection').find('p').css('padding', '0');
				}
				else
				{
					$(this).parents('.middleSection').wrapInner('<div></div>');
					$(this).parents('.middleSection').find('p').css('padding', '0');
				}

				flowplayer(
					$(this).attr('id'),
					flowplayerSWF,
					{
						plugins:
						{
							controls:
							{
								autoHide: 'always',
								scrubber: false,
								fullscreen: false,
								time: false,
								volume: false
							}
						},
						clip:
						{
							autoPlay: true,
							autoBuffering: true
						}
					}
				).ipad().play();
				
			});
		}
		
		if($('.project-bottom').size() > 0)
		{
			var max_height = 350;
			
			$('.project-bottom').each( function () {
				
					if($(this).height() > max_height)
						max_height = $(this).height();

					if(!$(this).hasClass('project-selected'))
						$(this).find('.project-content').css('display', 'none');
				
				});
			
			$('.mainContent').css('height', max_height + 'px');
			
			$('.project-bottom').hover(
					function ()
					{
						$(this).switchClass('project-opaque');
						
					},
					function ()
					{
						if(!$(this).hasClass('project-selected'))
						{
							$(this).switchClass(false, 'project-opaque');
						}
					}
				);
			
			$('.project-bottom').click( function () {
				
					if($(this).hasClass('project-selected'))
						return;

					$('.project-bottom').removeClass('project-selected');
					$('.project-bottom').addClass('project-opaque');
					
					$(this).removeClass('project-opaque');
					$(this).addClass('project-selected');
					
					$('.project-bottom .project-content').css('display', 'none');
					$(this).find('.project-content').fadeIn();
					
					var project_id = $(this).attr('id').replace('project-', '');
					
					$('.slideshow-holder').hide();
					$('.slideshow-holder').find('.slideshow').cycle('pause');

					$('#slideshow-' + project_id).fadeIn();
					$('#slideshow-' + project_id).find('.slideshow').cycle('resume');

				});
		}

	});

})(jQuery);

function twitterCallback(twitters)
{
	var statusHTML = [];
	
	tweet_count = 0;
	tweet_index = 0;
	
	while(tweet_count < 3)
	{
		if(!twitters[tweet_index].text)
		{
			tweet_index ++;
			continue;
		}
		
		var username = twitters[tweet_index].user.screen_name;
		var status = twitters[tweet_index].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) { return '<a href="'+url+'">'+url+'</a>'; }).replace(/\B@([_a-z0-9]+)/ig, function(reply) { return reply.charAt(0) + '<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>'; });
	
		var html = '<li class="tweet tweet-' + tweet_index + '"><span>' + status + '</span> <a class="tweet-date" href="http://twitter.com/' + username + '/statuses/' + twitters[tweet_index].id_str + '">' + relative_time(twitters[tweet_index].created_at) + '</a></li>';

		html += '<li class="' + ((tweet_index % 2 == 0) ? 'arrow-left' : 'arrow-right') + ((tweet_index == 2) ? ' arrow-no-margin' : '') + '"></li>';
		
		statusHTML.push(html);
		
		tweet_count ++;
		tweet_index ++;
	}
	
	document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function relative_time(time_value)
{
	var values = time_value.split(" ");
	time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];

	var parsed_date = Date.parse(time_value);
	var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	delta = delta + (relative_to.getTimezoneOffset() * 60);
	
	if(delta < 60)
		return 'less than a minute ago';
	else if(delta < 120)
		return 'about a minute ago';
	else if(delta < (60 * 60))
		return (parseInt(delta / 60)).toString() + ' minutes ago';
	else if(delta < (120 * 60))
		return 'about an hour ago';
	else if(delta < (24 * 60 * 60))
		return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
	else if(delta < (48 * 60 * 60))
		return '1 day ago';
	else
		return (parseInt(delta / 86400)).toString() + ' days ago';
}

