var initVar = false;
$("body").ready(init);
$("window").load(init);

function init()
{
	if(true == initVar)
		return;
	initVar = true;
	
	$(".submenu").css("opacity",0.0);
	$(".menu,.menuActive").each(function(c,e){
		$(e).hoverIntent({
		interval:50,
		over:showSubmenu,
		timeout:50,
		out:hideSubmenu
	});});
	
	$(".lightboxcontainer img").click(showBox);
	
	
	
	var height = 0;
	var counter = 0;
	$('#innerContent2').find('.capsule').each(function(c,e)
	{
		if($(e).width() > 500)
			return;
		
		height = ($(e).height()>height?$(e).height():height);
		
	});
	
	$('#innerContent2').find('.capsule').each(function(c,e)
		{
			if($(e).width() > 500)
				return;
				
			if(counter%2 == 0)
				$(e).css("margin-right",4);
			$(e).height(height);
			counter++;			
		});	
}

function showBox()
{
		var lightbox = $(this).parent().find(".lightbox");
		lightbox.show();
		var width  = lightbox.find("img").width();
		var height = lightbox.find("img").height();
		height += lightbox.find("p").height();
		
		lightbox.animate({
			width: width,
			height: height,
		});
		lightbox.bind("click",{},hideBox);
		
}

function hideBox()
{
	$(this).animate({
		width: 1,
		height: 1,
	},"normal",function(){$(this).hide();});
	
	$(this).unbind("click");
}


function showSubmenu()
{
	$(this).find(".submenu").css("display","block");
	$(this).find(".submenu").animate({opacity:1.0},1500);
}

function hideSubmenu()
{
	$(this).find(".submenu").animate({opacity:0.0},1500);
}
