
jQuery.fn.isChildOf = function(b){
    return (this.parents(b).length > 0);
};

/*****************************
 * Submenüs
 *****************************/

function showSubMenu(menuid) {
	var navi = document.getElementById('navi_' + menuid + '_a');
	var subnavi = document.getElementById('subnavi_' + menuid);
	
	//if(navi) navi.className = 'navi active';
	if(subnavi) subnavi.style.display = 'block';
}

function hideSubMenu(menuid) {
	var navi = document.getElementById('navi_' + menuid + '_a');
	var subnavi = document.getElementById('subnavi_' + menuid);
	
	//if(navi) navi.className = 'navi';
	if(subnavi) subnavi.style.display = 'none';
}

/*****************************
 * Widgets
 *****************************/

function makeActiveTab(bereich, tabnr, gesamttabs) {
	tabid = bereich + "_tab" + tabnr;
	
	var tabclass = document.getElementById(tabid).className;
	
	for(var i = 1; i <= gesamttabs; i++) {
		document.getElementById(bereich + "_tab" + i).className = "tab" + i + " inactive";
		document.getElementById(bereich + "_content" + i).className = "invisible_tab_content";
	}
	
	document.getElementById(bereich + "_tab1").className = "tab1_inactive";
	
	switch(tabnr) {
		case 1:
			document.getElementById(tabid).className = "tab1_active";
			document.getElementById(bereich + "_content1").className = "visible_tab_content";
			break;
		case 2:
			document.getElementById(tabid).className = "tab_active";
			document.getElementById(bereich + "_content2").className = "visible_tab_content";
			break;
		case 3:
			document.getElementById(tabid).className = "tab_active";
			document.getElementById(bereich + "_content3").className = "visible_tab_content";
			break;
	}
	
}

function makeActiveTab(bereich, tabnr, gesamttabs) {
	tabid = bereich + "_tab" + tabnr;
	
	var tabclass = document.getElementById(tabid).className;
	
	for(var i = 1; i <= gesamttabs; i++) {
		document.getElementById(bereich + "_tab" + i).className = "tab" + i + " inactive";
		document.getElementById(bereich + "_content" + i).className = "invisible_tab_content";
	}
	
	document.getElementById(bereich + "_tab1").className = "tab1_inactive";
	
	switch(tabnr) {
		case 1:
			document.getElementById(tabid).className = "tab1_active";
			document.getElementById(bereich + "_content1").className = "visible_tab_content";
			break;
		case 2:
			document.getElementById(tabid).className = "tab_active";
			document.getElementById(bereich + "_content2").className = "visible_tab_content";
			break;
		case 3:
			document.getElementById(tabid).className = "tab_active";
			document.getElementById(bereich + "_content3").className = "visible_tab_content";
			break;
	}
	
// 	document.getElementById(bereich + "_tab_content").className = "tab" + tabnr + "_content below_tabs";
}

/*****************************
 * Akkordeon Menü
 *****************************/

function akkordeon(event) {
	
	var object = event.target || event.srcElement;
		
	var list = jQuery(object).parent(".akkordeon").get(0);
	var status = jQuery(object).hasClass("active");
	
	jQuery(list).children(".active").removeClass("active").not(".aentry").slideUp();
	
	if(status) {
		jQuery(object).removeClass("active").next(".content").slideUp().removeClass("active");
	} else {
		jQuery(object).addClass("active").next(".content").slideDown().addClass("active");
	}
	
	return false;

}

/*****************************
 * Flash-Wrapper Klick-Event
 *****************************/

function clicky(id, url) {
	if(id && pageTracker) pageTracker._trackEvent("banner", "click", id, 1);
	if(url) window.open(url);
}

/*****************************
 * Such-Formular
 *****************************/

function submit_search_articles() {
	var search = jQuery("#search_article input[name=suche]").val();
	var action = jQuery(this).attr("action");
	location.href = action+'?suche=' + encodeURIComponent(search);
	return false;
}

/*****************************
 * Rechtsmarkt Akkordeon
 *****************************/

