$(function () { // This function will run at document.ready

    $('.island').hide();

	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 6000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 600,             // How long the slide transition takes
		hashTags: false,                // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",     	        // Start text
		stopText: "Stop",               // Stop text
		navigationFormatter: null		// Details at the top of the file on this use (advanced use)
	});
	
	$('.island').delay(800).fadeIn(5000);
	if (navigator.appName != "Microsoft Internet Explorer") {
		createBubble('.bubbles');
		createBubble('.bubbles');
		createBubble('.bubbles');
	}
	
	$('.rel-content').hover(
		function(){$('.island img').fadeOut('slow');},
		function(){$('.island img').fadeIn('slow');}
		);
	
});

function createBubble(effervescer) {
	var bubble = $('<img src="../wp-content/themes/SCOct2009Redesign/images/bubble.gif" style="opacity:0; position:absolute; top: 120px; left:30px" />');
	bubble.delay(Math.floor(Math.random()*1000)).appendTo(effervescer);
	animateBubble(bubble, Math.floor(Math.random()*1000), effervescer);
}

function animateBubble(bubble, delay, effervescer) {
	var pos_x = Math.floor(Math.random()*$(effervescer).width())+'px';
	var pos_y = Math.floor(Math.random()*$(effervescer).height())+'px';
	
	bubble.css('top', pos_y);
	bubble.css('left', pos_x);

	var size = Math.floor(Math.random()*10)+6;
	bubble.width(size);
	bubble.height(size);
	
	if (Math.round(Math.random())) {
		bubble.animate({
			top: '-=50',
			opacity: (Math.random()*.5)+.35,
			left: '-=20'
		}, 1000, 'easeInSine');
		bubble.animate({
			top: '-=50',
			opacity: 0,
			left: '+=20'
		}, 1000, 'easeOutSine');
	}
	else{
		bubble.animate({
			top: '-=50',
			opacity: (Math.random()*.5)+.35,
			left: '+=20'
		}, 1000, 'easeInSine');
		bubble.animate({
			top: '-=50',
			opacity: 0,
			left: '-=20'
		}, 1000, 'easeOutSine');
	}
	
	bubble.animate({opacity: 0},delay, function() {animateBubble(bubble, Math.floor(Math.random()*1000), effervescer);});
}