// Example usage
window.addEvent("domready", function() {
  $$('.ogTrigger').each(function(el){
    var myField = new ogSlideMenu(el);
  });
var el = $('jobscroller');
if (el) new ogSlideContent(el,{cellHeight: 80,cellWidth: 220,visibleCells: 2,loop: true});
		

 if ($("accordion")) {

  $$('#accordion .toggler').each(function(el) { 
    el.addEvent('mouseenter',function(){
     el.setStyle("color", "#FFFFFF");
     myEffect = el.effect('background-color', {duration: 10,transition: Fx.Transitions.linear, wait: true}).start('#ffffff','#9d2727');
    })
    el.addEvent('mouseleave',function(){
     el.setStyle("color", (el.getStyle("font-weight")=="bold" ?  "#4b4b4b" : "#9d2727"));
     myEffect = el.effect('background-color', {duration: 10,transition: Fx.Transitions.linear, wait: true}).start('#9d2727','#ffffff');
    })
  });
 
  var accordion = new Accordion("h3.atStart", "div.atStart", {
   opacity: true,
   alwaysHide: false,
   fixedHeight: false,
   onActive: function(toggler, element){
    toggler.setStyle("color", "#4b4b4b");
    toggler.setStyle("font-weight", "bold");
    toggler.setStyle("background-color", "#FFFFFF");
    toggler.setStyle("background-image", "url(/fileadmin/templates/ks/images/accordian_act.png)");
    $('pictureframe').setStyle("background-image", "url("+toggler.getLast().getProperty('src')+")");
   },
   onBackground: function(toggler, element){
    toggler.setStyle("color", "#9d2727");
    toggler.setStyle("font-weight", "normal");
    toggler.setStyle("background-image", "url(/fileadmin/templates/ks/images/accordian_no.png)");
   }
  }, $("accordion"));
 } 


	if ($("accordion_faq")) {	
		var accordion_faq = new Accordion('h3.atStart', 'div.atStart', {
			opacity: false,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#ff3300');
			},
	
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#222');
			}
		}, $('accordion_faq'));
	}

/*------------------------
  KS FAQ [BEGIN]
------------------------*/
 if ($("og-faq")) {
  $$('#og-faq .toggler').each(function(el) {
    el.addEvent('mouseenter',function(){
    // el.setStyle("color", "#000000");
     //myEffect = el.effect('background-color', {duration: 100,transition: Fx.Transitions.linear, wait: true}).start('#ffffff','#9d2727');
    })
    el.addEvent('mouseleave',function(){
     el.setStyle("color", (el.getStyle("font-weight")=="bold" ?  "#4b4b4b" : "#9d2727"));
     //myEffect = el.effect('background-color', {duration: 100,transition: Fx.Transitions.linear, wait: true}).start('#9d2727','#ffffff');
    })
  });

  var accordion = new Accordion("h3.atStart", "div.atStart", {
   opacity: true,
   display: 9999,
   alwaysHide: true,
   fixedHeight: false,
   onActive: function(toggler, element){
    toggler.setStyle("color", "#4b4b4b");
    toggler.setStyle("font-weight", "bold");
    //toggler.setStyle("background-color", "#FFFFFF");
    toggler.setStyle("background-image", "url(fileadmin/templates/ks/images/faq/faq-act.gif)");
   },
   onBackground: function(toggler, element){
    toggler.setStyle("color", "#9d2727");
    toggler.setStyle("font-weight", "normal");
    toggler.setStyle("background-image", "url(fileadmin/templates/ks/images/faq/faq-no.gif)");
   }
  }, $("og-faq"));
 }
/*------------------------
  KS FAQ [END]
------------------------*/
});

var ogSlideMenu = new Class({
  options: {
    fxDuration: 500,								// Duration of transition
			fxTransition: Fx.Transitions.Quad.easeInOut		// Transition for sliding overlay in/out
		},
		initialize: function(element, options) {
			this.element = element; 	// A tag Element
			this.slidebox = this.element.getNext(); // Slidebox element
			this.setOptions(options);
			this.ogSlide();
		},
		ogSlide: function(){
			if (this.slidebox.className == 'ogSlideBox') {
				this.slidebox.dimensions = this.slidebox.getCoordinates();	// Get and save Dimensions of A tag Element
	
				var slideboxFx = new Fx.Styles(this.slidebox, {duration: this.options.fxDuration, transition: this.options.fxTransition, wait:false});
	
				this.element.fxvars =({
					heightStart: 0,
					heightEnd: this.slidebox.dimensions.height
				});
				this.slidebox.setStyles({
					height: 0
				})
				
				this.element.addEvent("mouseenter", function(){
					slideboxFx.start({
						height: [this.fxvars.heightStart, this.fxvars.heightEnd]
					});
				});
				this.element.addEvent("mouseleave", function(){
					slideboxFx.start({
						height: this.fxvars.heightStart
					});
				});
			}
		}
	});
	ogSlideMenu.implement(new Options);
		
	