(function($){
	
	$(document).ready(function(){
		
		pagede = document.documentElement;
		pagew = jQuery(window).width();
		pageh = jQuery(window).height();
		
		$(".journal_akkordeon  .block").bind("click", rechtsmarkt_akkordeon_block_click);
		$(".journal_akkordeon  .block").bind("open", rechtsmarkt_akkordeon_block_open);
		$(".journal_akkordeon  .block").bind("close", rechtsmarkt_akkordeon_block_close);
		$(".journal_akkordeon  .block .teaser").bind("mouseenter", rechtsmarkt_akkordeon_block_colorIn);
		$(".journal_akkordeon  .block .teaser").bind("mouseleave", rechtsmarkt_akkordeon_block_colorOut);
		
		rechtsmarkt_check_blocks();
		
	});
	
	function rechtsmarkt_check_blocks() {
		
		var blocks = $.makeArray($(".journal_akkordeon  .block"));
		var blocks_to_show = new Array();
		
		for(var i in blocks) {
			cover_url = $(blocks[i]).find(".teaser .image img").attr("src");
			if(cover_url != undefined && cover_url.indexOf("/dummy_cover.gif") == -1) {
				blocks_to_show.push(blocks[i]);			
				rechtsmarkt_add_links(blocks[i]);
			}
		}

		if($.browser.msie && $.browser.version == "6.0") {
			$(blocks_to_show[blocks_to_show.length - 1]).removeClass("closed").addClass("opened");
		} else {
			$(blocks_to_show[0]).removeClass("closed").addClass("opened");
		}
		$(blocks_to_show).show();
		
	}
	
	function rechtsmarkt_add_links(block) {
		$(block).find(".teaser").append("<a class='link_order' href='/rechtsmarkt/einzelheftbestellung'>Zum Bestellformular</a>");
		$(block).find(".teaser").append("<span class='link_open'>Inhalt Anzeigen</span>");
	}
	
	function rechtsmarkt_akkordeon_block_click(event) {
		
		var block = event.currentTarget;
		var is_opened = jQuery(block).hasClass("opened");
	
		if(!is_opened) {
			rechtsmarkt_akkordeon_block_close_all();
			$(block).trigger("open");
		}
		
	}
	
	function rechtsmarkt_akkordeon_block_open(event) {
		
		$(this).find(".link_open").fadeOut(200);

		$(this).find(".content").slideDown(function(){
			var block = $(this).parents(".block:first");
			$(block).addClass("opened").removeClass("closed");
			$(block).find(".teaser").removeAttr("style");
			$(block).find(".link_order").fadeIn(200);
			$.scrollTo(block, 500);
		});
		$(this).find(".teaser").animate({height: "130px", padding: "10px"});
		$(this).find(".teaser img").animate({height: "130px", width: "90px"});
		
		$(".journal_akkordeon  .block").not(this).find(".teaser").trigger("mouseleave");
		
	}
	
	function rechtsmarkt_akkordeon_block_close(event) {
		
		$(this).find(".link_order").fadeOut(200);
		
		$(this).find(".content").slideUp(function(){
			$(this).parents(".block:first").removeClass("opened").addClass("closed");
			$(this).parents(".block:first").find(".link_open").fadeIn(200);
		});
		$(this).find(".teaser").animate({height: "73px", padding: "5px"});
		$(this).find(".teaser img").animate({height: "73px", width: "52px"});
		
	}
	
	function rechtsmarkt_akkordeon_block_close_all(event) {
		$(".journal_akkordeon  .block:not(.closed)").trigger("close");
	}
	
	function rechtsmarkt_akkordeon_block_colorIn(event) {
		var block = $(this).parents(".block:first");
		var is_opened = $(block).hasClass("opened");
		if(is_opened) return false;
		$(this).stop(true,true).animate({backgroundColor : "#e4e9ef"}, 300);
	}
	
	function rechtsmarkt_akkordeon_block_colorOut(event) {
		var block = $(this).parents(".block:first");
		var is_opened = $(block).hasClass("opened");
		if(is_opened) return false;
		$(this).stop(true,true).animate({backgroundColor : "#ffffff"}, 300);
	}
	
})(jQuery);

/*****************************
 * Sonstiges
 *****************************/

