/*
Script: rv4_b1.js
	Rammeverk v4 js functionality

License:
	MIT-style license.

Copyright:
	Copyright (c) 2008 - Edda Interaktiv

Thanks to:
	- the mootools community, <http://mootools.net/>
	- Valerio Proietti, <http://mad4milk.net/>
*/
var rv4 = new Hash({
	domready: function() {
		
		//
		// Had to remove all domready functionality, it's too slow when there's advertisement present.
		//
		
	},

/**
 * 
 */
	tablists: function(){
		// let's add a simple accordion for now, and do more tab-stuff later ^^
		var tablists = $$('.tablists');
		var accordions = [];
		tablists.each(function(tablist,i){
			// hide h2's and generate a ul before the tablist
			var h2s = tablist.getElements("h2");
			var uls = tablist.getElements('ul');
			var ul = new Element('ul',{
				'class':'tablistnav'
			});
			h2s.each(function(h2,i){
				h2.set('class','hide');
				new Element('span').set('text',h2.get('text')).inject(new Element('li').inject(ul,'bottom'),'top');
			});
			ul.inject(tablist,'top');
			// add accordions with the ul's as 
			accordions[i] = new Accordion(ul.getElements('li'),uls,{
				opacity:false,
				duration:0,
				onActive: function(toggler, element){
					toggler.addClass("current");
				},
				onBackground: function(toggler,element){
					toggler.removeClass("current");
				}
			});
		});
	},
	
	fixedAd: new Class({
	 
		initialize : function(id,options){
			this.fixed = $(id);
			this.parent = this.fixed.getOffsetParent().getCoordinates();

			this.offset = this.fixed.getCoordinates().top;
			window.addEvent('scroll',this.scrolled.bind(this));
		},
	 
		scrolled : function(){
			var scroll = window.getScroll();
			if (scroll.y > this.offset) {
					if ($('footernav') && (scroll.y + this.fixed.getSize().y) > $('footernav').getCoordinates().top) {
						this.fixed.removeClass('iefixedad');
						this.fixed.setStyles({
							top: $('footernav').getCoordinates().top - this.fixed.getSize().y - this.parent.top - 18 + "px",
							position: "absolute"
						});
					} else {
						if (!Browser.Engine.trident4) {
							this.fixed.setStyles({
								"top": "5px",
								position: "fixed"
							});
						}
						else {
							//this.fixed.setStyle("top", scroll.y-this.parent.top+10+"px");
							//this.fixed.setStyle("top", "expression(eval(document.body.scrollTop)+10)");
							this.fixed.addClass('iefixedad');
						}
					}
			} else {
				this.fixed.removeClass('iefixedad');
				this.fixed.setStyles({
					top: this.offset - this.parent.top + "px",
					position: "absolute"
				});
			}
		}
	})
});



window.addEvent('domready',function(){
	// launch the domready functions :)
	rv4.domready();
});

