$(document).ready(function() 
{
	$("ul.sf-menu").supersubs({
		minWidth: 13,
		maxWidth: 13,
		extraWidth: 2
	}).superfish({ 
		delay: 100,
		animation: { opacity:'show', height:'show' },
		speed: 300,
		autoArrows: true,
		dropShadows: true
	});
	
	// $('#container').bubbles();
	
	$('#nav li:last-child').css('background', 'none');
	
	/*
	$('#social a')
		.css({opacity: 0.7})
		.mouseenter(function(event)
		{
			$(this).stop().animate({opacity: 1}, 150);
		})
		.mouseleave(function()
		{
			$(this).stop().animate({opacity: 0.7}, 150);
		});
	*/
	
	/*
	$('#video_nav a img').css({opacity: 0.7});
	$('#video_nav a')
		.mouseenter(function(event)
		{
			$(this).find('img').stop().animate({opacity: 1}, 150);
		})
		.mouseleave(function()
		{
			$(this).find('img').stop().animate({opacity: 0.7}, 150);
		});
	*/
});
/*
(function ($) 
{
	$.fn.vAlign = function() 
	{
		return this.each(function(i)
		{
			//var margin = ($('#content').height() - $(this).height());
			//$(this).css("margin-top", margin + "px");
			
			var contentHeight = $('#content').height();
			var sidebarHeight = $('#sidebar').height();
			
			if(sidebarHeight < contentHeight)
			{
				$('#sidebar').css({height: contentHeight+'px'});	
			}
			
		});	
	};
	
})(jQuery);
*/
(function($)
{
	$.fn.bubbles = function(settings) 
	{
		$.fn.bubbles.defaults = 
		{
			particles	: 50,
			speedX		: 2,
			speedY		: 5,
			interval	: 50,
			directory	: '/wp-content/themes/mrbubble/images/'
		};
		
		var config = $.extend({}, $.fn.bubbles.defaults, settings);
		var bubbles = ['bubble_1.png', 'bubble_2.png', 'bubble_3.png', 'bubble_4.png', 'bubble_5.png'];
		var particles = [];
		
		function init(element)
		{
			$('body').css('overflow-x', 'hidden');
			
			var width = $(window).width();
			var height = $(window).height();
			
			var particle =  $('<img src="#" />');
			particle.css(
			{
				left		: '0px',
				top			: '0px',
				position	: 'absolute'
			});
			
			for(var i=0; i<config.particles; i++)
			{
				var p = particle.clone();
				
				p.bind('mousedown', function() { return false; });
				p.attr('id', 'particle_' + i);
				p.attr('src', config.directory + bubbles[ Math.floor(Math.random() * bubbles.length) ]);
				p.css(
				{
					top			: Math.floor(Math.random() * height),
					left		: Math.floor(Math.random() * width)
				});
				p.speedX = Math.round(Math.random() * (config.speedX * 2) - config.speedX);
				p.speedY = Math.round(Math.random() * (config.speedY * 2) - config.speedY);
				p.appendTo(element);
				
				particles.push(p);
			}
			
			setInterval(update, config.interval);
		}
		
		function update()
		{
			for(i in particles) 
			{
				var particle = particles[i];
				var left = parseInt(particle.css('left'));
				var top = parseInt(particle.css('top'));
				
				if(top > $(window).height()) 
				{
					top = -particle.height();
				}
				else if(top < -particle.height())
				{
					top = $(window).height();
				}
				
				if(left > $(window).width()) 
				{
					left = -particle.width();
				}
				else if(left < -particle.width())
				{
					left = $(window).width();
				}
				
				particles[i].css(
				{
					left	: left + particle.speedX + 'px',
					top		: top + particle.speedY + 'px'
				});
			}
        }
		
		
		function debug(message)
		{
			if(window.console && window.console.log)
			{
				window.console.log(message);
			}
		}
		
		init(this);
		
		return this.each(function() { });
		
	};
	
})(jQuery);
