/*****************
/*****************
**
** Projekt: pbb
**
/*****************
******************/



/** Config **********************************************************************************************/

var systemImgPath = "fileadmin/templates/SYSTEM/images/";

var bgFileMetanav = "pbb_bg-meta-flyout";
var bgFileNav = "pbb_bg-nav-flyout";
var bgFileMoreContact = "pbb_bg-contact-flyout";

var overSpeed = 100;
var outSpeed = 100;

var overlayIn = 200;
var overlayOut = 100;


var overSpeedLinks = 100;
var outSpeedLinks = 100;

var colors = {"default":"#CCCCCC","over":"#96D115","background-over":"#151715","background-default":"#3e413e","background-header":"#2D322D"};

/********************************************************************************************************/

//jQuery.noConflict();


jQuery.easing.def = "easeInCubic";


if (!flashPath) {
	var flashPath;
}
if (!flashHeight) {
	var flashHeight = 156;
}


var ie6 = false;
var ie7 = false;
var ie = jQuery.browser.msie;
if (ie) {
	if (jQuery.browser.version == 6.0) {
		ie6 = true;
	}
	if (jQuery.browser.version == 7.0) {
		ie7 = true;
	}
}





/**
	*
	* Default Manipulation
	*
	*/


function setDefaults() {

	$("#navigation ul li").last().addClass("last");
	

	$("#metanavigation ul ul").each(function() {
		$(this).find("li").last().addClass("last");
	});

	$("#sub-header ul").not("ul ul").each(function() {
		$(this).find("li").last().addClass("last");
	});
	$("#sub-header ul ul").each(function() {
		$(this).find("li").last().addClass("last").end().first().addClass("first");
	});

	$("#footer ul li").first().addClass("first").end().last().addClass("last");
	

	$("div#metanavigation ul li ul").css("display","none");
//	$("div#metanavigation ul").removeClass("hover").find("li").removeClass("first");
	$("div#overlay").css("display","none");
	$("div#sub-header ul").css("display","none");
	
	var contactMore = $("ul.contact-more");
	
	if (contactMore.length) {
		$("ul li",contactMore).last().addClass("last").end().first().addClass("first");
	}

	
}


/**
	*
	* mainMenu
	* @param obj jQuery Object or jQuery String
	* @param flie String filename
	*
	*/

function mainMenu(obj,file){


	if (!$(obj).length) return;

	obj.find("li").not("li li").mouseover(function() {
		if (!ie6) {
//			$(this).parent().find("li").css("background-image","none");
		}	
//		$(this).find("ul").delay(100).fadeIn(overSpeed,function() {	

		$(this).find("ul").delay(400).fadeIn(overSpeed,function() {	

			if (!ie6) {
				$(this).find("li").css("background-image","url("+systemImgPath+file+".png)");
				$(this).find("li.first").css("background-image","url("+systemImgPath+file+"-first.png)");
				$(this).find("li.last").css("background-image","url("+systemImgPath+file+"-last.png)");
			}
		});
	});
	obj.find("li").not("li li").mouseleave(function() {
		if (!ie6) {
			$(this).find("li").css("background-image","none");
		}
		obj.find("ul").stop(true,true).hide();
	});

/*
	obj.find("li").not("li li").hover(function() {
		$(this).find("ul").show();
	},
	function() { 
		$(this).find("ul").hide();
	});
*/

/*

	obj.children("li").click(function(event) {
//		event.preventDefault();
		$(this).find("ul").addClass("clicked");
		obj.find("ul").fadeOut(400).parent().find('ul.clicked:hidden').fadeIn(400);
		obj.removeClass("clicked");
	});
*/
}

/**
	*
	*  metaMenu
	*
	*/

function modifyMetaMenu() {
	
	if (ie6 || ie7) {
		var zIndexNumber = 1000;
		$('div#sub-header ul li ').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
		return;
	}
	
	var obj = $("#metanavigation ul li a").not("li li a");
	$(obj).each(function() {
		var txt = $(this).html();
		$(this).parent().find("ul").prepend('<li class="first"><a href="'+$(this).attr("href")+'">'+$(this).html()+'</a></li>').css("top",-16);
	}) 
	
}



/**
	*
	*  mainMenu
	*
	*/

function modifyMainMenu() {
	
	$("#navigation ul li a").mouseenter(function(){
		if (flashPath) $("#presenter").css("display","none");
		var myItem = this;
		$("div#sub-header > ul").css("display","none").eq($(myItem).parent().index()).fadeIn(overSpeed);
		var tmp = $("div#sub-header > ul").eq( $(myItem).parent().index() );
		//console.log( $( "li", tmp ).length );
		if( $( "li", tmp ).length > 0 ) {
			$("#sub-header #overlay").fadeIn(overlayIn,function(){
				if (ie) $(this).css("filter","alpha(opacity=80)");
			});			
		}
	});
	$("#wrapper").mouseleave(function(){
		if (flashPath) $("#presenter").css("display","block");
		$("#sub-header #overlay").fadeOut(overlayOut);
		$("div#sub-header > ul").fadeOut(overSpeed);
	});
}


