//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Weber Holiday Recipe JS Functions
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

document.observe("dom:loaded", function() {
										
	if($('next-arrow')){	 
		$('next-arrow').observe('click', toggleRecipesLeft);
	}
	
	if($('prev-arrow')){	 
		$('prev-arrow').observe('click', toggleRecipesRight);
	}

});

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Main Recipe Toggle Functions
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function toggleRecipesLeft(event){
	
	event.stop();
	element = Event.element(event);
	
	if($('ham-recipe-content').getStyle('display') != 'none'){
		
		var currentRecipe = $('ham-recipe-content');
		var nextRecipe = $('steak-recipe-content');
		
		var currentImage = $('ham-recipe-image');
		var nextImage = $('steak-recipe-image');
		
	}else if($('turkey-recipe-content').getStyle('display') != 'none'){
		
		var currentRecipe = $('turkey-recipe-content');
		var nextRecipe = $('ham-recipe-content');
		
		var currentImage = $('turkey-recipe-image');
		var nextImage = $('ham-recipe-image');
		
	}else if($('steak-recipe-content').getStyle('display') != 'none'){
		
		var currentRecipe = $('steak-recipe-content');
		var nextRecipe = $('turkey-recipe-content');
		
		var currentImage = $('steak-recipe-image');
		var nextImage = $('turkey-recipe-image');
		
	}else{
		
		return false;
	}
	
	new Effect.Fade(currentRecipe, {from: 1.0, to: 0, duration: 0.5, queue: { position: 'end', scope: 'recipe', limit: 2 }, afterFinish:function(){
			
			currentRecipe.hide();
			Effect.Appear(nextRecipe, {duration: 1.0, queue: { position: 'end', scope: 'recipe', limit: 2 }});																														  
																																		  
	}});
	
	new Effect.Fade(currentImage, {from: 1.0, to: 0, duration: 0.5, queue: { position: 'end', scope: 'recipe-image', limit: 2 }, afterFinish:function(){
			
			currentImage.hide();
			Effect.Appear(nextImage, {duration: 1.0, queue: { position: 'end', scope: 'recipe-image', limit: 2 }});																														  
																																		  
	}});
	
}

function toggleRecipesRight(event){
	
	event.stop();
	element = Event.element(event);
	
	if($('turkey-recipe-content').getStyle('display') != 'none'){
		
		var currentRecipe = $('turkey-recipe-content');
		var nextRecipe = $('steak-recipe-content');
		
		var currentImage = $('turkey-recipe-image');
		var nextImage = $('steak-recipe-image');
		
	}else if($('steak-recipe-content').getStyle('display') != 'none'){
		
		var currentRecipe = $('steak-recipe-content');
		var nextRecipe = $('ham-recipe-content');
		
		var currentImage = $('steak-recipe-image');
		var nextImage = $('ham-recipe-image');
		
	}else if($('ham-recipe-content').getStyle('display') != 'none'){
		
		var currentRecipe = $('ham-recipe-content');
		var nextRecipe = $('turkey-recipe-content');
		
		var currentImage = $('ham-recipe-image');
		var nextImage = $('turkey-recipe-image');
		
	}else{
		
		return false;
	}
	
	new Effect.Fade(currentRecipe, {from: 1.0, to: 0, duration: 0.5, queue: { position: 'end', scope: 'recipe', limit: 2 }, afterFinish:function(){
			
			currentRecipe.hide();
			Effect.Appear(nextRecipe, {duration: 1.0, queue: { position: 'end', scope: 'recipe', limit: 2 }});																														  
																																		  
	}});
	
	new Effect.Fade(currentImage, {from: 1.0, to: 0, duration: 0.5, queue: { position: 'end', scope: 'recipe-image', limit: 2 }, afterFinish:function(){
			
			currentImage.hide();
			Effect.Appear(nextImage, {duration: 1.0, queue: { position: 'end', scope: 'recipe-image', limit: 2 }});																														  
																																		  
	}});
	
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Email Shopping List Ajax Functions
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function initEmailForm(){
	
	if($('send-shopping-list')){
		$('send-shopping-list').observe('click', sendShoppingList);	
	}
	
}

function sendShoppingList(event){
	
	//event.stop();
	
	$('shopping-list-form').request({
		onComplete: function(transport){
			
				//drop in new comment
				Effect.Fade($('email-form-wrapper'), { duration: .5, afterFinish:function() {
					
					Effect.Appear($('email-thankyou'), { duration: .75, delay: 0});
					
				}});
				
		//end request complete
		}
	//end request
	});
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Modal Window Setup Functions
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function setupZoom(){
	var my_div = document.createElement('div');
	my_div.id="ajaxResult";
	document.body.appendChild(my_div);
	FancyZoomBox.init();
	$$(".isModal").each(function(el) { new FancyZoom(el); });
	//$(document).observe('zoom:zoomLoaded', initTabs);
	$(document).observe('emailForm:emailFormLoaded', initEmailForm);
}

function popZoom(element, url, params, customEvent){
			element = $(element);
			
			if(!customEvent){
				customEvent = 'noEvent:nothingLoaded';
			}
			new FancyZoomPop(element, url, params, customEvent);
		
}

// SwingTo (adapted from "BackEaseOut")
Effect.Transitions.SwingTo = function(pos) {
    var s = 1.70158;
    return (pos-=1)*pos*((s+1)*pos + s) + 1;
};


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// WSP JS 20091103
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function printFriendly(elementId) {
    var printArea = document.getElementById(elementId);
    //printArea.innerHTML = printArea.innerHTML.replace('<p class="previous_page"><a href="javascript:history.back();" onclick="javascript:history.back();" onmouseover="javascript:status=''; return true;" title="To Previous Page"><span class="replace">To Previous Page</span></a></p>', '');
    //printArea.innerHTML = printArea.innerHTML.replace('<p class="print_page"><a href="javascript:printFriendly(\'holiday_print\')" onclick="javascript:printFriendly(\'holiday_print\')" title="Print This Page" class="isModal">Print this page</a></p>', '');
    var printWindow = window.open('', '', 'left=275,top=215,width=650,height=700,scrollbars=1,location=0,resizable=0');

    printWindow.document.write(printArea.innerHTML);
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();

}