window.addEvent('domready', function() {
	
	helpSetup();

	var barbie = $('emailid');
	var orders = $('ordersid');
	var phil = $('philid');
	
	if( barbie != null ) {
		barbie.setText('barbie@hillstreetgrocer.com');
	}
	
	if( orders != null ) {
		orders.setText('orders@hillstreetgrocer.com');
	}
	
	if( phil != null ) {
		phil.setText('phil@hillstreetgrocer.com');
	}


	
	/* the Accordion */
	
	var tgl = $$('h2.accToggle');
	var sld = $$('ul.accSlide');
	
	var accordion = new Accordion(tgl, sld, {
			opacity: false,
			alwaysHide: true,
			duration: 200
	});
	
	/* switches for the tag displays */

	var relSwitch = $('relatedSwitch');
	
	if( relSwitch != null ) {
		relSwitch.addEvent('click', function() {
			if( $$('.minortag')[0].getStyle('display') == 'none' ) {
				$$('.minortag').setStyle('display', 'inline');
				relSwitch.setText('[less...]');
			}
			else {
				$$('.minortag').setStyle('display', 'none');
				relSwitch.setText('[more...]');
			}
			
			accordion.display(0).chain(function() {
				accordion.display(0);
			});
		});
	}
	
	var clSwitch = $('cloudSwitch');
	
	if( clSwitch != null ) {
		clSwitch.addEvent('click', function() {
			if( $('shortcloud').getStyle('display') == 'none' ) {
				$('shortcloud').setStyle('display', 'block');
				$('longcloud').setStyle('display', 'none');
				clSwitch.setText('[more...]');
			}
			else {
				$('shortcloud').setStyle('display', 'none');
				$('longcloud').setStyle('display', 'block');
				clSwitch.setText('[less...]');
			}
			
			var nCloud = tgl.length - 2;
		
			accordion.display(nCloud).chain(function() {
				accordion.display(nCloud);
			});
		});
	}
	
	
	/* misc */
	
	var bgimage = $('bgimage');
	
	if( bgimage != null ) { /* bgimage backgrounds must be 358px tall and around 400px wide. */
		var offset = window.getHeight() - 458;
		var bgposStr = '100% ' + offset + 'px';
		bgimage.setStyle('background-position', bgposStr);
		var bgimagepath = 'url("http://hillstreetgrocer.com/wp-content/themes/hsgtheme/images/bg/bg' 
								+ $random(1,9) + '.jpg")';
		bgimage.setStyle('background-image', bgimagepath);
	}
	
	var strips = $('strips');
	
	if( strips != null ) { /* set minimum height equal to screen size */
		var stripsSize = strips.getSize();
		if( stripsSize.size.y < window.getHeight() ) {
			strips.setStyle('height', window.getHeight());
		}
	} 
		
});

window.addEvent('resize', function() {

	var specArea = $('spec-area');
	
	if( specArea != null ) {
		var contentSize = $('content').getSize();
		var theSpace = window.getHeight() - contentSize.size.y - 122 - 40;
		var thePadding = theSpace - 200 - 10;
		if( thePadding > 0 ) { /* otherwise make people scroll down to see */
			$('content').setStyle('margin-bottom', thePadding);
		}	
	}

});
