jQuery(function( $ ){
	
	$("h1:first,h2:first").css({"padding":"15px 0 10px"});
	$("#newsflash-inner h2").css({"padding":"10px 0 10px"});
	
	Shadowbox.init({
	    // let's skip the automatic setup because we don't have any
	    // properly configured link elements on the page
	    //skipSetup: true
	});
	
	$(".firstlevel:last").find("a").css({"background":"none"});
	$(".firstlevel:first").find("a").css({"padding":"0"});
	
	var subnavcounter = 1;
	$('.subnav-container').each(function(){
		var subnav = $(this).find("ul.subnav");
		subnav.addClass("subnav"+subnavcounter);
		/*var subnavclass = subnav.attr("class");
		var size = subnav.find("li").size();
		if(size>6){
			var $bigList = subnav,
			group = $bigList.find('li:lt(6)').remove();
			while(group.length){
				$('<ul class="'+subnavclass+'"/>').append(group).appendTo($(this)).wrap('<div class="column" style="width: 225px; float: left;"/>');
				group = $bigList.find('li:lt(6)').remove();
			}
			subnav.remove();
		}*/
		subnavcounter++;
	});
	var subnavcounter = 0;
	
/*	//subnavli
	$(".subnavli").live("mouseover",function(){
		$(this).next().toggle();
	}).live("mouseout",function(){
		$(this).next().toggle();
	});*/
	
	$(".subnavli").live("hover",function(){
//		console.log();
		var myspan = $(this).find('span');
		myspan.toggle();
	}, function() { //on hover out...
		var myspan = $(this).find('span');
		myspan.toggle();
	});
	
	$(".csc-sitemap").each(function(){
		var subnav = $(this).find("ul:first");
		var $bigList = subnav,
		group = $bigList.find('li:lt(1)').remove();
		while(group.length){
			if(subnavcounter>0){
				if (subnavcounter == 4 || subnavcounter == 7){
					$('<ul style="clear:both;"/>').append(group).appendTo($(this));
				} else {
					$('<ul/>').append(group).appendTo($(this));
				}
			}
			group = $bigList.find('li:lt(1)').remove();
			subnavcounter++;
		}
		subnav.remove();
	});
	
	// subnavigation mouseover slidedown
	$(".mainnav a").mouseover(function(){
		if($(this).next().html()!=null){
			var classname = $(this).next().find("ul.subnav:first").attr("class").substring(7);
			$("#subnavigation-inner").attr("class",classname);
			var content = $(this).next().html();
			$("#subnavigation-inner").html(content);
			switch(classname){
				case 'subnav1':
					var marginleft = '109px';
					break;
				case 'subnav2':
					var marginleft = '230px';
					break;
				case 'subnav3':
					var marginleft = '351px';
					break;
				case 'subnav4':	
				case 'subnav5':
//					var marginleft = '472px';
					var marginleft = '593px';
					break;
			}
			$("#subnavigation").css({"background":"#f6b14c url('/fileadmin/templates/img/subnavback.gif') "+marginleft+" 0px no-repeat"});
			$("#subnavigation").slideDown();
		}
	});
	
	// subnavigation, sitemap hoverout slideup
	$("#subnavigation, #sitemap").hover(function(){
	}, function() { //on hover out...
		$(this).slideUp();
	});	
	
	// sitemap click slidedown
	$("a.sitemap").click(function(){
		var divOffset = $('#footer').offset().top;
		var smHeight = $("#sitemap").height();
		$("#sitemap").slideDown();
		$('html, body').animate({ scrollTop: divOffset+smHeight }); 
		return false;
	});
	
	$('.scroll-pane').jScrollPane();
	$("#newsflash").fadeIn(1000);
//	$("#newsflash").show("slide", { direction: "right" }, 1000);
	
	$(".faqlist-question").click(function(){
		var dis = $(this).next().css("display");
		$(".faqlist-answer").hide();
		$(".faqlist-item").css({"background":"url(/fileadmin/templates/img/faq_arrow.gif) no-repeat scroll 2px 2px #FFFFFF"});
		if(dis=="none"){
			$(this).parent().css({"background":"url(/fileadmin/templates/img/faq_arrow_act.gif) no-repeat scroll 2px 2px #FFFFFF"});
			$(this).next().show();
		} else {
			$(this).next().hide();
		}
	});
	
	$(".tx-indexedsearch-res").wrap('<div class="tx-indexedsearch-res-outer" />');
	
	$(".news-home-pics div:last").addClass("last");
	
	$("a.elearning-link").click(function(event){
		event.preventDefault();
		var href = $(this).attr("href");
		window.open('/'+href,"NCTb_eLearning_Module","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=960,height=619");
	});
});

window.onload = function() {
    // set up all anchor elements with a "movie" class to work with Shadowbox
    Shadowbox.setup("a.newsflv", {
		width:600,
		height:400
    });
	Shadowbox.setup("a.elearning-lightbox", {
		width:960,
		height:619
    });
	Shadowbox.setup("a.lightbox-link");
};
