﻿var savedTitleTag = '';

jQuery(window).load(function() {
	document.title = '' + savedTitleTag.split('#')[0];
});

jQuery(document).ready(function(){

	jQuery('.overlay-bg').click(function() {
		jQuery('#videotipp').remove();
	});

	jQuery('#submenu-item-2 li a').click(function() {
		setCookie('LargeCarousel', 1);
	});

	jQuery('#experts .expert_image_name a').each(function() {
		if(jQuery(this).attr('href') == '') {
			jQuery(this).removeAttr('rel');
		}
	});

	savedTitleTag = document.title;

	jQuery('.userlogin input.logout').removeAttr('onclick');

	jQuery('.userlogin input.login').removeAttr('onclick').click(function() {
		jQuery('.userlogin').hide();
		jQuery('#hp-register').hide();
		jQuery('#frmRezeptSchnellSuche').hide();
		jQuery('a.cookbook-link').hide();
		jQuery('#divHeaderMessage').hide();
		jQuery('#head').css('height','338px');
		jQuery('#headright .loginbox').show();
		return false;
	});

	jQuery('.userlogin input.register').removeAttr('onclick').click(function() {
		jQuery('.userlogin').hide();
		jQuery('.loginbox').hide();
		jQuery('#frmRezeptSchnellSuche').hide();
		jQuery('a.cookbook-link').hide();
		jQuery('#divHeaderMessage').hide();
		jQuery('#head').css('height','532px');
		jQuery('#headright').css('overflow','visible');
		jQuery('#headright #hp-register').show();
		return false;
	});

	jQuery('.userlogin input.newsletter-top').removeAttr('onclick').click(function() {
		window.location.href = 'eat-smarter-newsletter/bestellen.html';
		return false;
	});

	// click on register-link anywhere on any page triggers click to register button in head
	jQuery('.global-register-click').click(function() {
		jQuery('.overlay,.overlay-bg').click();
		jQuery('#headright .userlogin input.register').click();
		scroll(0,0);
		return false;
	});


   // NAVI
	var idName = [],
	idSubName = [],
	activetimeout,
	str_mouseout = "jQuery('#submenu ul').css( 'display', 'none' );" +
	    	  						"jQuery('#submenu ul li').css( 'display', 'none' );" +
	    	  						"jQuery('#submenu ul#' + activesubmenuitemid).css( 'display', 'inline' ).children('li').css( 'display', 'inline' );" +
	    	  						"jQuery('#mainnav li a').removeClass('underline');" +
	    	  						"jQuery(this).children('a').eq(0).addClass('underline');";

   jQuery("#mainnav ul").eq(0).children("li").each( function(index){

       idName[index] = "menu-item-" + (index + 1);
       idSubName[index] = "sub" + idName[index];
       jQuery(this).attr('id', idName[index]);
		 jQuery(this).children('ul').attr('id', idSubName[index]);
		jQuery(this).hover(
			function() {
				jQuery('ul#' + idSubName[index]).addClass('hover');
			},
			function() {
				jQuery('ul#' + idSubName[index]).removeClass('hover');
			}
		);
   });

	jQuery('#mainmenu ul li ul.node_submenu li').hover(
		function() {
			jQuery(this).css('background-color','#D6FB73');
		},
		function() {
			jQuery(this).css('background-color','#FFF');
		}
	);

	// NAVI end

   //Center vertically all items with class .vcenter
   // IMPORTANT: modified for recipe-details
   jQuery('.vcenter').each( function(i){
	   jQuerythis = jQuery(this);
	   jQueryparent = jQuerythis.parent();
	   var childHeight = jQuerythis.height(),
	   parentHeight = jQueryparent.height(),
	   topMarginValue = parseInt((parentHeight - childHeight) / 2),
	   topMargin;
	   if (topMarginValue < 0) topMarginValue = 0;
	   if (topMarginValue > 106) topMarginValue = 106; // modified for recipe-detail steps
	   topMargin = topMarginValue.toString() + 'px';
	   jQuerythis.css('margin-top', topMargin).css('visibility', 'visible');
   });

   //Center vertically all items with class .wb-vcenter
   // IMPORTANT: modified for webbook-links
   jQuery('.wb-vcenter').each( function(i){
	   jQuerythis = jQuery(this);
	   jQueryparent = jQuerythis.parent();
	   var childHeight = jQuerythis.height(),
	   parentHeight = jQueryparent.height(),
	   topMargin,
	   topMarginValue = parseInt((parentHeight - childHeight) / 2);
	   if (topMarginValue < 0) topMarginValue = 0;
	   topMargin = topMarginValue.toString() + 'px';
	   jQuerythis.css('margin-top', topMargin).css('visibility', 'visible');
   });

	jQuery('.tx-srfeuserregister-pi1-error').each(function() {
		if(jQuery(this).text() != '')
			jQuery('.userlogin a:eq(1)').trigger('click');
	});

	if(jQuery.trim(jQuery('.reg-error-wrap ul').html()) == '') {
		jQuery('.reg-error-wrap').remove();
	}

	/*
	jQuery('.forgot-reg-wrapper .registration a').click(function() {
		jQuery('.loginbox').hide();
		jQuery('.userlogin a:eq(1)').trigger('click');
		return false;
	});
	*/

	//jQuery('body#experts .answertext').hide();
	jQuery('body#experts .answertextlink').click(function() {
		jQuery('body#experts .answertext').slideDown(1000);
	});
	jQuery('body#experts .answertext').click(function() {
		jQuery('body#experts .answertext').slideUp(1000);
	});
});

function lead_weiterempfehlen(){
	// home > lead > weiterempfehlen-link

	jQuery('body').append(jQuery('<div id="lead_weiterempfehlen_form" class="overlay-bg" style="display:block; opacity:0.01; filter: alpha(opacity=1);"></div>'));
	jQuery('body').append(jQuery('<div id="lead_weiterempfehlen_form_content">	<form onsubmit="jQuery(this).parent().fadeOut(\'slow\'); jQuery(\'#lead_weiterempfehlen_form\').fadeOut(\'slow\').remove(); return false;">		<div class="row">			<label for="email">Email</label>			<input name="email" type="text" size="30" maxlength="30" value="email@email.de">		</div>		<div class="row">			<label for="text">Nachricht</label>			<textarea name="text" cols="50" rows="10"></textarea>		</div>		<div class="row">			<input type="submit" value="Senden">		</div>	</form></div>'));

	jQuery('#lead_weiterempfehlen_form').fadeTo( "slow", 0.75, function(){

		jQuery('#lead_weiterempfehlen_form_content').center().show(); // show content

	} );


	return false;
}

function show_additionalnutries() {
	jQuery('#additional_nutries').appendTo(jQuery('body'));
	jQuery('.overlay-bg').defaultOverlay();
	jQuery('#additional_nutries').center().show();
	return false;
}

jQuery(function(){
	jQuery('#additional_nutries .box-close').click(function() {
		jQuery('.overlay-bg').hide();
		jQuery('#additional_nutries').hide();
		return false;
	});
});