(function($){

	$(document).ready(function(){
		
		externallink_add_cssclass();
		alternate_table_rows();
		
		maxwidth = pagew - 100;
		maxheight = pageh - 50;
		
		var valSearchField = '';
		
		$('.colorbox').colorbox({
			photoScaling : false, maxWidth: maxwidth, maxHeight: maxheight, opacity:0.5,
			href : function() {
            	var href = $(this).attr("href");
            	if(href.search("getContent") != -1) {
            		href += (href.search("\\?") != -1) ? "&" : "/?";
            		href += "isColorbox";
            	}
            	return href;
            }
		});
		
		if($('.wp-content .hidden').length > 0) {
			var link = $("<div class='show-all'><a><span class='icon'></span><span class='text'>Weitere Informationen anzeigen</span></a></div>");
			$(link).find("a").click(function(){
				if($('.wp-content .hidden:hidden').length > 0) {
					$('.wp-content .hidden').slideDown();
					$(this).addClass("hide").find(".text").text("Weitere Informationen verstecken");
				} else {
					$('.wp-content .hidden').slideUp();
					$(this).removeClass("hide").find(".text").text("Weitere Informationen anzeigen");
				}
			});
			
			$('.wp-content .hidden:first').before(link);
		}
		
		$('#sidebar .sidebarbox .tabs div').hover(
			function () {
				$(this).css({'text-decoration' : 'underline'});
			},
			function () {
				$(this).css({'text-decoration' : 'none'});
			}
		);
		
		$('#search_article form').submit(submit_search_articles);
		
		$('#wrapper_rechtsmarkt_einzelheftform fieldset.cf-fs1, #wrapper_azur_einzelheftform fieldset.cf-fs1').after('<a class="more_link" href="#">Weitere Ausgaben ausw&auml;hlen</a>');
		
		$('#wrapper_rechtsmarkt_einzelheftform fieldset.cf-fs2, #wrapper_azur_einzelheftform fieldset.cf-fs2').after('<div style="line-height:1px;">&nbsp;</div>');
		
		$('#wrapper_rechtsmarkt_einzelheftform .more_link, #wrapper_azur_einzelheftform .more_link').click(function(){
			$(this).next('fieldset').slideToggle(175);
			return false;
		});
		
		$('a.search_button').mouseover(function(){
			$(this).addClass("mouseover");
		}).mouseout(function(){
			$(this).removeClass("mouseover");
		});
		
		$(".wp-caption_").delegate("a.colorbox:has(.magnifier)", "mouseover", function() {
			$(this).find(".magnifier").animate({
				width: "40px",
				height: "40px"
			}, 100);
		}).delegate("a.colorbox:has(.magnifier)", "mouseout", function(event) {
			if($(this).closest(".wp-caption").find(event.relatedTarget).length > 0) return;
			$(this).find(".magnifier").animate({
				width: "30px",
				height: "30px"
			}, 100);
		});
		
		$(".wp-caption a.colorbox").each(function(){
			var pos_y = $(this).find("img").height();
			var pos_x = $(this).find("img").width();
			$("<div class='magnifier' title='Zum Vergrößern bitte auf die Grafik klicken' />").css({
				"top" : (pos_y-36) + "px",
				"left" : (pos_x-36) + "px"
			}).appendTo(this);
		});
	});
	
	// Setze CSS-Klasse bei externen Links
	function externallink_add_cssclass() {
		try {
			var host = window.location.host;
	        host = host.replace(/\./g, "\\.");
	        $('#inner_content a, #sidebar a').not('[href*=fotos\\.juve\\.de], [href*='+host+'], [href^=javascript], [href^=\\/], [href^=\\?], [href^=#], [href^=ka], .submit, .button, .spbutton, .pagination a').each( function() {
	        		if ($(this).find('*:not(span)').length > 0 || $(this).text() == '') return;
	        		$(this).addClass('external-link');
	        });
		} catch(e) {}
	}
	
	function alternate_table_rows() {

		if(jQuery.browser.msie) {
			$("table.colored-number:not(.alternate_rows)").each(function(){
				$(this).addClass("alternate_rows")
				$(this).children("tbody").children("tr:odd").addClass("even");
				$(this).children("tbody").children("tr").children("td:first-child").addClass("number");
			});
			$("table.colored:not(.alternate_rows)").each(function(){
				$(this).addClass("alternate_rows")
				$(this).children("tbody").children("tr:odd").addClass("even");
			});
		}
	}

})(jQuery);