/**
	*
	* jQuery adaption of swfObject 
	*
	*/

function swfObject() {
	if (flashPath) {
		flashBG = $("#presenter img");
		$("#sub-header").prepend('<div id="flash-bg"></div>');
		$("#flash-bg").prepend(flashBG);
		$('#flash').flash({	
			'src':flashPath,
			'width':'959',
			'height': flashHeight,
			'wmode' : 'transparent',
			'allowfullscreen':'false',
			'allowscriptaccess':'always',
			'version':'9.0.24'
		});
	}
}


/**
	*
	* function changeSeachButton
	* 
	*
	*/
	
function changeSearchButton() {
	var obj = $("#search #search-button");
	var src = obj.attr("src");
	var ext = src.slice(-4);
	var srcOver = src.slice(0,-4) + "_over" + ext;
	$(obj).hover(function() {
		$(this).attr("src",srcOver);
	},function() {
		$(this).attr("src",src);
	});
}

/**
	*
	* function clearSearchInput
	* 
	*
	*/

function clearSearchInput() {
	$('#search #search-input').focus(function() {
		$(this).attr("value","");
	});
}

/**
	*
	* function changeLinkColor
	*
	* @param obj jQuery Object or jQuery String
	* @param over String (style)
	* @param out String (style)
	*
	*/


function changeLinkColor(obj,over,out) {
	$(obj).bind("mouseenter",function() {
	$(this).stop().animate(over, overSpeedLinks);
	});
	$(obj).bind("mouseleave",function() {
		$(this).stop().animate(out, outSpeedLinks);
	});
}


function markSubmenu(obj,over,out) {
	$(obj).bind("mouseenter",function() {
		$(this).parent().parent().parent().find("a").eq(0).addClass("dyn-current");
																	
	});
	$(obj).bind("mouseleave",function() {
		$(this).parent().parent().parent().find("a").eq(0).removeClass("dyn-current");
	});
}

function markMainmenu(obj,over,out) {
	$(obj).bind("mouseenter",function() {
		$(obj).removeClass("dyn-current");
		$(this).addClass("dyn-current");
																	
	});
	$("#wrapper").bind("mouseleave",function() {
		$(obj).removeClass("dyn-current");
	});
}



/**
	*
	* function modalDialog
	*
	* for modal dialog overlay
	*
*/

function modalDialog() {
	var overlay = $("#dialog-overlay");

	if(!$(overlay).length) return;
	resizeOverlay(overlay);
	
	var target = $("#modal-dialog");
	
	if(!$(target).length) return;
	
	var url = target.attr("title");
	
	target.hide();
	target.load(url + " #ajax-content > *",function(){
		target.fadeIn("slow",function(){
			resizeOverlay(overlay);
		});
	});

	
	
}

function resizeOverlay(overlay) {
	if(!$(overlay).length) return;
	overlay.css("height" , $(document).height());
	$("#dialog-wrapper").css("height" , $(document).height());
}


$(window).load(function() {

	resizeOverlay($("#dialog-overlay"));
//	modalDialog();

});
	


jQuery(document).ready(function(){	

	var flashBG;

	// Metamenue
	var metaOver = {color:colors["over"],backgroundColor:colors["background-over"]};
	var metaOut = {color:colors["default"],backgroundColor:colors["background-default"]};
	changeLinkColor($("div#metanavigation ul li li a").not(".current"),metaOver,metaOut);
	var contactNav = $("ul.contact-more li li a");
	if (contactNav.length)	changeLinkColor(contactNav.not(".current"),metaOver,metaOut);


	// 1. Ebene
	var mainOver = {color:colors["over"],backgroundColor:colors["background-over"]};
	var mainOut = {color:colors["default"],backgroundColor:colors["background-header"]};
//	changeLinkColor($("div#navigation li a").not("div#wrapper li li a, .current"),mainOver,mainOut);
	markMainmenu($("div#navigation li a"),mainOver,mainOut);


	// 3. Ebene
	var subOver = {color:colors["over"],backgroundColor:colors["background-over"]};
	var subOut = {color:colors["default"],backgroundColor:colors["background-default"]};
	changeLinkColor($("div#wrapper li li a").not(".current"),subOver,subOut);
	markSubmenu($("div#wrapper li li a").not(".current"),subOver,subOut);

	setDefaults();
	modifyMetaMenu();
	modifyMainMenu();
	
	changeSearchButton();
	clearSearchInput();
	
	mainMenu($("#metanavigation ul"),bgFileMetanav);
	mainMenu($("#sub-header ul"),bgFileNav);
	mainMenu($("ul.contact-more"),bgFileMoreContact);


	swfObject();
	
	$("ul.contact-more li a:first").click( function(){return false;} );
	$("#col-1-2 table, #col-1 table").each( function(){
		if( $( "thead", this ).length == 0 ) {
			$( "tr:first-child td p", this ).attr('style', 'border: none;');
		}
	});
});


