$(document).ready(function(){ 
	//Sitespecific javascript here
	//Greybox closebox
$(".greybox").click(function(){
			$("#GB_window").css("background-color","#aaaaaa").prepend('<span class="closeMe">St&auml;ng</span>');
			$(".closeMe").click(GB_hide);
			});
	//Searchbox clear and fill
	function input_values()
	{	
		var inputBox = $('#newsletter input, #search input');
	
		
		inputBox.focus(function(){
			if ($(this).val() != "") {
				
				var theValue = $(this).val();
				$(this).attr('temp', theValue)
				$(this).val('');
			};
		
		});
		inputBox.blur(function(){
			if ($(this).val() == "") {
				var theValue = $(this).attr('temp');
				$(this).val(theValue);
			};
			
		});
	}
	input_values();
	
	//Even and odd rows in tables
	/* if Environment is NOT Editor */
		$("table tr").mouseover(function() {
			$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");
		});
		$("table tr:nth-child(even), table tr td:nth-child(even)").addClass("even");
		$("table tr:nth-child(odd), table tr td:nth-child(odd)").addClass("odd");
		$("table tr:first-child").removeClass('even').addClass("th");
		$('table tr td:first').addClass('first');
		$('table tr td:last').addClass('last');
		
    //List even odd and first and last list
    $('ul li:nth-child(even)').addClass('even');
    $('ul li:nth-child(odd)').addClass('odd');
    $('ul li:first-child').addClass('first');
    $('ul li:last-child').addClass('last');
		
		//Show links with flowplayer as embedded media
		if ($('p > a').attr('title') == 'flowplayer') {
			$('a[title=flowplayer]').jmedia(
			{version:"6,0"},
			{width:"630", 
			height:"355", 
			autoplay: true,
			maintainaspect:"true"});
		};


	
	/*Accordion menu*/
	//Hide submenus
	$('#sub_nav li ul').hide();
	//If menu option is current, show sub menu
	if ($('#sub_nav li:first-child').hasClass('current'))
		{
			$('#sub_nav ul:first-child > li > ul').slideToggle('slow');
		};
	//When clicking the top level, show submenu, but not sub sub menus
	$('#sub_nav ul:first-child > li > a').click(function() {
		
			$(this).parent().toggleClass('current');
		
		$(this).next().slideToggle('slow');
		return false;
	});

function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}


	
	if($(".newsticker-jcarousellite ul li")){
	$(".newsticker-jcarousellite").jCarouselLite({  
		vertical: true,  
		visible: 8,
		auto:500,           
		speed:2000  
    }); 
}
    
    if($("#work_search")){
	    $("#country").change(function(){
	    	var pageid = $('#pageid').val();
	    	var action = "/CM.php?PageID="+pageid+"&lan="+$(this).val();
	    	$("#work_search").attr("action", action); 
	    	$("#work_search").submit();
		});
	}
	
	if($("#work_content_search")){
		$("#country").change(function(){
	    	var pageid = $('#pageid').val();
	    	var action = "/CM.php?PageID="+pageid+"&lan="+$(this).val();
	    	$("#work_content_search").attr("action", action); 
	    	$("#work_content_search").submit();
		});
	}
	
	if($("#country_form")){
		$("#country").change(function(){
	    	var pageid = $('#pageid').val();
	    	var action = "/CM.php?PageID="+pageid+"&lan="+$(this).val();
	    	$("#country_form").attr("action", action); 
	    	$("#country_form").submit();
		});
	}
	
	if($("#office_form")){
		$("#office").change(function(){
	    	var page = $('#office').val();
	    	var action = page;
	    	$("#office_form").attr("action", action); 
	    	$("#office_form").submit();
		});
	}

});