Element.extend({
		// $('myEl') -> background-position: 0% 10%
		// $('myEl').getBgPosition('x') <- 0
		// $('myEl').getBgPosition('y') <- 10
		getBgPosition: function(direction) {
			if (!direction.test(/(x|y)/)) return false;
			var current = this.getStyle('backgroundPosition').trim().split(' ');
			current.each(function(pos, i) { current[i] = pos.toInt(); });
			return (direction == 'x') ? current[0] : current[1];
		}
	});

    var ogSlideContent = new Class({
		options: {
			visibleCells: 3,
			cellWidth: 200,
			cellHeight: 150,
			loop: false,
			swapDirection: false,
			vertical: false,
			fxDuration: 500,								// Duration of transition
			fxTransition: Fx.Transitions.Quad.easeOut		// Transition for sliding overlay in/out
		},
		initialize: function(element, options) {
			this.element = element; 	// UL Element
			this.setOptions(options);
			this.ogSlide();
		},
		ogSlide: function(){
			this.element.dimensions = this.element.getCoordinates();
			this.wrapper = new Element('div').setProperty('class', 'ogSlideWrapper').setStyles({
				float: (this.options.vertical ? 'none' : 'left'),
				display: (this.options.vertical ? '' : 'inline'),
				overflow: 'hidden',
				height: ((this.options.visibleCells - 1) * this.options.cellHeight * this.options.vertical) + this.options.cellHeight + (2 * !this.options.vertical),
				width: ((this.options.visibleCells - 1) * this.options.cellWidth * !this.options.vertical) + this.options.cellWidth + (2 * this.options.vertical),
				margin: 0,
				padding: 0
			}).injectAfter(this.element);
			this.element.remove();						// Remove original object
			this.element.injectInside(this.wrapper);	// and place it inside the wrapper object
			
			this.ultag = this.element.getFirst();
			this.litags = this.ultag.getChildren();

			this.litags.each(function(litag,index) {
				litag.setStyles({
					width: this.options.cellWidth,
					height: this.options.cellHeight,
					float: 'left',
					display: 'inline',
					margin: 0,
					padding: 0
				});
				// Add copies of the first visible frames to the end of the UL tag
				if (this.options.loop && index<this.options.visibleCells) {
					litag.clone().injectInside(this.ultag);
				}
			},this);
			if (this.options.loop) this.litags = this.ultag.getChildren();

			this.ultag.setStyles({
				listStyleType: 'none',
				width: ((this.litags.length-1) * this.options.cellWidth * !this.options.vertical) + this.options.cellWidth,
				height: ((this.litags.length-1) * this.options.cellHeight * this.options.vertical) + this.options.cellHeight,
				margin: 0,
				padding: 0,
				borderTop: (this.options.vertical ? 'none' : '1px solid #E0E0E0'),
				borderBottom: (this.options.vertical ? 'none' : '1px solid #E0E0E0'),
				borderRight: (this.options.vertical ? '1px solid #E0E0E0' : 'none'),
				borderLeft: (this.options.vertical ? '1px solid #E0E0E0' : 'none')
			});
		
			this.posMax = this.litags.length - this.options.visibleCells;
			this.posCount = 0;
				
			this.backButton = new Element('div').setProperty('class', 'ogButton').setStyles({
				position: 'relative',
				backgroundImage: (this.options.vertical ? 'url(fileadmin/templates/ks/images/buttonup.png)' : 'url(fileadmin/templates/ks/images/buttonleft.png)'),
				backgroundRepeat: 'no-repeat',
				backgroundAttachment: 'scroll',
				backgroundPosition: '0px 0px',
				float: (this.options.vertical ? 'none' : 'left'),
				display: (this.options.vertical ? '' : 'inline'),
				width: (this.options.vertical ? this.options.cellWidth-5 : 12),
				height: (this.options.vertical ? 12 : this.options.cellHeight-5),
				margin: 0,
				padding: 0,
				cursor: 'pointer'
			}).injectBefore(this.wrapper);
			
			new Element('div').setStyles({
				position: 'absolute',
				backgroundImage: (this.options.vertical ? 'url(fileadmin/templates/ks/images/buttonup.png)' : 'url(fileadmin/templates/ks/images/buttonleft.png)'),
				backgroundRepeat: 'no-repeat',
				backgroundAttachment: 'scroll',
				backgroundPosition: 'bottom right',
				width: 12,
				height: 12,
				marginRight: (this.options.vertical ? -7 : 0),
				marginBottom: (this.options.vertical ? 0 : -7),
				bottom: 0,
				right: 0
			}).injectInside(this.backButton);

			this.backArrow = new Element('div').setProperty('class', 'ogArrow').setStyles({
				position: 'relative',
				backgroundImage: (this.options.vertical ? 'url(fileadmin/templates/ks/images/arrowup.png)' : 'url(fileadmin/templates/ks/images/arrowleft.png)'),
				backgroundRepeat: 'no-repeat',
				backgroundAttachment: 'scroll',
				backgroundPosition: (this.options.vertical ?( this.options.loop || this.options.swapDirection ? 0 : -4) + 'px 0px' : '0px ' + (this.options.loop || this.options.swapDirection ? 0 : -7) + 'px'),
				top: (this.options.vertical ? 4 : parseInt((this.options.cellHeight-12)/2)),
				left: (this.options.vertical ? parseInt((this.options.cellWidth-12)/2) : 4),
				width: (this.options.vertical ? 7 : 4),
				height: (this.options.vertical ? 4 : 7)
			}).injectInside(this.backButton);
			
			this.forwardButton = new Element('div').setProperty('class', 'ogButton').setStyles({
				position: 'relative',
				backgroundImage: (this.options.vertical ? 'url(fileadmin/templates/ks/images/buttondown.png)' : 'url(fileadmin/templates/ks/images/buttonright.png)'),
				backgroundRepeat: 'no-repeat',
				backgroundAttachment: 'scroll',
				backgroundPosition: 'top left',
				float: (this.options.vertical ? 'none' : 'left'),
				display: (this.options.vertical ? '' : 'inline'),
				width: (this.options.vertical ? this.options.cellWidth-5 : 12), /* -7 if no border on UL tag */
				height: (this.options.vertical ? 12 : this.options.cellHeight-5),
				//margin:0, 
				padding: 0,
				cursor: 'pointer'
			}).injectAfter(this.wrapper);
			
			new Element('div').setStyles({
				position: 'absolute',
				backgroundImage: (this.options.vertical ? 'url(fileadmin/templates/ks/images/buttondown.png)' : 'url(fileadmin/templates/ks/images/buttonright.png)'),
				backgroundRepeat: 'no-repeat',
				backgroundAttachment: 'scroll',
				backgroundPosition: 'bottom right',
				width: 12,
				height: 12,
				marginRight: (this.options.vertical ? -7 : 0),
				marginBottom: (this.options.vertical ? 0 : -7),
				bottom: 0,
				right: 0
			}).injectInside(this.forwardButton);

			this.forwardArrow = new Element('div').setProperty('class', 'ogArrow').setStyles({
				position: 'relative',
				backgroundImage: (this.options.vertical ? 'url(fileadmin/templates/ks/images/arrowdown.png)' : 'url(fileadmin/templates/ks/images/arrowright.png)'),
				backgroundRepeat: 'no-repeat',
				backgroundAttachment: 'scroll',
				backgroundPosition: (this.options.vertical ?( this.options.loop || !this.options.swapDirection ? 0 : -7) + 'px 0px' : '0px ' + (this.options.loop || !this.options.swapDirection ? 0 : -4) + 'px'),
				top: (this.options.vertical ? 4 : parseInt((this.options.cellHeight-12)/2)),
				left: (this.options.vertical ? parseInt((this.options.cellWidth-12)/2) : 4),
				width: (this.options.vertical ? 7 : 4),
				height: (this.options.vertical ? 4 : 7)
			}).injectInside(this.forwardButton);
			
			new Element('div').setStyle('clear', 'left').injectAfter(this.forwardButton);

			this.backButton.onclick = this.options.swapDirection ? this.ogScrollForward.bindAsEventListener(this) : this.ogScrollBack.bindAsEventListener(this);
			this.forwardButton.onclick = this.options.swapDirection ? this.ogScrollBack.bindAsEventListener(this) : this.ogScrollForward.bindAsEventListener(this);

		this.forwardButton.addEvent('mouseover',this.ogButtonMouseOver.bindAsEventListener(this));
		this.forwardButton.addEvent('mouseout',this.ogButtonMouseOut.bindAsEventListener(this));
		this.backButton.addEvent('mouseover',this.ogButtonMouseOver.bindAsEventListener(this));
		this.backButton.addEvent('mouseout',this.ogButtonMouseOut.bindAsEventListener(this));

			this.scroll = new Fx.Scroll(this.wrapper, {
				wait: true,
				duration: this.options.fxDuration,
				transition: this.options.fxTransition
			});
		},
		ogButtonMouseOver: function(event) {
			cel = event.target || event.srcElement
			el = cel.getElement('div[class=ogArrow]');
			if (!el) el = cel.getParent().getElement('div[class=ogArrow]');
			el.setStyle('backgroundPosition',(this.options.vertical ? el.getBgPosition('x')+'px ' + '-7px' : '-4px ' + el.getBgPosition('y')+'px'));
		},
		ogButtonMouseOut: function(event) {
			cel = event.target || event.srcElement
			el = cel.getElement('div[class=ogArrow]');
			if (!el) el = cel.getParent().getElement('div[class=ogArrow]');
			el.setStyle('backgroundPosition',(this.options.vertical ? el.getBgPosition('x')+'px ' + '0px' : '0px ' + el.getBgPosition('y')+'px'));
		},
		ogScrollForward: function(){
			if (this.options.loop && this.posCount == this.posMax) {
				this.posCount = 0;
			}	
			if (this.posCount < this.posMax) {
				this.posCount++;
				this.scroll.start([(this.posCount-1) * this.options.cellWidth * !this.options.vertical,(this.posCount-1) * this.options.cellHeight * this.options.vertical], [this.posCount * this.options.cellWidth * !this.options.vertical,this.posCount * this.options.cellHeight * this.options.vertical]);
			}
			this.forwardArrow.setStyles({
				backgroundPosition: (this.options.vertical ? (this.posCount < this.posMax || this.options.loop ?  0 : -4) + 'px ' + this.forwardArrow.getBgPosition('y') + 'px' : this.forwardArrow.getBgPosition('x') + 'px ' + (this.posCount < this.posMax || this.options.loop ?  0 : -7) + 'px')
			});
			this.backArrow.setStyles({
//				backgroundPosition: this.backArrow.getBgPosition('x') + 'px ' + ((this.posCount > 0 || this.options.loop)?  0 : -31) + 'px'
				backgroundPosition: (this.options.vertical ? (this.posCount > 0 || this.options.loop ?  0 : -7) + 'px ' + this.backArrow.getBgPosition('y') + 'px' : this.backArrow.getBgPosition('x') + 'px ' + (this.posCount > 0 || this.options.loop ?  0 : -4) + 'px')

			});
		},
		ogScrollBack: function(){
			if (this.options.loop && this.posCount == 0) {
				this.posCount = this.posMax;
			}
			if (this.posCount > 0) {
				this.posCount--;
				this.scroll.start([(this.posCount+1) * this.options.cellWidth * !this.options.vertical,(this.posCount+1) * this.options.cellHeight * this.options.vertical], [this.posCount * this.options.cellWidth * !this.options.vertical,this.posCount * this.options.cellHeight * this.options.vertical]);
			}
			this.forwardArrow.setStyles({
			//	backgroundPosition: this.forwardArrow.getBgPosition('x') + 'px ' + ((this.posCount < this.posMax || this.options.loop)?  0 : -31) + 'px'
				backgroundPosition: (this.options.vertical ? (this.posCount < this.posMax || this.options.loop ?  0 : -4) + 'px ' + this.forwardArrow.getBgPosition('y') + 'px' : this.forwardArrow.getBgPosition('x') + 'px ' + (this.posCount < this.posMax || this.options.loop ?  0 : -7) + 'px')
			});
			this.backArrow.setStyles({
				//backgroundPosition: this.backArrow.getBgPosition('x') + 'px ' + ((this.posCount > 0 || this.options.loop)?  0 : -31) + 'px'
				backgroundPosition: (this.options.vertical ? (this.posCount > 0 || this.options.loop ?  0 : -4) + 'px ' + this.backArrow.getBgPosition('y') + 'px' : this.backArrow.getBgPosition('x') + 'px ' + (this.posCount > 0 || this.options.loop ?  0 : -7) + 'px')
			});
		}
	});
	ogSlideContent.implement(new Options);		

/* ------------------------------------------
   giver rækker i tabeller baggrundsfarve 
   hvis class=widthBackground (css)
------------------------------------------ */
window.onload = oddevenrows;

function oddevenrows() {
  var table = document.getElementsByTagName('table');
  var tableCount = table.length;
  for (var i=0;i<tableCount;i++) {
    var tr = table[i].getElementsByTagName('tr');
    var trCount = tr.length;
    for (var t=0;t<trCount;t++) {
      tr[t].className = (t%2) ? 'even' : 'odd';
    }
  }
}

/* ------------------------------------------
   Benyttes til søgeboksen - er pt. slået fra
------------------------------------------ */
function addCheckboxValue(form) {
	var swordextra = '';
    for (var i=1;i<6;i++) {
		var el = form.elements['indexedsearchboxcheckbox['+i+']'];
		//alert(el)
		if (el.checked) {
			swordextra+=' '+el.value.replace(/^\s+|\s+$/g,"");
		}
	}
	var el = form.elements['tx_indexedsearch[sword]'];
	el.value = el.value + swordextra;
	return true;
}
