$(document).ready(init);

function init()
{
	window._uds_vbw_donotrepair = true;
	
	var input = $("input[type='text']")
		.addClass("idleField")
     	.focus(function() 
		{
     		$(this).removeClass("idleField").addClass("focusField");
  		    if (this.value == this.defaultValue)
			{ 
  		    	this.value = '';
			}
			if(this.value != this.defaultValue)
			{
   				this.select();
   			}
  		})
		.blur(function() 
		{
  			$(this).removeClass("focusField").addClass("idleField");
  		    if ($.trim(this.value) == '')
			{
	    		this.value = (this.defaultValue ? this.defaultValue : '');
			}
  		});

	$("#boats_rollover_top").mouseout(hideBoatRollover);
	
	setupVideoPlayer();
	setupMarquee();
	setupFlickrFeed();
	setupTwitterFeed(true);
}

function setupVideoPlayer()
{
	function LoadVideoBar() 
	{
		var videoBar;
		var options = 
		{
		    largeResultSet : !true,
		    horizontal : true,
		    autoExecuteList : 
			{
		      cycleTime : GSvideoBar.CYCLE_TIME_MEDIUM,
		      cycleMode : GSvideoBar.CYCLE_MODE_LINEAR,
		      executeList : ["ytchannel:axiswake"]
		    }
		}
		
		videoBar = new GSvideoBar(document.getElementById("videoBar-bar"),
		                          GSvideoBar.PLAYER_ROOT_FLOATING,
		                          options);
	}
	// arrange for this function to be called during body.onload
	// event processing
	GSearch.setOnLoadCallback(LoadVideoBar);
}

function setupMarquee()
{
	$('#slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 5000,
		timeoutFn: slideChanged
	});
	
	function slideChanged(currElement, nextElement, opts, isForward)
	{
		var buttons = $("#marqueeButtonParent").children();
		
		$("#dots").find("div")
			.each(function(index)
			{
				$(buttons[index]).hide();
				$(this).html("<img src='images/grey_marquee_dot.png' width='10' height='10' alt='Grey Marquee Dot'>");
				if(index === opts.currSlide)
				{
					$(buttons[index]).show();
					$(this).html("<img src='images/red_marquee_dot.png' width='10' height='10' alt='Grey Marquee Dot'>");
				}
			});
			
		return 5000;
	}
									
	$("#dots").click(function(e) 
	{
		var dot = $(e.target);
		dotId = dot.parent().attr("id");
		
		// alert("clicked: " + dotId);
		$("#dots").find("div")
			.each(function(index)
			{
				if($(this).attr("id") == dotId)
				{
					$("#slideshow").cycle(index);
				}
			})
	});
    
}

function setupFlickrFeed()
{
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=31972300@N03&lang=en-us&format=json&jsoncallback=?", function(data)
	{
		$.each(data.items, function(i, item)
		{
			var bigImage = item.media.m.replace("_m.", ".");
			var smallImage = item.media.m.replace("_m.", "_s.");
			var tag = $("<img/>");
			if(i == 0)
			{
				tag.attr("src", bigImage)
					.attr("style", "margin: -10px 0px 0px -10px")
					.appendTo("#images")
					.wrap("<a rel='flickr' class='images' href='" + bigImage + "'></a>")
					.wrap("<div class='first_image' />");
			}
			else if( i > 0 && i <= 4)
			{
				tag.attr("src", item.media.m)
					.attr("style", "margin: -10px 0px 0px -10px")
					.appendTo("#images")
					.wrap("<a rel='flickr' class='images' href='" + bigImage + "'></a>")
					.wrap("<div class='other_images' />");
			}
			else if( i > 4 && i <= 8)
			{
				tag.attr("src", item.media.m)
					.attr("style", "margin: -10px 0px 0px -10px")
					.appendTo("#images")
					.wrap("<a rel='flickr' class='images' href='" + bigImage + "'></a>")
					.wrap("<div class='other_images' />");
			}
			else
			{
				tag.attr("src", item.media.m)
					.appendTo("#images")
					.wrap("<a rel='flickr' class='images' href='" + bigImage + "'></a>")
					.wrap("<div class='hidden_images' />");
			}
		});
		$(".images").fancybox({
			'padding' : 17
		});
		$("#images").wrap("<div class=images />");		
	});
	
}

function setupTwitterFeed(bUse)
{
	if(bUse)
	{
		$(".tweet").tweet({
			username: "axiswake",
			join_text: "auto",
			avatar_size: 0,
			count: 5,
			auto_join_text_default: "", 
	     	auto_join_text_ed: "",
	        auto_join_text_ing: "",
	        auto_join_text_reply: "",
	        auto_join_text_url: "",
			loading_text: "loading tweets..."
		});
	}
	
}

function onBoatMouseOver()
{
	$("#boats_rollover").css("visibility", "visible")
						.css("display", "block");
}

function hideBoatRollover()
{
	$("#boats_rollover").css("visibility", "hidden")
						.css("display", "none");
}

// el is the element that was rolled over or rolled out of. 
function mainNavRollover(el)
{
	var elName = $(el).find("span").text();
	var elDiv = $(el).find("div");
	switch(elName)
	{
		case "Options":
			elDiv.css("top", "-15px")
				.css("left", "60px")
				.toggleClass("other_nav_rollover_hidden other_nav_rollover_visible");
		break;
			
		case "The Wake":
			elDiv.css("top", "-15px")
				.css("left", "170px")
				.toggleClass("other_nav_rollover_hidden other_nav_rollover_visible");
		break;
		
		case "Axis DNA":
			elDiv.css("top", "-15px")
				.css("left", "282px")
				.toggleClass("other_nav_rollover_hidden other_nav_rollover_visible");
		break;
		
		case "Build Your Own":
			elDiv.css("top", "-20px")
				.css("left", "385px")
				.toggleClass("other_nav_rollover_hidden build_own_rollover");
		break;
		
		default : alert("no such element exists: " + elName);
	}
}

