function Steuma()
{
	this.currentProjectDisplay = 0;
	this.projectDisplay = Array();
	this.projectDisplayImgBack = null;
	this.projectDisplayImgFront = null;

	this.addProjectDisplay = function(title,url,image)
    {
		var preloader = new Image();
		preloader.src = image;
		this.projectDisplay[this.projectDisplay.length] = Array(title,url,image,preloader);
	}

	this.setupProjectDisplay = function()
    {
		if( this.projectDisplay.length == 0 )
		{
			return;
		}

		this.projectDisplayImgBack = new Element("img");
		this.projectDisplayImgFront = new Element("img");
		this.projectDisplayImgBorder = new Element("img");
		this.projectDisplayImgBorder.src = "img/displayborder.png";
		this.projectDisplayImgBorder.addClass("border");

		this.projectDisplayImgFront.fx = new Fx.Tween(this.projectDisplayImgFront,{
			onComplete: function(){
				this.instance.projectDisplayImgBack.src = this.instance.projectDisplayImgFront.src;
			}
		});
		this.projectDisplayImgFront.fx.instance = this;

		this.projectDisplayImgBack.inject($("projectdisplay"));
		this.projectDisplayImgFront.inject($("projectdisplay"));
		this.projectDisplayImgBorder.inject($("projectdisplay"));

		this.projectDisplayImgBack.src = this.projectDisplay[this.currentProjectDisplay][3].src;
		this.projectDisplayImgFront.src = this.projectDisplay[this.currentProjectDisplay][3].src;

		for( var i = 0; i < this.projectDisplay.length; i++ )
		{
			var anchor = new Element("a");
			anchor.href = this.projectDisplay[i][1];
			anchor.innerHTML = this.projectDisplay[i][0];
			anchor.inject($("projectinfo"));
		}

		$("projectinfo").fx = new Fx.Tween($("projectinfo"));
	}

	this.runProjectDisplay = function()
    {
		this.currentProjectDisplay++;

		if( this.currentProjectDisplay >= this.projectDisplay.length )
		{
			this.currentProjectDisplay = 0;
		}

		
		this.projectDisplayImgFront.fx.set("opacity",0);
		this.projectDisplayImgFront.src = this.projectDisplay[this.currentProjectDisplay][3].src;
		this.projectDisplayImgFront.fx.start("opacity",0,1);

		
		//this.projectDisplayImgBack.src = this.projectDisplay[this.currentProjectDisplay][3].src;
		$("projectinfo").fx.start("top",-(this.currentProjectDisplay*26));

		this.runProjectDisplay.delay(10000,this);
	}

    this.setupNewsNavigator = function()
    {
        var newsListing = $(document.body).getElement("div.borderbox dl.news");
        var newsNavigationPrev = $(document.body).getElement("div.borderbox div.newsnavigation a.new");
        var newsNavigationNext = $(document.body).getElement("div.borderbox div.newsnavigation a.old");

        if(( newsListing != null ) && ( newsNavigationPrev != null ) && ( newsNavigationNext != null ))
        {
            var current_id = parseInt(newsListing.getAttribute("currentid"),0);
            if( current_id > 0 )
            {
                newsListing.instance = new SteumaNewsListing(current_id,newsListing,newsNavigationPrev,newsNavigationNext);
                newsListing.instance.setup();
            }
        }
    }

    this.fixProductHeight = function()
    {
        /*
         <dl class="products">
        {foreach from=$Products item=product name=products}
            <dd{if $smarty.foreach.products.index %2 == 0} class="clear"{/if}>
         */

        var maxHeight = 1;
        var products = $$("dl.products dd");
        for( var i = 0; i < products.length; i++ )
        {
            if( maxHeight < products[i].offsetHeight )
            {
                maxHeight = products[i].offsetHeight;
            }
        }
        
        maxHeight += 10;

        for( i = 0; i < products.length; i++ )
        {
            products[i].setStyle("height",maxHeight);
        }
    }

	this.load = function()
    {
        this.fixProductHeight();
		this.setupProjectDisplay();
        this.setupNewsNavigator();

		this.runProjectDisplay.delay(10000,this);
	}

    this.checkContactForm = function()
    {
        if(
            ( ($("contact_name").value = $("contact_name").value.trim()).length < 2 ) ||
            ( $("contact_name").hasClass("inputinfo") )
        )
        {
            alert("Please enter your name.");
            $("contact_name").focus();
            return false;
        }
        if(
            ( ($("contact_email").value = $("contact_email").value.trim()).length < 5 ) ||
            ( $("contact_email").value.indexOf(".") == -1 ) ||
            ( $("contact_email").value.indexOf("@") == -1 ) ||
            ( $("contact_email").hasClass("inputinfo") )
        )
        {
            alert("Please enter your e-mail address.");
            $("contact_email").focus();
            return false;
        }
        if(
            ( ($("contact_message").value = $("contact_message").value.trim()).length < 8 ) ||
            ( $("contact_message").hasClass("inputinfo") )
        )
        {
            alert("Please enter your message.");
            $("contact_message").focus();
            return false;
        }

        $("contact_send").value = "True";

        return true;
    }
}

var steuma = new Steuma();

window.addEvent("domready",function(){
	steuma.load();
});