$(window).ready(function(){
	

	$('#rw_subheader_pic').fadeIn(1500);
	
	function rw_logo_control(){ 
	
			//DYNAMIC LOGO POSITION IN MASTHEAD
			var rw_logo_targ_w = $('#rw_logo_targ').width(); //get target div width to compare for placement and scale
			
			
			//get pos of targ
			var rw_targ = $('#rw_logo_targ');
			var rw_targ_pos = rw_targ.position();
			var rw_targ_left = rw_targ_pos.left;
			var rw_targ_top = rw_targ_pos.top;
			
			var rw_targ_center = rw_targ_left+(rw_logo_targ_w/2); //get targ div info for placement
			
			
						
			//if the width of the logo should differ than width of targ div, assign the offset here
			var rw_logo_w_diff = 85;
			var rw_logo_scale = rw_logo_targ_w - rw_logo_w_diff; //create calc here
			
			//console.log(rw_logo_scale);
			
			//assign scale and pos of logo
			$('#rw_logo').css({'width':rw_logo_scale+'px'});
			
			var rw_logo_center = rw_logo_scale/2;
			
			
			
			$('#rw_logo').css({'left':rw_targ_center-rw_logo_center+'px'});
			
			
	};//close rw logo control
	
	rw_logo_control();	
	
	
	
	function sp_logo_control_hover(){ 
	
			//DYNAMIC LOGO POSITION IN MASTHEAD
			var rw_logo_targ_w = $('#rw_logo_targ').width(); //get target div width to compare for placement and scale
			
			
			//get pos of targ
			var rw_targ = $('#rw_logo_targ');
			var rw_targ_pos = rw_targ.position();
			var rw_targ_left = rw_targ_pos.left;
			var rw_targ_top = rw_targ_pos.top;
			
			var rw_targ_center = rw_targ_left+(rw_logo_targ_w/2); //get targ div info for placement
			
			
						
			//if the width of the logo should differ than width of targ div, assign the offset here
			var rw_logo_w_diff = 80;
			var rw_logo_scale = rw_logo_targ_w - rw_logo_w_diff; //create calc here
			
			//console.log(rw_logo_scale);
			
			//assign scale and pos of logo
			$('#rw_logo').css({'width':rw_logo_scale+'px', 'transition': 'width .25s'});
			
			var rw_logo_center = rw_logo_scale/2;
			
			
			
			//$('#rw_logo').css({'left':rw_targ_center-rw_logo_center+'px'});
			
			
	};//close sp logo control hover
		
	$('#sp_logo_new').mouseover(function () {
		/*sp_logo_control_hover();*/
		$('#rw_main_nav .rw_col_two #sp_logo_new img').css({'width':'75%', 'transition': 'width .25s'});
	});
	
	$('#sp_logo_new').mouseout(function () {
		/*rw_logo_control();*/
		$('#rw_main_nav .rw_col_two #sp_logo_new img').css({'width':'72%', 'transition': 'width .25s'});
	});

	
	
	
/********************************************************/
/***** START FONT CONTROL LISTENER (GLOBAL) ************/


					function rw_font_perc_listen_global(){

						$('.rw_font_targ_global').each(function(index){

								//grab the percentage of the scale of the font desired
								var rw_font_scale_factor = $(this).attr('rw_scale');

								var rw_update_font_size = rw_font_percent_control_global(rw_font_scale_factor);
								//alert(rw_update_font_size);
								$(this).css({'font-size':rw_update_font_size+'px'})


						});//close each loop
						
					};//close rw_font_perc_listen_global








					/********** FONT PERCENTAGE CONTROL BASED ON BASE FONT AND 1200 PIXEL WIDTH ************/

					function rw_font_percent_control_global(rw_scale_factor){

						  var rw_base_font = 12;
						  var rw_max_screen_width = 1200;

						  var rw_current_screen_width = $('#rw_main_hold').width();
						  var rw_screen_perc_diff = rw_current_screen_width/rw_max_screen_width;

						  if(rw_current_screen_width<rw_max_screen_width){

								//convert percentages to the goal fonts size desired
								var rw_goal_scale_factor = rw_scale_factor*rw_base_font;

								//find a perc of the goal font size based on perc of screen diff
								var rw_final_font_size = rw_goal_scale_factor*rw_screen_perc_diff;


						  }else{

								var rw_final_font_size = rw_scale_factor*rw_base_font;

						  };//close if screen width
						  return rw_final_font_size;



					};//close font percent control_global




					rw_font_perc_listen_global();


						



/***** END FONT CONTROL LISTENER (GLOBAL) ************/
/********************************************************/



/********************************************************************/
/***** START FONT CONTROL LISTENER (GLOBAL) by Sergey P. 

	function sp_font_size(){
		var rw_base_font = 70;
		var rw_max_screen_width = 1200;

		var rw_current_screen_width = $(window).width();
		var rw_screen_perc_diff = rw_current_screen_width/rw_max_screen_width;

		if(rw_current_screen_width<rw_max_screen_width){
			console.log('FIRE');
			var sp_font_size = rw_base_font*rw_screen_perc_diff;
		}
		return sp_font_size;
		
	};//close sp_font_size

	sp_font_size();
	
	function sp_font_size_update(){
		var sp_update_font_size = sp_font_size();
		$('.rw_row2').css('text-transform', 'uppercase');
		$('.rw_row2').css('font-size', sp_font_size() + 'px');
	}
	sp_font_size_update();
************/
/***** END FONT CONTROL LISTENER (GLOBAL) by Sergey P. ************/
/******************************************************************/



/****************************************/
/**** START DYNAMIC BANNER CLICKER  ****/

$('body').delegate('.rw_targ_click', 'click', function(){

	//only click through to the recipe detail if overlay for playing video is not present
	//this is necessary since recipe banners use its entire container to pass the detail click thru
	
	var rw_check_for_overlay = $(this).children().children('.rw_vid_overlay_list').length;
	if(rw_check_for_overlay == 0){
		var rw_click_value = $(this).attr('rw_link');
		window.location.href = rw_click_value;
	};//close if

});//.rw_targ_click



/********** RECIPE SEARCH ADV/SIMPLE *************/

$('.rw_recipe_search_adv_click').click(function(){

	/*$('#rw_simple_search_go_img').hide();*/
	/*$('.rw_recipe_framed').css({'background-color':'#990016'})*/
	$('.rw_recipe_search_adv_click').hide();
	$('#rw_recipe_search_box_page').slideDown(function(){
	
		$('.sp_go_button_center').fadeIn();
		$('.rw_recipe_search_simple_click').show();
	});

});//end click


$('.rw_recipe_search_simple_click').click(function(){
	$(this).hide();
	$('.sp_go_button_center').hide();
	/*$('.rw_recipe_framed').css({'background-color':'transparent'})*/
	
	$('#rw_recipe_search_box_page').slideUp(function(){
	  $('.rw_recipe_search_adv_click').show();
	  $('#rw_simple_search_go_img').fadeIn();
	});
	/*****
	$('#rw_recipe_search_box_page').fadeOut("fast",function(){
	
		$('.rw_recipe_search_adv_click').show();
		$('#rw_simple_search_go_img').fadeIn();
	
	});
	*********/

});//end click









	

/******* PRODUCTS/RECIPES TABS *******/

    $('.sp_tab').click( function() {
        $('.sp_tabs div.sp_tab_active').removeClass('sp_tab_active');
        $(this).toggleClass('sp_tab_active');
    });

/******* END OF PRODUCTS/RECIPES TABS *******/




/******* RECIPE SEARCH **********************/

	$('.rw_side_recipe_go_ext').click(function(){

			  var rw_recipe_keyword = $('#rw_recipe_keyword_search').val();
			  if(rw_recipe_keyword == ''){
				  //alert('You must type in a keyword to search.')
				  $('#rw_ext_recipe_search').submit();
			  }else{
					$('#rw_ext_recipe_search').submit();
					//window.location.href = "/recipes/recipe-search-results/"+rw_recipe_keyword;
			  }

	});//click go
	
	$('.rw_side_recipe_go').click(function(){

			  //var rw_recipe_keyword = $('#rw_recipe_search_field').val();
			 
					$('#rw_int_recipe_search').submit();
					//window.location.href = "/recipes/recipe-search-results/"+rw_recipe_keyword;
			  

	});//click go
	
	
	
	
	
	



/******* EMMA SIGNUP ************/


	 $('#rw_sidebar_emma_button').click(function(){$('#rw_sidebar_emma').submit();});//click

	 $('#rw_sidebar_emma_button_sidebar').click(function(){$('#rw_sidebar_emma_sidebar').submit();});//click

	 $('#rw_sidebar_emma_button_mobile').click(function(){$('#rw_sidebar_emma_mobile').submit();});//click








/***************************************/
/****ROLLOVER CONTROL ******/

function sp_rolloverControll() {



	  $('.rw_img_rollover').mouseover(function () {
	  
			var viewportWidth = $(window).width();

			if (viewportWidth > '567') {

					var thisSrc = $(this).attr('src');

					if (thisSrc.indexOf("-rollover.jpg") < 0) {

						  //find the . in the extension and go back three letters and place a 2

						  var thisRolloverSrc = thisSrc.replace(".jpg", "-rollover.jpg");
						  $(this).attr('src', thisRolloverSrc);

					}
			}

	  });

	  $('.rw_img_rollover').mouseout(function () {
	  
			var viewportWidth = $(window).width();

			if (viewportWidth > '567') {

					  var thisSrc = $(this).attr('src');

					  if (thisSrc.indexOf("-rollover.jpg") > 0) {

						  //find the . in the extension and go back three letters and place a 2

						  var thisRolloutSrc = thisSrc.replace("-rollover.jpg", ".jpg");
						  $(this).attr('src', thisRolloutSrc);

					  }
			}
			
	  });



	   $('.rw_img_rollover_png').mouseover(function () {
	   
			  var viewportWidth = $(window).width();

					  if (viewportWidth > '567') {

							var thisSrc = $(this).attr('src');

							if (thisSrc.indexOf("-rollover.png") < 0) {

								//find the . in the extension and go back three letters and place a 2



								var thisRolloverSrc = thisSrc.replace(".png", "-rollover.png");
								$(this).attr('src', thisRolloverSrc);

					  		}
			 		 }

	  });

	  $('.rw_img_rollover_png').mouseout(function () {
	  
			var viewportWidth = $(window).width();

			if (viewportWidth > '567') {

				  var thisSrc = $(this).attr('src');

				  if (thisSrc.indexOf("-rollover.png") > 0) {

						//find the . in the extension and go back three letters and place a 2
						var thisRolloutSrc = thisSrc.replace("-rollover.png", ".png");
						$(this).attr('src', thisRolloutSrc);

				  }

			}
		  
	  });


  	 $('#sp_get_the_recipe').mouseover(function () {
	 
			var viewportWidth = $(window).width();

			if (viewportWidth > '567') {

				  var thisStyle = $('.sp_bkg_change_rollover').attr('style');

				  if (thisStyle.indexOf("-rollover.jpg") < 0) {

						  //find the . in the extension and go back three letters and place a 2

						  var thisRolloverStyle = thisStyle.replace(".jpg", "-rollover.jpg");
						  $('.sp_bkg_change_rollover').attr('style', thisRolloverStyle);

				  }

			}

	  });

	  $('#sp_get_the_recipe').mouseout(function () {
	  
			  var viewportWidth = $(window).width();

			  if (viewportWidth > '567') {

					var thisStyle = $('.sp_bkg_change_rollover').attr('style');

					if (thisStyle.indexOf("-rollover.jpg") > 0) {

							//find the . in the extension and go back three letters and place a 2
							var thisRolloutStyle = thisStyle.replace("-rollover.jpg", ".jpg");
							$('.sp_bkg_change_rollover').attr('style', thisRolloutStyle);

					}

			  }
			
	  });
	  
};/*end of sp_rolloverControll();*/

sp_rolloverControll();



/********
START REVEAL OPEN THING
*******/



$(".rw_faq_q").click(function () {$(this).nextAll(".rw_faq_a").first().fadeToggle();});

$(".rw_template_revealer").click(function () {$(this).nextAll(".rw_template_revealed").first().fadeToggle();});
$(".rw_template_new_revealer").click(function () {$(this).nextAll(".rw_template_revealed").first().fadeToggle();});



/********
END REVEAL OPEN THING
*******/







	
	$(window).resize(function(){
		rw_logo_control();
		rw_font_perc_listen_global();
		/*sp_rolloverControll();
		sp_font_size_update();*/
	});//close resize
	
	
	
	
	
	
	
});//close window ready




