var news_h = 0;

function jump_to(url) {
	// acts like a page anchor
	if ( $("a[href=" + url + "]:first") ) {
		t = $("a[href=" + url + "]:first").offset().top;
		$(window).scrollTop(t-20);
	}
}

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function scroll_news() {
	/*if ( $("#news").scrollTop() >= news_h - $("#news").innerHeight() ) {
		$("#news").scrollTop(0);
	} else {
		$("#news").scrollTop ( $("#news").scrollTop() + 1 );
	} */
	$("#news").scrollTop ( $("#news").scrollTop() + 1 );
}

function scroll_shortcuts() {
	$("#shortcuts").stop(true, true);
	temp = Math.round($(window).scrollTop() - 320);
	if (temp < 0) { temp = 0; }
	$("#shortcuts").animate({ 
		top: temp + "px"
	  }, 300, "swing" );
}

function setStyle($element,$tag,$val) {
	$el = eval("document.getElementById('" + $element + "')");
	$el.style[$tag] = $val;
}
	
function show(divname) {
	document.getElementById(divname).style.visibility = "visible";
}
	
function hide(divname) {
	document.getElementById(divname).style.visibility = "hidden";
}

function toggle(divname) {
	$("#" + divname).slideToggle(150);
	a = "a[href*='" + divname + "']";
	if ($(a).text().indexOf("(click to read)") > -1) {
		txt = $(a).text().replace(/click to read/, "click to close");
	} else {
		txt = $(a).text().replace(/click to close/, "click to read");
	}
	$(a).text(txt);
}

$(document).ready( function() {
							
	// logo rollover
	$("#logo").hoverIntent(
		function() {
			$(this).children(":first").attr('src', '/images/logo_over.gif');
		},
		function() {
			$(this).children(":first").attr('src', '/images/logo.gif');
		}
	);
							
	// setup shortcuts scroll	
	if ($("#shortcuts")) {
		shortcuts_top = $("#shortcuts").offset().top;
		$(window).bind("scroll", scroll_shortcuts);
		scroll_shortcuts();
	}
	
	// news scroller
	$("#news").children().each( function(i) {
		news_h += $(this).outerHeight();
	});
	
	if ($("#news")) {
		$("#news").scrollTop(0);
		$("#news").bind("focus mouseover", function(i) {
			clearInterval(news_scroll);
		});
		$("#news").bind("blur mouseout", function(i) {
			news_scroll = setInterval('scroll_news()', 50);							
		});
		var news_scroll = setInterval('scroll_news()', 50);
	}
	
	// splash animation & rollover
	if ($("#splash")) {
		$("#splash-left, #splash-right").hover(
			function() {
				$(this).children().css('color', '#ffffff');
				src = $(this).children("img").attr('src').replace(/\.gif/, '_over.gif');
				$(this).children("img").attr('src', src);
			},
			function() {
				$(this).children().css('color', '#cccccc');
				src = $(this).children("img").attr('src').replace(/_over\.gif/, '.gif');
				$(this).children("img").attr('src', src);
			}											 
		);
		
		
		meet = $(".content:first").position().left + 350;
		$("#splash-left").animate( { left: (meet - $("splash-left").width()) + "px" }, 1000, "linear", function() {
			$("#splash-left").animate( { left: (meet - $("splash-left").width() - 50) + "px" }, 150, "swing", function() {
				$("#splash-left").animate( { left: (meet - $("splash-left").width()) + "px" }, 100, "swing" );																										  			});
		});
		
		
		$("#splash-right").animate( { left: meet + "px" }, 1000, "linear", function() {
			$("#splash-right").animate( { left: (meet + 50) + "px" }, 150, "swing", function() {
				$("#splash-right").animate( { left: meet + "px" }, 100, "swing" );																										  			});
		});
	}

});