/*
*	Print Recipes
*	Creates a JS interface for printing recipes in different formats
*	
*	Requires jQuery library (http://www.jquery.com)
*	
*	Taylan Pince (taylan@trapeze.com) - November 14, 2007
*/

if (typeof trapeze == 'undefined') trapeze = new Object();

trapeze.PrintRecipes = {
	
	card_default : 'full-page',
	card_types : {
		'full-page'			: {'title': 'Full Page', 'width': 'full', 'height': 'full'},
		'three-five-card'	: {'title': '3x5 Card', 'width': 432, 'height': 288},
		'four-six-card'		: {'title': '4x6 Card', 'width': 360, 'height': 216}
	},
	
	hide_step_images: false,
	
	all_types : function() {
		var all_types = "";
		for (var card_class in this.card_types) {
			all_types += card_class + " ";
		}
		return all_types;
	},
	
	switch_card : function(card_type) {
		$("body").removeClass(this.all_types()).addClass(card_type);
		$("#Options").find("li a").removeClass("active").filter("." + card_type).addClass("active");
	},
	
	increase_font_size: function(element){
	    var currentSize = parseFloat(element.css('font-size'));
	    
	    element.css('font-size', currentSize + (currentSize * .2));
	},
	
	decrease_font_size: function(element){
	    var currentSize = parseFloat(element.css('font-size'));
	    
	    element.css('font-size', currentSize - (currentSize * .2));
	},
	
	init : function() {
		var html = '<ul>';
		for (var card_class in this.card_types) {
			html += '<li><a href="javascript:void(0);" onclick="trapeze.PrintRecipes.switch_card(\'' + card_class + '\')" class="' + card_class + '">' + this.card_types[card_class].title + '</a></li>';
		}
		html += '</ul>';
		$("#Options").append(html);
		this.switch_card(this.card_default);
		
		// Hide Images
		html = '<div class="noprint extended_option"><a class="hide_images" href="javascript:void(0)">Hide Photos</a></div>';
		$("#Options").append(html);
		
		$('.hide_images').click(function(){
		    this.hide_step_images = !this.hide_step_images;
		    
		    if(this.hide_step_images) {
		        $('img.step_image').fadeOut();
		        $('.hide_images').text('Show Photos');
		    } else {
		        $('img.step_image').fadeIn();
		        $('.hide_images').text('Hide Photos');
		    }
		});
		
		// Font resizer
		html = '<div class="noprint extended_option">Font Size: '
		html += '<a class="increase_font" href="javascript:void(0)">+A</a>';
		html += ' | ';
		html += '<a class="decrease_font" href="javascript:void(0)">-A</a>';
		html += '</div>';
		
		var increase_font_size = this.increase_font_size;
		var decrease_font_size = this.decrease_font_size;
		
		$("#Options").append(html);
		
		$('.increase_font').click(function(){
		    $.map($('.resizable'), function(element){
    		    increase_font_size($(element));
    	    });
    	    $.map($('.preparation-item p'), function(element){
    		    increase_font_size($(element));
    	    });
		});
		
		$('.decrease_font').click(function(){
		    $.map($('.resizable'), function(element){
    		    decrease_font_size($(element));
    	    });
    	    $.map($('.preparation-item p'), function(element){
    		    decrease_font_size($(element));
    	    });
		});
	}
	
}

$(function() {
	trapeze.PrintRecipes.init();
});