$(window).load(function(){

		
/***************************** 
RW MATCH HEIGHTS OF DIVS  
******************************/


var rw_collect_hts = new Array();

//collect and push all heights of the divs with the rw_ht_match class

$('.rw_ht_match').each(function(index){
	//alert($(this).height());
	rw_collect_hts.push($(this).height());
	});

//Math.max will only apply to numbers in a comma delimited list. An array is of type array and will not work
//to get around that, use the following to APPLY the math.max function to an array type
var rw_highest_number = Math.max.apply(Math, rw_collect_hts); 


	
$('.rw_ht_match').css({height:rw_highest_number+'px'});
	
	

/***************************** 
SP PRODUCT DROPDOWN  
******************************/
$('.sp_input_field').change(function() {
  var url = $(this).val();
  window.location = url;
});


	/***************************** 
	SP HOME PAGE FEATURE MODULE GO BUTTON HOVER HANDLE  
	
	$('#sp_feature_module_link').mouseover(function() {$('#rw_feature_module').css('background-image','url(/images/uploads/assets/home-module-paper-bg-1200-rollover.png)')});

	$('#sp_feature_module_link').mouseout(function() {$('#rw_feature_module').css('background-image','url(/images/uploads/assets/home-module-paper-bg-1200.png)')});
	******************************/

/***
$('#sp_products_nav').mouseover(function(){$('#sp_product_dd').slideDown();});

$('#sp_products_nav').mouseout(function(){$('#sp_product_dd').slideUp();});
***/

$('#sp_products_nav')
	.mouseover(function(){$('#sp_product_dd').slideDown();})	
	
	.mouseout(function(){
        window.t = setTimeout(function() {$('#sp_product_dd').slideUp();}, 1500);
});

$('#sp_product_dd').mouseover(function(){$(this).show();});




$('#sp_recipes_nav').mouseover(function(){$('#sp_recipes_dd').slideDown();});

$('#sp_recipes_nav').mouseout(function(){$('#sp_recipes_dd').slideUp();});


$('#sp_commitment_nav').mouseover(function(){$('#sp_commitment_dd').slideDown();});

$('#sp_commitment_nav').mouseout(function(){$('#sp_commitment_dd').slideUp();});


$('#sp_media_nav').mouseover(function(){$('#sp_media_dd').slideDown();});

$('#sp_media_nav').mouseout(function(){$('#sp_media_dd').slideUp();});






});//close window load





