﻿/*
----------------------------------------------------------
	Initialize Namespace
----------------------------------------------------------
*/
window.Websajt = { Util: {}, Form: {}, Admin: {}, Effects: {}, Menu: {} };

document.observe("dom:loaded", function () {
    // initially hide all containers for tab content
    var nodes = $('SubMenu').select('li');
    count = 0;
    nodes.each(function (s) {
        if (count == nodes.length - 1) {
            s.addClassName("last");
        }
        count++
    });

    nodes = $('SubMenu').select('.level-2');
    count = 0;
    nodes.each(function (s) {
        if (count == nodes.length - 1) {
            s.addClassName("last");
        }
        count++
    });
});

Websajt.Class = {
	create: function() {
		return function() {
		this.initialize.apply(this, arguments);
		}
	}
};

/*
----------------------------------------------------------
	Milou.Constants
		-Websajt.CustomEvents.MouseOverBox(this)
		-Websajt.CustomEvents.MouseOutBox(this)
		-Websajt.CustomEvents.Search(this)
		-Websajt.CustomEvents.Submit(strButtonID)
		-Websajt.CustomEvents.PreventSubmit()
		-Websajt.CustomEvents.CheckContentHeight()
----------------------------------------------------------
*/

Websajt.CustomEvents = {
	MouseOverBox: function(objElement) {
		$(objElement).addClassName('hover');
	},
	MouseOutBox: function(objElement) {
		$(objElement).removeClassName('hover');
	},
	Search: function(strElement, strUrl) {
		document.location.href = strUrl + '?q=' + $F(strElement);
	},
	Submit: function(e, strButtonID, delay) {
		if (e.keyCode == 13) {
			if (delay != null) {
				setTimeout(function() { $(strButtonID).click() }, delay);
			}
			else
				$(strButtonID).click();
			return false;
		}
	},
	PreventSubmit: function(e, strButtonID) {
		try {
			if (e.keyCode == 13) {
				if (e.target.tagName != "TEXTAREA") {
					e.returnValue = false;
					e.cancel = true;
					e.preventDefault();
					e.stopPropagation();
				}
			}
		}
		catch (exp) { }
	},
	CheckContentHeight: function() {

		if (Object.isElement($('ContainerContentLeft')) && Object.isElement($('ContainerContentMain')) && Object.isElement($('ContainerContentRight'))) {
			var intLeft = $('ContainerContentLeft').getHeight();
			var intMiddle = $('ContainerContentMain').getHeight();
			var intRight = $('ContainerContentRight').getHeight();

			if ((intLeft > intMiddle) && intLeft > intRight)
				$('ContainerContentRight').setStyle({ height: intLeft + 'px' })
			else if ((intMiddle > intLeft) && intMiddle > intRight)
				$('ContainerContentRight').setStyle({ height: intMiddle + 'px' })
		}
	}
};

Websajt.Util.deEncAddr = function(ea) {
    var em = '';
    for (i = 0; i < ea.length; ) {
        var le = '';
        le = ea.charAt(i) + ea.charAt(i + 1);
        em += String.fromCharCode(parseInt(le, 16));
        i += 2;
    }
    return em;
}

Websajt.Util.safeMail = function(ea) {
document.location.href = 'mailto:' + Websajt.Util.deEncAddr(ea);
}
