window.addEvent('domready', function(){
	// if this href doesn't match the parent container, we're in an iframe
	if(!(parent.location.href == window.location.href)) {
		$(window.document.html).setStyle('overflow','hidden');
		
		if(parent.window.box.autoSize) {
			var newDimensions = $('content').getCoordinates(); // overlay dimensions
			var openContainer = $(parent.document.body).getElement('.MultiBoxContainer');
			var initialOpenDimensions = openContainer.getCoordinates(); // parent dimensions
			var openContainerBorder = openContainer.getStyle('border-width').replace(/px/g,'').split(' '); // get padding-left/right
			var openDimensionsX = initialOpenDimensions.width - openContainerBorder[0] - openContainerBorder[2]; // default open width
			var openDimensionsY = initialOpenDimensions.height - openContainerBorder[1] - openContainerBorder[3]; // default open height
			var newCoordinatesLeft = ((parent.window.getScroll().x + (parent.window.getSize().x / 2)) - (newDimensions.width / 2));
			var newCoordinatesTop = (parent.window.getScroll().y + 20);
		
			// animate current dimensions to new dimensions and center
			$(parent.document.body).getElement('.MultiBoxContainer').setStyle("overflow", "");
			var fx = new Fx.Elements($$(parent, $(parent.document.body).getElements('.MultiBoxContainer'), $(parent.document.body).getElements('iframe[id^=iFrame]')), {
				onComplete: function(){
					parent.window.box.contentEffects.start({ 'opacity': 1 });
				}
			}).start({
				'0': { 'width': [openDimensionsX,newDimensions.width], 'height': [openDimensionsY,newDimensions.height], 'left': [initialOpenDimensions.left, newCoordinatesLeft], 'top': [initialOpenDimensions.top, newCoordinatesTop] },
				'1': { 'width': [openDimensionsX,newDimensions.width], 'height': [openDimensionsY,newDimensions.height], 'left': [initialOpenDimensions.left, newCoordinatesLeft], 'top': [initialOpenDimensions.top, newCoordinatesTop] }
			});
			
			var fx2 = new Fx.Elements($(parent.document.body).getElements('.MultiBoxContent')).start({
				'0': { 'width': [openDimensionsX,newDimensions.width], 'height': [openDimensionsY,newDimensions.height]}
			});
		}
		else {
			parent.window.box.contentEffects.start({ 'opacity': 1 });			
		}
		// grab back button
		if($('back')) {
			$('back').addEvent('click',function(e){
				new Event(e).stop();
				// calls parent window box.close
				parent.window.box.close();
			});
		}
	}
	
	if($('cbSpecialOffers')) {
		// array of offer/update checkboxes
		var offerInputs = $('special-offers-select').getElements('input');
		offerInputs.set('disabled','true'); // no user interaction onload
		// array of corresponding labels
		var offerLabels = $('special-offers-select').getElements('label')
		offerLabels.each(function(el){ el.setStyle('color','#aaa') }); // gray them out (disabled)
		$('cbSpecialOffers').addEvent('click',function(){
			// if the input#special-offers gets checked
			if(this.get('checked')) {
				// enable inputs/labels
				offerInputs.removeProperty('disabled');
				offerLabels.each(function(el){ el.setStyle('color','#000000') });
			} else {
				// disable inputs/labels
				offerInputs.set('disabled','true');
				offerInputs.removeProperty('checked');
				offerLabels.each(function(el){ el.setStyle('color','#AAAAAA') });
			}
		});
	}

	if($('back-link')) {
		$('back-link').addEvent('click',function(e){
				new Event(e).stop();
				if(parent.location.href == this.get('href'))
				{
					history.go(-1);
				} else {
					parent.window.box.close();
				}
		});
	}

	if($('back-click')) {
		$('back-click').addEvent('click',function(e){
				new Event(e).stop();
				if(parent.location.href == this.get('href'))
				{
					history.go(-1);
				} else {
					parent.location.href=this.get('href');
					parent.window.box.close();
				}
		});
	}
	
	if($('back-clickView')) {
		$('back-clickView').addEvent('click',function(e){
				new Event(e).stop();
					parent.location.href=this.get('href');
					parent.window.box.close();
		});
	}

});
