/**
 * Form Box Function
 */
var formbox = function() {
	var $ = window.jQuery;
	var boxID = '#formbox';
	var backID = '#formboxBackground';
	var form = '#formboxForm';
	var content = '#formboxContent';
	var inTrans = false;
	var index = 0;
	var isIE6 = $.browser.msie && $.browser.version == '6.0';
	speed = 500;

	function init() {
		$(boxID+' #formboxClose').click(hideBox);
		if($(backID).length < 1) {
			$(boxID).before($('<div id="' + backID.substr(1) + '"/>'));
			var css = {background: '#462e13', cursor: 'pointer', display: 'none', left: 0, opacity: .52, top: 0};
			$.extend(css, isIE6 ? {height: $('#container').height() + 'px', position: 'absolute', width: $('body').width() + 'px'} : {bottom: 0, right: 0, position: 'fixed'});
			$(backID).click(hideBox).css(css);
		}
	}
	$(init);

	function showBox() {
		$(boxID).fadeIn(speed,function(){
		});
		$(backID).fadeIn(speed);
	}

	function hideBox() {
		$(boxID).fadeOut(speed,function(){
			$(content).html('');
			$(form).fadeIn('fast');
		});
		$(backID).fadeOut(speed);
	}

	function trans(newIndex) {
		if(inTrans) return;
		inTrans = true;
		$(boxID+' .item:eq('+newIndex+')').fadeIn(speed);
		$(boxID+' .item:eq('+index+')').fadeOut(speed, function(){inTrans = false;});
		index = newIndex;
	}

	return {
		show: showBox,
		hide: hideBox
	};
};
