function openSpecials() {
	window.open('/specials.html', 'specials', 'width=400,height=700,scrollbars=yes');
}

var contact = {
	show:function() {
		contact.positionElements();
		Effect.Appear('contact', {duration:0.5});
		Effect.Appear('shield', {to:0.8,duration:0.5});
		$('shield').observe('click',contact.close);
	},
	
	submit: function(form) {
		
	},
	
	positionElements:function() {
		var shield = $('shield');
		var dialog = $('contact');
		var pageSize = document.viewport.getDimensions();
		var scroll = document.viewport.getScrollOffsets();
		
		shield.setStyle({width: $(document.body).getWidth() + 'px', height: $(document.body).getHeight() + 'px'});
		shield.setOpacity(0.8);
		dialog.setStyle({
			left: ((pageSize.width)/2) + scroll.left - (dialog.getWidth()/2) + 'px',
			top: ((pageSize.height)/2) + scroll.top - (dialog.getHeight()/2) + 'px'
		});
	},
	
	close:function() {
		$('contact').hide();
		$('shield').hide();
	}
}

var slideshow = {
	current: 1,
	rotate_interval: null,
	is_rotating: false,
	
	show:function(id) {
		slideshow.stop();
		slideshow.changeImg(id);
	},
	
	changeImg:function(id) {
		var newImg = $('ss_'+id);
		var newSize = newImg.getHeight();
		var oldImg = $('ss_'+slideshow.current);
		var oldSize = oldImg.getHeight();
		
		// Set the photo container's height to the larger of the 2 image heights temporarily to
		// prevent the content below from jumping around during the brief time when no image is displayed
		var big = $('photo_view');
		big.setStyle({height: (newSize>oldSize ? newSize : oldSize) + 'px'});
		
		Effect.Fade(oldImg, {duration:0.25, queue:'front'});
		Effect.Appear(newImg, {duration:0.25, queue:'end', afterFinish: function() {
			big.setStyle({height: 'auto'}); // Set photo container's height back to auto
		}});
		
		$('ss_link_'+slideshow.current).removeClassName('active');
		$('ss_link_'+id).addClassName('active');
		slideshow.current = id;
	},
	
	beginRotate:function() {
		slideshow.rotate_interval = window.setInterval(slideshow.rotate, 5000);
		slideshow.is_rotating=true;
	},
	
	rotate:function() {
		var newImg = slideshow.current+1;
		if($('ss_'+newImg) == null) newImg=1;
		slideshow.changeImg(newImg);
	},
	
	pause:function() {
		window.clearInterval(slideshow.rotate_interval);
	},
	
	resume:function() {
		if(slideshow.is_rotating)
			slideshow.beginRotate();
	},
	
	stop: function() {
		window.clearInterval(slideshow.rotate_interval);
		slideshow.is_rotating = false;
	}
}

var Forms = {
	submit:function(f) {
		var form = $(f);
		form.request({
			parameters: { ajax:'true'},
			onComplete: function(r){ Forms.done(f,r); }
		});
		Forms.clearErrors();
		$('submit-cont').addClassName("busy");
	},
	
	done: function(form, request) {
		var result = request.headerJSON;
		if(typeof result.error == "object") {
			for(var i=0; i<result.error.length; i++) {
				var e = $('inp-'+result.error[i]).insert("<span class=\"err-warning\" style=\"display:none\"><span>Required</span></span>");
				e = e.getElementsByClassName('err-warning')[0];
				Effect.Appear(e);
			}
			$('submit-cont').insert('<div id="form-err">Please fill out the required fields above.</div>');
		}
		else if(result.error==true) {
			$('submit-cont').insert('<div id="form-err">Error submitting form. Please try again.</div>');
		}
		else {
			$('submit-cont').insert('<div id="form-success">Form submitted successfully!</div>');
			window.setTimeout(function(){Effect.Fade('form-success')}, 5000);
			Form.reset(form);
			Forms.clearErrors();
		}
		$('submit-cont').removeClassName("busy");
	},
	
	clearErrors:function() {
		var e = $$('.err-warning');
		for(var i=0; i<e.length; i++) {
			Element.remove(e[i]);
		}
		if($('form-err')) $('form-err').remove();
	}
}
