jQuery(document).ready(function(){
  jQuery('#load').ajaxStart(function(){ jQuery(this).show(); }).ajaxStop (function(){ jQuery(this).fadeOut(500); });
  // jQuery('.boxy a').boxy({center: false});
  jQuery('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8, scrollbarMargin: 20, wheelSpeed: 50, reinitialiseOnImageLoad: true});
  jQuery('a[rel*=facebox]').facebox() 
});

var sub = [], i = 0, acc = [1,0,0,0,0,0,0,0,0,0], acc = [];

window.addEvent('domready', function () {
		
	
	// set the colors of the borders in the menu
	var firstpink = $('menu').getElement('ul > li:nth-child(4n+1) > a');
	var secondgreen = $('menu').getElement('ul li:nth-child(4n+2) > a');
	var thirdblue = $('menu').getElement('ul > li:nth-child(4n+3) > a');
	var fourthyellow = $('menu').getElement('ul > li:nth-child(4n+4) > a');
	
	var fi = new Fx.Tween(firstpink);
	fi.set('border-color', 'rgb(255, 124, 200)');
	var se = new Fx.Tween(secondgreen);
	se.set('border-color', 'rgb(0, 245, 0)');
	var th = new Fx.Tween(thirdblue);
	th.set('border-color', 'rgb(124, 222, 255)');
	var fo = new Fx.Tween(fourthyellow);
	fo.set('border-color', 'rgb(255, 225, 0)');
	// end of setting colors
	
	// add menu toggling
	var pages = ['om-forsbergs', 'utbildningar', 'studenter'], j = 0, result = null;
	for (j = 0; j < pages.length; j++) {
		result = window.location.pathname.match(pages[j]);
		if (result !== null && result.length === 1)
			break;
	}
	$$('#menu > ul > li.page_item').each(function (element, key) {
		element.addEvents({
			'mouseover': function (event) {
				$(this).addClass('menu_hover');
			},
			'mouseout': function (event) {
				$(this).removeClass('menu_hover');
			}
		});
	});
	$$('#menu > ul > li > ul').each(function (element, key) {
		sub[key] = new Fx.Slide(element);
		/* uncomment this to remove the animation
		if (key === j)
			$(element).setStyle('display', 'block');
		else*/
			if (key !== j) {
				sub[key].slideOut().chain(function () {
					$(element).setStyle('display', 'block');
				});
			} else {
				$(element).setStyle('display', 'block');
			}
	});
	$$('#menu > ul > li:nth-child(4n+2) > a').addEvent('click', toggleSub0);
	$$('#menu > ul > li:nth-child(4n+3) > a').addEvent('click', toggleSub1);
	$$('#menu > ul > li:nth-child(4n+4) > a').addEvent('click', toggleSub2);
	// end of adding menu toggling
	
	// accordion for the "Aktuellt"-page
/* TOGGLER
	$$('.acc_element').each(function (element, key) {
		acc[key] = new Fx.Slide(element);
		if (key != 0)
			acc[key].slideOut();
	}, this);
	$$('.acc_toggler').each(function (element, key) {
		if (key == 0)
			element.addClass('active');
		element.addEvents({
			'click': function (event) {
				event.stop();
				$(this).toggleClass('active');
				acc[key].toggle();
			},
			'mouseover': function (event) {
				if (!$(this).hasClass('active'))
					$(this).getElement('a').setStyle('text-decoration', 'underline');
			},
			'mouseout': function (event) {
				if (!$(this).hasClass('active'))
					$(this).getElement('a').setStyle('text-decoration', 'none');
			}
		});
	});
*/
	/* BEHÖVS EJ
	var myAccordion = new Accordion($$('.acc_toggler'), $$('.acc_element'), {
		onActive: function (toggler, element) {
			toggler.getElement('h3 span.text').setStyle('text-decoration', 'underline');
		},
		onBackground: function (toggler, element) {
			toggler.getElement('h3 span.text').setStyle('text-decoration', 'none');
		},
		opacity: false,
		alwaysHide: false
	});*/
	/* TOGGLER $$('.acc_toggler').setStyle('cursor', 'pointer'); */
	// end accordion
});

function toggleSub0(event) {
	event.preventDefault();
	sub[0].toggle();
	$(this).blur();
}
function toggleSub1(event) {
	event.preventDefault();
	sub[1].toggle();
	$(this).blur();
}
function toggleSub2(event) {
	event.preventDefault();
	sub[2].toggle();
	$(this).blur();
}