/**
* Setting .mac class on bodytag if on mac
* - We can then use the .mac selector in CSS to make speciel mac exceptions...
* 
* @param none
* @return Void
*/
function prepare_for_mac()
{
	if(navigator.platform.indexOf("Mac") != -1 || navigator.userAgent.indexOf("Safari") != -1)
	{
		document.body.className = ( navigator.userAgent.indexOf("Safari") != -1 ? 'mac safari' : 'mac firefox' );
	}
}

function toggle_list(list_id)
{
	var shown 				= getElementsByClassName('content shown','div')[0];
	var h2_shown 			= getElementsByClassName('h2 active','h2')[0];
	var list_el				= document.getElementById(list_id);
	var h2_el				= getElementsByClassName('h2','h2',list_el)[0];
	var cont_el				= getElementsByClassName('content','div',list_el)[0];

	shown.className			= 'content hidden';
	h2_shown.className 		= 'h2 inactive';
	h2_el.className			= ( h2_el.className	== 'h2 inactive' ? 'h2 active' : 'h2 inactive' );
	cont_el.className		= ( cont_el.className == 'content shown' ? 'content hidden' : 'content shown' );
	
}
function tween_header_image(num)
{
	var arr_image	= getElementsByClassName('image','div',$('header'));
	var total		= arr_image.length;
	var num			= ( num >= total || !num ? 0 : num ); // Find the next or start over
	var opacity		= ( arr_image[num].className == 'image imhidden' ? 0.99 : 0 ); // Since IE doesn't understand opacity, we use a dummy class

	JSTweener.addTween(arr_image[num].style,
	{
		time: 0.7,
		transition: 'linear',
		opacity: opacity,
		onUpdate: function()
		{
			// Make it work in IE
			if(document.all)
			{
				arr_image[num].style.filter='alpha(opacity='+Math.round(this.target.opacity*100)+')';
			}
		},
		onComplete: function()
		{
			// Let it stand for a while if we have just shown it (opacity is the value before the tween)
			if(opacity >= 0.99)
			{
				arr_image[num].style.opacity	= 1;
				if(document.all)
				{
					arr_image[num].style.filter='alpha(opacity=100)';
				}
				arr_image[num].className		= 'image imvisible';
				setTimeout(function(){tween_header_image(num); },3500);
			}
			else // show the next image immediately
			{
				arr_image[num].className	= 'image imhidden';
				num++;
				tween_header_image(num);
			}
		}
	});
}
function hover_menu()
{
	var arr_menu	= jQuery('#left li');
	jQuery('#left li.inactive, #mid li.inactive, #right li.inactive, #frontpage .box li.inactive').hover(
			function()
			{
				jQuery(this).removeClass('inactive');
				jQuery(this).addClass('active');
			},
			function ()
			{
				jQuery(this).addClass('inactive');
				jQuery(this).removeClass('active');
			});
}
/*
function init_tween_news()
{
	setTimeout(function() { tween_news(0); },1000);
}
function tween_news(num)
{
	var arr_news	= jQuery('#news .item');
	var total		= arr_news.length;
	var num			= ( num >= total || !num ? 0 : num ); // Find the next or start over

	arr_news[num].onmouseover	= function()
	{
		//JSTweener;
	}

	JSTweener.addTween(arr_news[num].style,
	{
		time: 8,
		transition: 'linear',
		left: (-1 - arr_news[num].offsetWidth), // offsceen
		suffix: {
			left: 'px'
		},
		onComplete: function()
		{
			arr_news[num].style.left	= '801px';
			num++;
			tween_news(num);
		}
	});
}
*/
var intervalID;

function init_move_news(num)
{
	var arr_news	= getElementsByClassName('item','div',$('news'));
	var total		= arr_news.length;
	var num			= ( num >= total || !num ? 0 : num ); // Find the next or start over
	intervalID		= setInterval(function() { move_news(arr_news[num].id,num); },50);
	arr_news[num].onmouseover	= function() { clearInterval(intervalID); }
	arr_news[num].onmouseout	= function() { intervalID = setInterval(function() { move_news(arr_news[num].id,num); },50); }
}

function move_news(el_id,num)
{
	if($(el_id))
	{
		var cur_pos	= parseInt($(el_id).style.left);
		var new_pos	= cur_pos - 2;
		if(new_pos < (0 - $(el_id).offsetWidth) )
		{
			clearInterval(intervalID);
			$(el_id).style.left	= '801px';
			init_move_news(num+1);
		}
		else
		{
			$(el_id).style.left	= new_pos +'px';
			//setTimeout(function(){ move_news(el_id,num) },10);
		}
	}
}

jQuery(document).ready(function ()
{
	jQuery('#page #right .kursus').each(
	function()
	{
		if(this.className != 'active sIFR-replaced')
		{
			jQuery(this).click(function() {
				if (jQuery(this).parent().find('.kurser').css('display') == 'block')
				{
					jQuery(this).parent().find('.kurser').css('display','none');
				}
				else
				{
					jQuery(this).parent().find('.kurser').css('display','block')
				}
			});
		}
	});
});

// Add load events
jQuery(document).ready(prepare_for_mac);
jQuery(document).ready(hover_menu);
