﻿
function bottom_menu() {
	var h = Math.max($('contentLeft').getDimensions().y, $('contentMid').getDimensions().y, $('contentRight').getDimensions().y);
	// h += 0;
	
	$('contentRight').setStyle('min-height', h);
	
	/*$('footer').position({
		relativeTo: $('contentDIV'),
		position:  'top',
		edge: 'top',
		offset: { y: h }
	});*/
}


function subnav() {
	$$('.subnav').each(function (ul) {

		//	var s = new Fx.Slide(ul);

		var parent_div = $(ul.getParents('div.sliding')[0]);
		var parent_li = $(ul.getParents('li')[0]);

		var a = $(parent_li.getChildren('a')[0]);
		var yOff = (a.get('text') == 'FAQ and Rental Terms') ? 3 : 8;

		function align(div, li) {
			div.position({
				relativeTo: li,
				position: { x: 'left', y: 'bottom' },
				edge: { x: 'left', y: 'top' },
				offset: { x: -8, y: yOff }
			});
		}

		align(parent_div, parent_li);

		function firstTime() {
			ul.hide();
			parent_div.removeClass('none');
			ul.show();
		}


		a.addEvent('click', function (e) {
			e.stop();

			function tog() {
				(ul.getStyle('display') == 'block') ? ul.hide() : ul.show();
				align(parent_div, parent_li);
			}

			(parent_div.hasClass('none')) ? firstTime() : tog();
		});
	});
}



function Locations_updateDIV() {
	if ($('ZIP_textBox') && $chk($('ZIP_textBox').value.toInt())) {
		var req = new Request.HTML({
			url: '/Home/Locations_menu_filtered',
			onSuccess: function (responseTree, responseElements, responseHTML, responseJavaScript) {
				$('Locations_updateDIV').set('html', responseHTML);
			}
		}).post({ zipPart: $('ZIP_textBox').value });
	}
}



var max_brand_logo_width = 70;

function brand_logos() {
	var path = '/Content/images/brand/';
	var files = [
		path + 'Britax.jpg',
		path + 'Delta.gif',
		path + 'Baby Trend.jpg',
		path + 'Peg Perego.png',
		path + 'Graco.gif',
		path + 'Bugaboo.jpg',
		path + 'The First Years.png',
		path + 'BOB.jpg',
		path + 'Safety 1st.gif',
		path + 'Evenflo.jpg'
	];

	var links = [
		'http://www.britax.com',
		'http://www.deltaenterprise.com',
		'http://www.babytrend.com',
		'http://www.pegperego.com',
		'http://www.gracobaby.com',
		'http://www.bugaboo.com',
		'http://www.thefirstyears.com',
		'http://www.bobstrollers.com',
		'http://www.safety1st.com',
		'http://www.evenflo.com'
	];

	var brand_logo_imgs = [];
	var r1, a;

	var ai = new Asset.images(files, {
		onProgress: function (i) {
			(this.width > max_brand_logo_width) ? r1 = max_brand_logo_width / this.width : r1 = 1;

			this.width = this.width * r1;
			this.height = this.height * r1;
			brand_logo_imgs[i] = this;
		},
		
		onComplete: function () {
			brand_logo_imgs.each(function (img, i) {
				a = new Element('a', { href: links[i], target : '_blank' });
				a.grab(img);
				a.inject($('brand_logos'));
			});
		}
	});
}





window.addEvent('domready', function () {
	brand_logos();
	bottom_menu();
	subnav();
    
	$$('.locImg').each(function (img) {
		img.addEvent('load', function (event) {
			bottom_menu();
		});
	});
});
