
$(document).ready(function(){

	$("#thumbnails img").bind("click", function(e){
		var big = $(this).attr("src");			
		$("#focus-image").attr("src", str_replace(".jpg", "",big) +"-full.jpg");
		$('.active').removeClass("active");
		$(this).addClass("active");
	});

	startRotation();

	$("#nav .register").bind("mouseover", function(e){
		hideFlyouts('register');
		$("#nav .register").animate( { width:"155px"}, "fast" );
		$("#register-flyout").fadeIn("fast");		
		hover = true;
	});

	$("#nav .about").bind("mouseover", function(e){
		hideFlyouts('about');
		$("#nav .about").animate( { width:"155px"}, "fast" );
		$("#about-flyout").fadeIn("fast");		
		hover = true;
	});
	$("#nav .summit").bind("mouseover", function(e){
		hideFlyouts('agenda');
		$("#nav .summit").animate( { width:"155px"}, "fast" );
		$("#agenda-flyout").fadeIn("fast");		
		hover = true;
	});
	$("#nav .speaker").bind("mouseover", function(e){
		hideFlyouts('speaker');
		$("#nav .speaker").animate( { width:"155px"}, "fast" );
		$("#speaker-flyout").fadeIn("fast");		
		hover = true;
	});
	$("#nav .past").bind("mouseover", function(e){
		hideFlyouts('past');
		$("#nav .past").animate( { width:"155px"}, "fast" );
		hover = true;
	});

	$("#nav .register").bind("mouseout", function(e){
		hover = false;
		setTimeout('hideFlyouts();', 1000);
	});
	$("#nav .about").bind("mouseout", function(e){
		hover = false;
		setTimeout('hideFlyouts();', 1000);

	});
	$("#nav .summit").bind("mouseout", function(e){
		hover = false;
		setTimeout('hideFlyouts();', 1000);

	});
	$("#nav .speaker").bind("mouseout", function(e){
		hover = false;
		setTimeout('hideFlyouts();', 1000);
	});
	$("#nav .past").bind("mouseout", function(e){
		hover = false;
		setTimeout('hideFlyouts();', 1000);
	});
});

var hover = false;

function hideFlyouts(ignore) {
	if(!hover) {
		if(ignore != 'about') {
			$("#about-flyout").fadeOut("fast");
			$("#nav .about").animate( { width:"114px"}, "fast" );
		}
		if(ignore != 'register') {
			$("#register-flyout").fadeOut("fast");
			$("#nav .register").animate( { width:"155px"}, "fast" );
		}
		if(ignore != 'agenda') {
			$("#agenda-flyout").fadeOut("fast");
			$("#nav .summit").animate( { width:"137px"}, "fast" );
		}
		if(ignore != 'speaker') {
			$("#speaker-flyout").fadeOut("fast");
			$("#nav .speaker").animate( { width:"116px"}, "fast" );
		}
		if(ignore != 'past') {
			$("#nav .past").animate( { width:"107px"}, "fast" );
		}
	}
}

var go = true;

function startRotation() {
	go = true;
	if(go)
		setTimeout('rotation();', 7000);
}

function rotation() {
	rotate('right');
	if(go)
		setTimeout('rotation();', 7000);
}

function rotate(dir, click) {
	if(go || click) {
		if(dir == 'left') {
			var v = $("#thumbnails img.active").next();
	
			if(!v.length) {
				v = $("#thumbnails img:first");
			}
		}
	
		if(dir == 'right') {
			var v = $("#thumbnails img.active").prev();
	
			if(!v.length) {
				v = $("#thumbnails img:last");
			}
		}
	
		if(click)
			go = false;
	
		var big = $(v).attr("src");			
		$("#thumbnails img.active").removeClass("active");
		$("#focus-image").attr("src", str_replace(".jpg", "",big) +"-full.jpg");
		$(v).addClass("active");
	}
}

function str_replace(find, replace, search) {
	return search.split(find).join(replace);
}
