if (window.addEvent) { 
    window.addEvent('load',function(){
        fitColHeight();
        if (document.getElementById('newscontainer-hp')) {
            fitBoxHeight();
        }
    })
}

function fitColHeight() {
    var cols = $$('#col1','#col1-content','#col2','#col2-content','#col3','#col3-content');
    var height = 0;
    cols.each(function(col){
        var el = $(col);
        height = Math.max(height, el.clientHeight, el.offsetHeight);
    });
    if (!height){
        return;
    }
    cols.each(function(col){
        //alert(col.get('id')+height);
        var h, id = col.get('id');
        if (id == 'col3') return;
        if (['col1','col2'].contains(id)){
            h = (height+15)+'px';
        }
        else {
            h = (height)+'px';
        }
        //alert(col.get('id')+' '+h);
        col.setStyle('height',h);
        
    });
    //cols.setStyle('height',height+'px');
    return;
    var col1 = document.getElementById('col1');
    var col1_content = document.getElementById('col1-content');
    var col1_h = col1.offsetHeight;

    var col2 = document.getElementById('col2');
    var col2_content = document.getElementById('col2-content');
    var col2_h = col2.offsetHeight;

    var col3 = document.getElementById('col3');
    var col3_content = document.getElementById('col3-content');
    var col3_h = col3.offsetHeight;

    if (col3_h <= col2_h) { 
        col3_h = '500';

    }
    col1.style.height = 'auto';
    col1.style.height = (col3_h) + 'px';            
    col1_content.style.height = (col3_h - 15) + 'px';            
       
    col2.style.height = 'auto';
    col2.style.height = (col3_h) + 'px';
    col2_content.style.height = (col3_h - 15) + 'px';
    
    col3.style.height = 'auto';
    col3.style.height = (col3_h) + 'px';
    col3_content.style.height = (col3_h - 15) + 'px';
}

function fitBoxHeight() {
    var leftbox = document.getElementById('box-left');
    var leftbox_h = leftbox.offsetHeight;
    
    var rightbox = document.getElementById('box-right');
    var rightbox_h = rightbox.offsetHeight;
    
    var fitheight = Math.max(rightbox_h,leftbox_h);

    leftbox.style.height = 'auto';
    leftbox.style.height = fitheight + 'px';
    
    rightbox.style.height = 'auto';
    rightbox.style.height = fitheight + 'px';
}

function quick(url) {
    document.quickfinder_form.action = url.value;
    document.quickfinder_form.submit();
}

function checkValue(item, command) {
    switch (command) {
        case 'focus':
            if (item.value == 'Passwort') {
                replaceInput(item,'password','',1);
            }
            break;
        case 'blur':
            if (item.value == '') {
                replaceInput(item,'text','Passwort',0)
            }
            break;
    }
}

function replaceInput(oldpass,type,value,focus){
    var newpass=document.createElement('input');
    newpass.setAttribute('type',type);
    newpass.setAttribute('name',oldpass.getAttribute('name'));
    newpass.setAttribute('id',oldpass.getAttribute('id'));
    newpass.setAttribute('onfocus',oldpass.getAttribute('onfocus'));
    newpass.setAttribute('onblur',oldpass.getAttribute('onblur'));
    newpass.setAttribute('value',value);
    oldpass.parentNode.replaceChild(newpass,oldpass);
    if (focus == 1) newpass.focus();
}

//Menü

// Also known as IE fix
var TridentFix = new Class({
	tridentFix: function(item){
		item.addEvents({
			'mouseover':function(){
				this.addClass('iehover');
			},
			'mouseout':function(){
				this.removeClass('iehover');
			}
		});
	}
});


