/*----------------------------------------------------------------------------------------
	*
	*	@copyright:_________2009, Wort und Bild Verlag Konradsh�he GmbH und Co. KG
	*	@link:______________http://www.apotheken-umschau.de
	*	@author:____________Jung v. Matt/Neckar
	*	@function:__________fire functions / custom functions
	*
	*	@version:___________V0007
	* 	@revision:__________$Revision: 51 $
	* 	@lastmodified:______$Date: 2009-05-29 17:11:59 +0200 (Fr, 29 Mai 2009) $
	*
----------------------------------------------------------------------------------------*/

/*------------------------------------------------
	*	Adding class to html-tag to hide sections 
		on page load without flickering
--------------------------------------------------*/
document.documentElement.className += " jsLoad";

/*------------------------------------------------
	*	Fire all Functions which need to be 
		executed or initialized if DOM is loaded
--------------------------------------------------*/
// Provides conflicts between jQuery and other libs which uses the '$' function
//jQuery.noConflict();

jQuery(document).ready(function($){
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Browser sniffing ||--------------------------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
	// Internet Explorer sniffing
	var gpIESniff = $.browser.msie;
	var gpIEVersionSniff = $.browser.version;
	// IE6
	if(gpIESniff && gpIEVersionSniff < 7)var gpIE6Sniff = true;
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Snippets for layout optimization ||----------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
	
	/*-----|| to position filter element correct if there is a switcher ||---------------*/
	if($("#filterSrd").length && $(".swTabSrd").length){
		$("#filterSrd").css({"padding-top":"46px"});	
	}
	
	/*-----|| for centering pager items ||----------------------------------------------*/
	if($(".pagerSrd").length){
		var pagerW = 0;
		var pagerG = 0;
		$(".pagerSrd ol li").each(function(){
			pagerG = jQuery(this).outerWidth();	
			pagerW += pagerG;
		 })
		//$(".pagerSrd ol").css({"width":pagerW+"px"});
	}
	
	/*-----|| overview teaser in slot ||------------------------------------------------*/
		$(".ctSlot .ovteaserTypeA").hover(function(){
			$(this).find(".overlayBg").addClass("overlayBgHover");
		 },
		function(){
			$(this).find(".overlayBg").removeClass("overlayBgHover");
		});
		$(".ctSlot .ovteaserTypeB").hover(function(){
			$(this).find(".ctBox").addClass("overlayBgHover");
		 },
		function(){
			$(this).find(".ctBox").removeClass("overlayBgHover");
		});
	
	/*-----|| diseases subject area ||---------------------------------------------------*/
		$(".subjectAreaSrd ul li:nth-child(3n+1), .subjectAreaSrd ul li:nth-child(3n+1) a, .subjectAreaSrd ul li:nth-child(3n+1) a span").css({"width":"152px"});
		
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Fire functions ||----------------------------------------------------------*/
	/*-----------------------------------------------------------------------------------*/

	/*-----|| Main flyout navigation ||--------------------------------------------------*/
	mnFlyOut();
	
	/*-----|| Toggle form value text ||--------------------------------------------------*/
	tgFmVal();
	
	/*-----|| Toggle box in slot area ||-------------------------------------------------*/
	//tgBox();
	toggleBox();
	
	/*-----|| Toggle box search ||-------------------------------------------------------*/
	tgBoxSearch();
	
	/*-----|| Teaser content header ||---------------------------------------------------*/
	teaser();
	
	/*-----|| Specific IE6 fixes ||------------------------------------------------------*/
	if(gpIE6Sniff){
		// Form Button Hover
		fmBtnIeHover();
	}
	
	
	
	
	/*-----|| Styled form fields (plugin) ||---------------------------------------------*/
	$(".jqTransform").jqTransform();
	$(".jqTransform .jqTransformSelectWrapper").each(function (i) { /* to prevent overlapping */
			$(this).css({zIndex:100 - (i--)});							   
	});
	
	/*-----|| Custom area scroller (plugin) ||-------------------------------------------*/
	if($('#arScroller').length) {
		$("#arScroller").jScrollPane({showArrows:true, arrowSize: 28, scrollbarWidth: 24, dragMinHeight: 30, dragMaxHeight: 110});
	}
	
	/*-----|| Expand clickable areas (plugin) ||-----------------------------------------*/
	
	/*
	$('.clickArea a:first').bigTarget({
		hoverClass: 'clickAreaOver', // CSS class applied to the click zone onHover
		clickZone: '.clickArea' // jQuery parent selector
	});
	*/
	
	/*-----|| image/text carousel (plugin) ||--------------------------------------------*/
	$('.imgCarouselCont').jCarouselLite({
        btnNext: ".jBtnNext",
        btnPrev: ".jBtnPrev",
		visible: "2",
		easing: "easeOutQuint",
		speed: 1000
    });
	
	/*-----|| accordion (plugin) ||------------------------------------------------------*/
	$('#ctCont .accordionTypeA').simpleAccordion();
	$('#chCont .podcasts .accordionTypeA').simpleAccordionB();
	
	/*-----|| Rounded corners for IE (plugin) ||-----------------------------------------*/
	
	//Commented next function as it gives problems with IE8.js
	/*
	if(gpIESniff){
		// Corners Header Form BG
		$('.fmBgSrd').corners("1px no-native no-webkit no-mozilla");
		if(!gpIE6Sniff){
			$('.swTabSrd li a').corners("2px top transparent no-native no-webkit no-mozilla");
		} else {$('.swTabSrd li a').corners("2px top no-native no-webkit no-mozilla");}
		$('.ieCorners1111').corners("2px top bottom no-native no-webkit no-mozilla");
		$('.ieCorners0111').corners("2px top-right bottom no-native no-webkit no-mozilla");
		$('.starRatingSrd').corners("2px no-native no-webkit no-mozilla");
	}
	*/
	/*-----|| 2 column lists for IE/Opera (plugin) ||------------------------------------*/
	if(gpIESniff || $.browser.opera || $.browser.safari){
		$('.ctMain .linklistTypeA ul').makeacolumnlists({cols:2,colWidth:217,equalHeight:false,startN:1});
	}
	if(gpIESniff || $.browser.opera){
		$('.glossarAzSrd .botCont ul, .subjectAreaListSrd .botCont ul').makeacolumnlists({cols:2,colWidth:210,equalHeight:false,startN:1});
	}
	
	/*-----|| 3 column lists for IE/Opera (plugin) ||------------------------------------*/
	if(gpIESniff || $.browser.opera || $.browser.safari){
		$('.searchFilterSrd .botCont ul').makeacolumnlists({cols:3,colWidth:140,equalHeight:false,startN:1});
	}
	
	/*-----|| 3 column lists for IE/Opera/Safari (plugin) ||-----------------------------*/
	if(gpIESniff || $.browser.opera){
		$('.tgBox .lnList').makeacolumnlists({cols:3,colWidth:90,equalHeight:false,startN:1});
	}
	
	/*-----|| 3datepicker (plugin) ||-----------------------------*/
	if($("#datepicker").length){
		$("#datepicker").datepicker({
			prevText: '&lt;',
			nextText: '&gt;',
			dateFormat: 'dd.mm.yy',
			dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
			monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
			showAnim: 'slideDown'
		
		});
	}

	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Function: main navigation ||-----------------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
	function mnFlyOut () {
		
		// First of all, disable the fallback css menu behaviour
		var mnFB = $("#mnFb");
		if (mnFB){
			mnFB.attr("rel", "alternate stylesheet");
			mnFB.attr("disabled", "disabled");
		}
		
		$("#mnCont li.mnLv0 li h3").parent().next().css({"border-top-color":"#FFFFFF"});
		
		/*-----|| Level 0/1 Hover delayed --> ANIMATED ||---------------------------*/
		$("#mnCont li.mnLv0").hoverIntent(function(){ // main navigation
			var el = $(this);
			if(el.find("a.mnLv0").next().length){ // if flyout exists
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#004276"},200, function() {
						el.find("a.mnLv0").next().stop().slideDown("fast");
					});
				}
				else {el.find("a.mnLv0").next().stop().slideDown("fast");}
			} else {
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#004276"},200);
				}
			}
		},
		function(){
			var el = $(this);
			el.find("a.mnLv0").next().hide();
			if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
				el.find("a.mnLv0").stop().animate({"color":"#58595B"},200);
			}
		});
		
		$("#snCont li.mnLv0").hoverIntent(function(){ // sub navigation
			var el = $(this);
			el.css({zIndex:850});
			if(el.find("a.mnLv0").next().length){ // if flyout exists
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#00838C"},200, function() {
						el.find("a.mnLv0").next().stop().slideDown("fast");
					});
				}
				else {el.find("a.mnLv0").next().stop().slideDown("fast");}
			} else {
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#00838C"},200);
				}
			}
		},
		function(){
			var el = $(this);
			el.css({zIndex:800});
			el.find("a.mnLv0").next().hide();
			if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
				el.find("a.mnLv0").stop().animate({"color":"#58595B"},200);
			}
		});
		
		$(".lnIconFlSrd").hoverIntent(function(){ // bookmark flyout
			var el = $(this);
			el.find(".lnIconBook").addClass("current");
			el.find(".ATxtButton").addClass("ATxtcurrent");
			el.find(".artActListFl").slideDown("fast");

		},
		function(){
			var el = $(this);
			el.find(".lnIconBook").removeClass("current");
			el.find(".ATxtButton").removeClass("ATxtcurrent");
			el.find(".artActListFl").hide();
		});
		
		/*-----|| Level 0/1 Focus --> ANIMATED ||---------------------------*/
		$("#mnCont li.mnLv0>a").focus(function(){ // main navigation
			var el = $(this).parent();

			$("li.mnLv0>a:not(.current)").animate({"color":"#58595B"},200);
			$("li.mnLv0>a").next().hide();
			
			if(el.find("a.mnLv0").next().length){ // if flyout exists
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#004276"},200, function() {
						el.find("a.mnLv0").next().stop().slideDown("fast");
					});
				}
				else {el.find("a.mnLv0").next().stop().slideDown("fast");}
			} else {
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#004276"},200);
				}
			}
		});
		
		$("#snCont li.mnLv0>a").focus(function(){ // sub navigation
			var el = $(this).parent();

			$("li.mnLv0>a:not(.current)").animate({"color":"#58595B"},200);
			$("li.mnLv0>a").next().hide();

			if(el.find("a.mnLv0").next().length){ // if flyout exists
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#00838C"},200, function() {
						el.find("a.mnLv0").next().stop().slideDown("fast");
					});
				}
				else {el.find("a.mnLv0").next().stop().slideDown("fast");}
			} else {
				if(!el.find("a.mnLv0").hasClass("current")){ // if flyout is not current
					el.find("a.mnLv0").stop().animate({"color":"#00838C"},200);
				}
			}
		});
	
		
		/*-----|| Flyout Level 2 Hover delayed ||---------------------------*/
		$("#mnCont li.mnLv0 > ul li:has(ul)").hoverIntent(function(){
			var el = $(this);
			el.find("ul").css({'width':1});
			el.find("a:first").addClass("mnLv1Hover");
			el.find("ul").animate({ 
				width: 218
			}, "fast" );
		},function(){
			var el = $(this);

			el.find("ul").animate({ 
				width: 0
			}, "fast",callback);
			function callback() {
				el.find("ul").hide();
				// Removes classname to change bg-pos
				el.find("a:first").removeClass("mnLv1Hover");
			}
		});	
		
		/*-----|| Flyout Level 2 Focus ||---------------------------*/
		$("#mnCont li.mnLv0 > ul > li > a").focus(function(){
			var el = $(this).parent();
		
			$("#mnCont li.mnLv0 > ul > li").find("ul:visible").animate({ 
				width: 0
			}, "fast",callback);
			function callback() {
				$(this).hide();
				// Removes classname to change bg-pos
				$(this).prev().removeClass("mnLv1Hover");
			}
			
			if(el.find("a").next().length){ // if flyout exists
				el.find("a:first").addClass("mnLv1Hover");
				el.find("ul").css({'width':1});
				el.find("ul").animate({ 
					width: 218
				}, "fast" );
			}
		});
		
		/*-----|| Close Flyout if clicked outside ||---------------------------*/
		$(document).bind("click", function(e) {
			var $clicked=$(e.target); // get the element clicked
			if(!($clicked.is("#mnCont a"))){
				$("#mnCont li.mnLv0 > ul").hide();
				if(!$("#mnCont a.mnLv0").hasClass("current")){ // if flyout is not current
					//$("#mnCont a.mnLv0").stop().fadeTo("fast",1.0);
					$("#mnCont a.mnLv0").stop();
				}
				//$(document).unbind("click");
			}
		});
				
	}
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Function: toggle text in input fields on focus  ||-------------------------*/
	/*-----------------------------------------------------------------------------------*/
	function tgFmVal () {
		// Function call if the text search field has been clicked (focused)
		var defValues = new Array();
		$("input.fmTxt, textarea.fmArea").focus(function() {
			if (!defValues[this.id]) {
				defValues[this.id] = this.value;
			}
			if (this.value == defValues[this.id]) {
				this.value = '';
			}
			$(this).blur(function() {
				if (this.value == '') {
					this.value = defValues[this.id];
				}
			});
		});
	}
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Function: toggle box ||----------------------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
/*	function tgBox () {
		$(".tgHandler h4").wrapInner("<a href='#'></a>"); // insert a-tag to provide keyboard func
		//$(".tgHandler").css({cursor:"pointer"});
		$(".tgHandler a").attr("title","Bitte klicken um Inhalte einzublenden");
		$(".stateOpen").next().show(); // if element has class "stateOpen" open element
		$(".stateOpen").each(function(i){ // fpr each element which is open, define title tag
			$(this).find("a").attr("title","Bitte klicken um Inhalte auszublenden");
		});
		
		$(".tgHandler a").bind("click", function(){ // if element is clicked/focused
			var el = $(this).parent();
			el.toggleClass("stateOpen");
			el.next().slideToggle("normal",function(){
				if(el.hasClass("stateOpen")){
					el.find("a").attr("title","Bitte klicken um Inhalte auszublenden");
				} else {
					el.find("a").attr("title","Bitte klicken um Inhalte einzublenden");
				}
			});
			return false;
		});
	}
*/	
	function toggleBox() {
		$('.toggleBox').click(function(){
			$(this).next().slideToggle();
			$(this).toggleClass('stateOpen');
		});
	}
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Function: toggle box search/glossar/etc. ||---------------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
	function tgBoxSearch () {
		$(".searchFilterSrd .btnToggle, .glossarAzSrd .btnToggle, .glossarAzSrdfix .btnToggle,.fmSearchFilterSrd .btnToggle, .reviewCont .btnToggle").wrapInner("<a href='#'></a>"); // insert a-tag to provide keyboard func
		//$(".tgHandler").css({cursor:"pointer"});
		$(".searchFilterSrd .btnToggle a, .glossarAzSrd .btnToggle a, .glossarAzSrdfix .btnToggle a, .fmSearchFilterSrd .btnToggle a, .reviewCont .btnToggle a").attr("title","Bitte klicken um Inhalte einzublenden");
		
		$(".searchFilterSrd .btnToggle a, .glossarAzSrd .btnToggle a, .glossarAzSrdfix .btnToggle a, .fmSearchFilterSrd .btnToggle a, .reviewCont .btnToggle a").bind("click", function(){ // if element is clicked/focused
			var el = $(this);
			el.toggleClass("open");
			el.parent().parent().next().slideToggle("normal",function(){
				if(el.hasClass("open")){
					el.attr("title","Bitte klicken um Inhalte auszublenden");
				} else {
					el.attr("title","Bitte klicken um Inhalte einzublenden");
				}
			});
			return false;
		});
	}
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Function: teaser content header ||-----------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
	function teaser () { // switches bg and icons
		var linkEl = $("#boxOver a");
		
		$("#boxOver a").hover(function(){
			var el = $(this);
			
			if(el.hasClass("lnActive")) {
				return false;
			} else {
				$("#boxOver a").removeClass("lnActive");
				//$("#boxOver a").find("strong").remove();
				el.addClass("lnActive");
				//el.append(" <strong>&raquo;</strong>");
			}
		}, function(){ 
				//clearTimeout(lnMoOnTimer);
		});
	}
	
	/*-----------------------------------------------------------------------------------*/
	/*-----|| Function: ie6 form button hover ||-----------------------------------------*/
	/*-----------------------------------------------------------------------------------*/
	function fmBtnIeHover () { 
		$(".fmBtn").hover(function(){
			var el = $(this);
			el.addClass("fmBtnIEHover");
		}, function(){ 
			var el = $(this);
			el.removeClass("fmBtnIEHover");
		});
	}
	
	
});



