function initAccordion()
{
	var element = $(".paragraph");
	element.children(".content").hide();
	element.children(".content").first().show();
	
	element.children(".content-head").click(function(){
		var index = element.children(".content-head").index($(this));
		var thisContent = element.eq(index).children(".content");
		if (thisContent.is(":hidden"))
		{
			element.children(".content").not(":hidden").slideUp(400);
			thisContent.slideDown(400);
		}
	});
}

function Menu()
{
	this.resetDelay = 250;
	this.handle = null;
	
	this.setSubmenu = function(i)
	{
		$("#nav2 div.menu-entry").removeClass("menu-show");
		$("#nav2 div.menu-entry").eq(i).addClass("menu-show");
	};
	
	this.setSelected = function()
	{
		var pos = $("#nav1 a").index($("#nav1-active"));
		this.setSubmenu(pos);
	};
	
	this.resetMenu = function()
	{		
		outerThis = this;
		reset = function()
		{
			outerThis.setSelected();
		};
		this.handle = window.setTimeout("reset()", this.resetDelay);
	};
	
	this.abortReset = function()
	{
		if (this.handle != null)
		{
			window.clearTimeout(this.handle);
		}
		this.handle = null;
	};
	
	this.init = function()
	{
		this.setSelected();
		outerThis = this;
		
	    $("#nav1 a").each(function(i, elem)
	    {
	    	$(elem).hover(function()
	    	{	
	    		outerThis.abortReset();
		    	var i = $("#nav1 a").index($(this));
		    	outerThis.setSubmenu(i);
	    	},
	    	function()
	    	{
	    		outerThis.resetMenu();
	    	});
	    });

    	var funcIn = function()
    	{
    		outerThis.abortReset();
    	};
    	
    	var funcOut = function()
    	{
    		outerThis.resetMenu();
    	};

    	$("#nav2").hover(funcIn, funcOut);
    	$("#nav2-overlay").hover(funcIn, funcOut);
	};
	
	this.init();
}

function inputfields()
{
	$(".input").each(function()
	{
		active = false;
		html = $(this).attr("value");
		
		$(this).focus(function(){
	    	if (active == false)
			{
	    		active = true;
	    		$(this).attr("value","");
			}
	    });
	    $(this).blur(function(){
	    	if ($(this).attr("value").length == 0)
			{
	    		active = false;
	    		$(this).attr("value", html);
			}
	    });
	});
    
}

function lightbox()
{
	var imagePath = "";
	$("head script").each(function(i, elem){
		var src = $(elem).attr("src");
		if (src != undefined && src.match("jquery.lightbox") != null)
		{
			imagePath = src.substring(0, src.substring(0, src.lastIndexOf("/")).lastIndexOf("/"));
			imagePath += "/img/lightbox/";
			return;
		}
	});
	$("a.lightbox").lightBox({
    	imageBlank: imagePath + 'lightbox-blank.gif',
    	imageLoading: imagePath + 'lightbox-ico-loading.gif',
    	imageBtnClose: imagePath + 'lightbox-btn-close.gif',
    	imageBtnPrev: imagePath + 'lightbox-btn-prev.gif',
    	imageBtnNext: imagePath + 'lightbox-btn-next.gif'
    });
}

$(function()
{
    if (options.accordion)
	{
    	initAccordion();
	}
    
    var menu = new Menu();
    
    inputfields();
    lightbox();
    
    $("div.imageArea").each(function (i, elem){
    	var width = $(elem).children("a.lightbox").children("img").attr("width");
    	var heightImg = $(elem).children("a.lightbox img").attr("height");
    	var heightDesc = $(elem).children("div.description").css("width");
    	var heightImageArea = parseFloat(heightImg) + parseFloat(heightDesc.substring(0, heightDesc.length-2));
    	$(elem).css("width", width + "px");
    	$(elem).css("height", heightImageArea + "px");
    });
});

