$(document).ready(function(){

	$("div.entry").mouseenter(function() {
		$("div.content", this).slideUp(150);
	});

	$("div.entry").mouseleave(function() {
		$("div.content", this).slideDown(150);
	});

	activateHOver("#mailLink1");
	activateHOver("#mailLink2");

	configureEntryes(false);
	updateRolloversSize();

	$(window).resize(function() { onResize() });

	$(".entry a").each(function() {
		
		var href = $(this).attr("href");				

		$(this).parent().attr("href", href);
		$(this).parent().click(function() { window.open($(this).attr("href")); event.preventDefault(); } );
		$(this).removeAttr("href");
	});
	
});

function configureEntryes(resize)
{
	var lastLeft = 0;
	var lastWidth = 880;
	var firstEntry = true;
	var WIDTH = $(window).width() - 80;
	var MIN_WIDTH = 880;

	$("div.content").each(function() {

		$(this).css("opacity", 0.6);

		if (firstEntry) { firstEntry = false; return; }
		
		var width = MIN_WIDTH;
		var space = WIDTH - width;

		var left = Math.floor(Math.random() * (WIDTH - width) );
		left = (left < 0) ? 0 : left;
		left = ((left + width) > WIDTH) ? WIDTH - width : left;

		$(this).animate({marginLeft: left + "px"}, (resize) ? 0 : 4000);
		$(this).css("width", width + "px");
		
		lastLeft = left;
		lastWidth = width;
	});

	$("div.entry").each(function() {
		$(this).css("overflow", "hidden");
		$(this).css("height", "95px");
	} );
}

function updateRolloversSize() 
{
	$("div.rollover").each(function() {
		$(this).css("width", ($(window).width() - 80) + "px" );
		$(".text", this).css("width", ($(window).width() - 80 - 100) + "px");
	} );
}

function onResize()
{
	configureEntryes(true);
	updateRolloversSize();
}

function activateHOver(obj)
{
	$(obj).hover(function() {
		var currentImg = $(this).attr("src");
		$(this).attr("src", $(this).attr("hover"));
		$(this).attr("hover", currentImg);
	}, function() {
		var currentImg = $(this).attr('src');
		$(this).attr("src", $(this).attr("hover"));
		$(this).attr("hover", currentImg);
	});
}
    