var DropMenu = new Class({
	Implements: [Options,TridentFix],
	/* 
		don't know about options yet
		but set it up anyways just in case 
	*/
	options: {
		mode: 'horizontal'
	},
	menu: null,
	initialize: function(menu,options){
		if(options) this.setOptions(options);
	
		this.menu = $(menu);
		
		// grab all of the menus children - LI's in this case
		var children = this.menu.getChildren();
		
		// loop through children
		children.each(function(item,index){
			// declare some variables 
			var fChild, list;
			
			/* 
				fChild = first child - which should be an A tag
				list = submenu UL
			*/
			fChild = item.getFirst();
			list = fChild.getNext('ul');
			
			// check if IE, if so apply fix
			if(Browser.Engine.trident) this.tridentFix(item);
			
			// if there is a sub menu UL
			if(list){
				item.mel = list; // pel = parent element
				list.pel = item; // mel = menu element
				new SubMenu(list); // hook up the subMenu
			}
		},this); // binding loop to this object for trident fix

	}	
});



var SubMenu = new Class({
	Implements: [Options,TridentFix],
	/* 
		don't know about options yet
		but set it up anyways just in case 
	*/
	options: {
		mode: 'vertical'
	},
	menu: null, // storage for menu object
	depth: 0, // storage for current menu depth
	initialize: function(el,depth,options){
		if(options) this.setOptions(options); // set options
		if(depth) this.depth = depth;// set depth
		this.menu = el; //attach menu to object
		
		if(this.depth == 0)	this.menu.addClass('submenu'); // class for first level
		if(this.depth >= 1)	this.menu.addClass('sub_submenu'); // class for deeper levels - in case :P
		
		this.menu.fade('hide'); // set menu to hid

		/*
			hook up menu's parent with event
			to trigger menu
		*/
		this.menu.pel.addEvents(this.parentEvents); 
		
		// get menu's child elements
		var children = this.menu.getChildren();
			
		// loop through children
		children.each(function(item,index){
			// declare some variables 
			var fChild, list;
			
			/* 
				fChild = first child - which should be an A tag
				list = submenu UL
			*/
			fChild = item.getFirst();
			list = fChild.getNext('ul');
			
			// check if IE, if so apply fix
			if(Browser.Engine.trident) this.tridentFix(item);
			
			// if the menu item has a sub_submenu
			if(list){
				/*
					create marker for menu item
					that has a sub_submenu
					this is to show persistence and 
					where you are in the menu tree
				*/
				var count = new Element('span').set('html','\&raquo;').addClass('counter');
				
				item.adopt(count); // stuff it inside li
				count.fade('hide'); // hide it

				item.mel = list; // mel = menu element
				item.count = count; // attach count accessor to menu item
				list.pel = item; // pel = parent element
				
				// create new subMenu with depth incremented
				new SubMenu(list,this.depth+1);
			}
		},this); //bound to this for trident fix
	},
	// menu parent mouse events
	parentEvents: {
		'mouseover': function(){
			/*
				if it has a count accesor
				then fade it in 
			*/
			if(this.count) this.count.fade('in');
			
			// fade in menu
			this.mel.fade('in');		
		},
		'mouseout': function(){
			/*
				if it has a count accesor
				then fade it out 
			*/
			if(this.count) this.count.fade('out');
			
			// fade out menu
			this.mel.fade('out');
		}
	}
});

Fx.Elements = new Class({

    Extends: Fx.CSS,

    initialize: function(elements, options){
        this.elements = this.subject = $$(elements);
        this.parent(options);
    },

    compute: function(from, to, delta){
        var now = {};
        for (var i in from){
            var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
            for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
        }
        return now;
    },

    set: function(now){
        for (var i in now){
            var iNow = now[i];
            for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
        }
        return this;
    },

    start: function(obj){
        if (!this.check(arguments.callee, obj)) return this;
        var from = {}, to = {};
        for (var i in obj){
            var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};
            for (var p in iProps){
                var parsed = this.prepare(this.elements[i], p, iProps[p]);
                iFrom[p] = parsed.from;
                iTo[p] = parsed.to;
            }
        }
        return this.parent(from, to);
    }

});

