// JavaScript Document


function get_lexikon(){
	 jQuery('#dynamic_lexikon').slideUp();
	 jQuery.ajax({
		 type: "POST",
		 url: "http://www.wortbildton.de/callback.php",
		 data: "",
		 success: function(msg){
			 jQuery('#dynamic_lexikon').html(msg).slideDown();
		 }
  });
}

jQuery.fn.fadeToggle = function(s, fn){
	return (this.is(":visible"))
			? this.fadeOut(s, fn)
			: this.fadeIn(s, fn);
 };


$(document).ready(function()
{	

	// Accordion erstellen
	
	$('.accordion').accordion({
			header: "h3"
	});

	$('.accordion .slider').wbtslider({
		 slideshow:true,
		 width:533,
		 sleep: 3000
	});
	
	var last_subnav = '';
	var curr_subnav = '';
	var last_link = '';
	
	$(".subnavRun").click(function () {
			if(last_subnav.length > 0 && last_subnav.attr('rel') != $(this).attr('rel')){
				$('#'+last_subnav.attr('rel')).slideUp("medium");
			}else if(last_subnav.length > 0 && last_subnav.attr('rel') == $(this).attr('rel')){
				$('#'+last_subnav.attr('rel')).fadeOut("medium");
			}
			
			if(last_subnav.length == 0){
				
				$('#'+$(this).attr('rel')).fadeToggle("medium");
			}else if(last_subnav.attr('rel') != $(this).attr('rel')){
				if($('#'+$(this).attr('rel')).css('display') == 'none'){
					$('#'+$(this).attr('rel')).fadeToggle("medium");
				}else{
					$('#'+$(this).attr('rel')).slideToggle("medium");
				}
			}else{
			//alert(1);
				$('#'+$(this).attr('rel')).fadeToggle("medium");
			}
			
			if(last_link.length > 0){
				var latest_links = last_link.attr('rel').split(',');
				for(var i=0;i <= latest_links.length; i++){
					$('.menu_item_'+latest_links[i]).removeClass('hover');
					last_link.removeClass('hover');
				}
				last_link ='';
			}
			curr_subnav = $(this);
			last_subnav = $(this);
			last_link = '';
			/*$('#subnav').bind("mouseenter",function(){
				$('#subnav').bind("mouseleave",function(){
					$('#'+curr_subnav.attr('rel')).fadeOut("medium"); 
				});
			});*/
   });
	
	 
	
	$(".menu_abc").mouseover(function(){
			
			$('#subnav_port .subnav_item_sec .subnav_item a,#subnav_port .subnav_item_inner a').removeClass('hover');
			$('#subnav_port .subnav_item_sec .subnav_item a').attr('href','#');
			
			/*if(last_link.length > 0){
				last_link.removeClass('hover');
				var latest_links = last_link.attr('rel').split(',');
				/*for(var i=0;i <= latest_links.length; i++){
					$('#'+curr_subnav.attr('rel')+' .menu_item_'+latest_links[i]).removeClass('hover');
					$('#'+curr_subnav.attr('rel')+' .menu_item_'+latest_links[i]).attr('href','#');
				}
				last_link='';
			}*/
			if($(this).attr('rel') != ''){
				$(this).toggleClass('hover');
				var link_split = $(this).attr('href').split('/');
				var links = $(this).attr('rel').split(',');
				last_link = $(this);
				
				for(var i=0;i <= links.length; i++){
					if($(this).attr('title') == 'Kunden'){
						var new_link = $('#'+curr_subnav.attr('rel')+' .menu_item_'+links[i]).attr('rel');
					}else{
						var new_link = $('#'+curr_subnav.attr('rel')+' .menu_item_'+links[i]).attr('rel')+link_split[link_split.length-2];
					}
					
					$('#'+curr_subnav.attr('rel')+' .menu_item_'+links[i]).toggleClass('hover');
					$('#'+curr_subnav.attr('rel')+' .menu_item_'+links[i]).attr('href',new_link);
				}
			}
			
	});
	
	$(".menu_abc").click(function(){
		return false;
	});
	
	
$(".news_toggle").click(function () {
			$(this).parent().removeClass('news_active');
      $(".news_container").show();
			$('.wiki').addClass('wiki_active');
	  	$(".wiki_container").hide();	  
    });
	
$(".wiki_toggle").click(function () {
			$(this).parent().removeClass('wiki_active');
      $(".wiki_container").show();
			$('.news').addClass('news_active');
	  	$(".news_container").hide();
    });	
	
	
});



jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

/*$.preloadImages("http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_portfolio.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_portfolio.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_kunden.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_kunden.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_team.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_team.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_kontakt.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_kontakt.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_impressum.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_impressum.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_sitemap.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_sitemap.jpg",				
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/head_portrait.jpg",
				"http://www.wortbildton.de/wbt/wp-content/themes/WBT/images/footer_portrait.jpg"); */
