/******************************* siemens' new web appearance script *****/
/******************************* Copyright (c) 2007-2008 Siemens AG *****/
/************************************************************************/
/********************************************** module HeaderVisual *****/
/************************************************************************/
/*************************************** author virtual identity AG *****/
/* $LastChangedDate: 2008-02-29 12:33:39 +0100 (Fr, 29 Feb 2008) $ *****/

// swap header visuals

var HeaderVisual = Class.create();

HeaderVisual.initialize = function() {
	if ($("HeaderVisualZone") && $("HeaderTextZone"))	{
		HeaderVisual.node  = $("HeaderVisualZone");
		HeaderVisual.defaultContentNode = $("headerTextZone");

		$A($("toolbar-zone").getElementsByTagName("ul")).findAll(function(elt) {
			return $(elt).hasClassName("js-swap-headervisual");
		}).each(function(elt) {
			$A(elt.getElementsByTagName("li")).each(function(elt) {
				new HeaderVisual($(elt));
			});
		});
	}
}

HeaderVisual.prototype = {
	initialize: function(listItem) {
        if (listItem.id)
        {
		    this.id     = listItem.id;
		    this.source = RESOURCES_PATH + headerVisualImages[this.id];
		    this.loaded = false;
		    this.active = false;

		    this.initBgImage();
		    listItem.observe("mouseover", function() {
			    this.show();
		    }.bindAsEventListener(this));

		    listItem.observe("mouseout", function() {
			    this.hide();
		    }.bindAsEventListener(this));
	    }
	},

	initBgImage: function() {
		this.image  = new Image;

		this.image.onload = function() {
			this.loaded = true;
			if (this.active) {
				this.show();
			}
		}.bindAsEventListener(this);

		this.image.src = this.source;
	    
		this.imageNode = document.createElement("div");
		this.imageNode.className = "swap-image-container";
		this.imageNode.style.backgroundImage = "url(" + this.source + ")";
		
		HeaderVisual.node.appendChild(this.imageNode);
	},
	
	hide: function() {
		this.active = false;
//		HeaderVisual.defaultContentNode.show();
//		$("headertext-" + this.id).removeClassName("active");
		if (this.loaded) {
			this.imageNode.style.display = "none";
		} 
	},

	show: function() {
		this.active = true;
//		HeaderVisual.defaultContentNode.hide();
//		$("headertext-" + this.id).addClassName("active");
		if (this.loaded) {
			this.imageNode.style.display = "block";
		}
	}
}

