//Innerfade
(function($){$.fn.innerfade=function(options){return this.each(function(){$.innerfade(this,options);});};$.innerfade=function(container,options){var settings={'animationtype':'fade','speed':'normal','type':'sequence','timeout':2000,'containerheight':'auto','runningclass':'innerfade','children':null};if(options)
$.extend(settings,options);if(settings.children===null)
var elements=$(container).children();else
var elements=$(container).children(settings.children);if(elements.length>1){$(container).css('position','relative').css('height',settings.containerheight).addClass(settings.runningclass);for(var i=0;i<elements.length;i++){$(elements[i]).css('z-index',String(elements.length-i)).css('position','absolute').hide();};if(settings.type=="sequence"){setTimeout(function(){$.innerfade.next(elements,settings,1,0);},settings.timeout);$(elements[0]).show();}else if(settings.type=="random"){var last=Math.floor(Math.random()*(elements.length));setTimeout(function(){do{current=Math.floor(Math.random()*(elements.length));}while(last==current);$.innerfade.next(elements,settings,current,last);},settings.timeout);$(elements[last]).show();}else if(settings.type=='random_start'){settings.type='sequence';var current=Math.floor(Math.random()*(elements.length));setTimeout(function(){$.innerfade.next(elements,settings,(current+1)%elements.length,current);},settings.timeout);$(elements[current]).show();}else{alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');}}};$.innerfade.next=function(elements,settings,current,last){if(settings.animationtype=='slide'){$(elements[last]).slideUp(settings.speed);$(elements[current]).slideDown(settings.speed);}else if(settings.animationtype=='fade'){$(elements[last]).fadeOut(settings.speed);$(elements[current]).fadeIn(settings.speed,function(){removeFilter($(this)[0]);});}else
alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');if(settings.type=="sequence"){if((current+1)<elements.length){current=current+1;last=current-1;}else{current=0;last=elements.length-1;}}else if(settings.type=="random"){last=current;while(current==last)
current=Math.floor(Math.random()*elements.length);}else
alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');setTimeout((function(){$.innerfade.next(elements,settings,current,last);}),settings.timeout);};})(jQuery);function removeFilter(element){if(element.style.removeAttribute){element.style.removeAttribute('filter');}}
// Document Ready

var prices = {
	'label' : 'Material',
	'values': {
		'vinyl-printing': 'Vinyl Printing',
		'banner-printing': 'Banner Printing',
		'poster-printing': 'Poster Printing'
	},
	'vinyl-printing': {
		'label': 'Vinyl Type',
		'id': 'vinyl-printing',
		'values': {
			'4-5-year-vinyl': '4-5 Year Vinyl',
			'5-7-year-vinyl': '5-7 Year Vinyl',
			'cast-vinyl': 'Cast Vinyl'
		},
		'4-5-year-vinyl': {
			'label': 'Finish',
			'id': '4-5-year-vinyl',
			'values': {
				'no-lam': 'No Laminate',
				'lam': 'Laminate'
			},
			'no-lam': {
				'sizes': {
					0: {
						'min': 0,
						'max': 5,
						'price': 29.95
					},
					1: {
						'min': 5,
						'max': 10,
						'price': 24.95
					},
					2: {
						'min': 10,
						'max': 10000,
						'price': 21.95
					}
				}
			},
			'lam': {
				'sizes': {
					0: {
						'min': 0,
						'max': 5,
						'price': 32.95
					},
					1: {
						'min': 5,
						'max': 10,
						'price': 27.95
					},
					2: {
						'min': 10,
						'max': 10000,
						'price': 24.95
						
					}
				}	
			}
		},
		'5-7-year-vinyl': {
			'label': 'Finish',
			'id': '5-7-year-vinyl',
			'values': {
				'no-lam': 'No Laminate',
				'lam': 'Laminate'
			},
			'lam': {
				'sizes': {
					0: {
						'min': 0,
						'max': 5,
						'price': 32.95
					},
					1: {
						'min': 5,
						'max': 10,
						'price': 27.95
					},
					2: {
						'min': 10,
						'max': 10000,
						'price': 24.95
						
					}
				}
			},
			'no-lam': {
				'sizes': {
					0: {
						'min': 0,
						'max': 5,
						'price': 39.95
					},
					1: {
						'min': 5,
						'max': 10,
						'price': 32.95
					},
					2: {
						'min': 10,
						'max': 10000,
						'price': 29.95
					}
				}	
			}
		},
		'cast-vinyl': {
			'label': 'Finish',
			'id': 'cast-vinyl',
			'values': {
				'no-lam': 'No Laminate',
				'lam': 'Laminate'
			},
			'lam': {
				'sizes': {
					0: {
						'min': 0,
						'max': 5,
						'price': 41.95
					},
					1: {
						'min': 5,
						'max': 10,
						'price': 36.95
					},
					2: {
						'min': 10,
						'max': 10000,
						'price': 33.95
						
					}
				}
			},
			'no-lam': {
				'sizes': {
					0: {
						'min': 0,
						'max': 5,
						'price': 51.95
					},
					1: {
						'min': 5,
						'max': 10,
						'price': 45.95
					},
					2: {
						'min': 10,
						'max': 10000,
						'price': 42.95
						
					}
				}	
			}
		}
	},
	'banner-printing': {
		'sizes': {
			0: {
				'min': 0,
				'max': 5,
				'price': 24.95
			},
			1: {
				'min': 5,
				'max': 10,
				'price': 22.95
			},
			2: {
				'min': 10,
				'max': 10000,
				'price': 20.95
			}
		}		
	},
	'poster-printing': {
		'label': 'Size',
		'id': 'poster-printing',
		'values': {
			'a2': 'A2',
			'a1': 'A1',
			'a0': 'A0'
		},
		'a2': { 'prices': 9.00 },
		'a1': { 'prices': 15.00 },
		'a0': { 'prices': 26.00 }
	}
};
var string = "prices";
var next = false;

$(document).ready(function() {
	$('#steps_images').innerfade({
		speed: 'slow',
		timeout: 3500,
		type: 'sequence',
		containerheight: '102px'
	});
	
	var have_width_height = false;
	var first_done = false;
	
	$('#width, #height').keyup(function() {
		
		if ($('#width').val() > 0 && $('#height').val() > 0) { 
		
			have_width_height = true;
			
			if (!first_done)
			{
				$('#inital-select').removeAttr('disabled').data('string', string);
				$.each(prices.values, function(key, value) {
					$('#inital-select').append($('<option>').val(key).text(value));
				});
				$('#inital-select').change(function() {
					update_select(this);
				});
				first_done = true;
			}
			
		}
		else
		{
			have_width_height = false;
		}
	});

	function update_select(select)
	{
		var dont_remove = false;
		
		if ($(select).val() == "-----") { return false; }
		if ($(select).data('string') != null) { string = $(select).data('string'); }
		if ($(select).data('dont-remove') != null) { dont_remove = $(select).data('dont-remove'); }
		
		if (!dont_remove) {
			dont_remove = "#"+$(select).attr('id');
		} else {
			dont_remove = dont_remove + ", #"+$(select).attr('id');
		}
		
		$('#calculator select:not('+dont_remove+')').parents('.extra-select').remove();
		$('#price-from-container').hide();
		
		var new_string = string + "['" + $(select).val() + "']";
		next = eval(new_string);
		if (next.values != null)
		{
			$('#calculator .material-container:last').after($('<div class="material-container extra-select">').append(
				$('<label>').attr('for', next.id).text(next.label)
			).append(
				$('<select class="material">').attr('id', next.id).data('string', new_string).data('dont-remove', dont_remove).append($('<option>').val('-----').text('-----'))
			)).append('<br style="clear:both;" />');
			
			$.each(next.values, function(key, value) {
				$('#'+next.id).append($('<option>').val(key).text(value));
			});
			
			$('#'+next.id).change(function() { update_select(this); });
		}
		
		if (next.sizes != null || next.prices != null) { update_price(next); }
		
	}
	
	function update_price()
	{
		if (next.prices != null)
		{			
			$('#price-from').html("£" + parseFloat(next.prices).toFixed(2));
			$('#price-from-container').show();
			return true;
		}
		
		var size = get_sqm();
		$.each(next.sizes, function(loop_value) {
			loop_value = next.sizes[loop_value];
			if (size > loop_value.min && size <= loop_value.max)
			{
				$('#price-from').html("£" + parseFloat(loop_value.price * size).toFixed(2));
				$('#price-from-container').show();
			}
		});
		
	}
	
	function get_sqm() { return parseFloat(($('#width').val() / 1000) * ($('#height').val() / 1000)).toFixed(1); }

	$('#calculator button').click(function(e) {
		e.preventDefault();
		window.location = 'http://upload.uploadprints.co.uk';
		return false;
	});
	
});
// Cufon
Cufon.replace('h1', {textShadow: '1px -1px 1px rgba(0, 0, 0, 0.2)'})('h2', {hover: true})('h3', {hover: true})('#telephone');
