window.addEvent('domready', function() {
	var myAccordion = new Accordion($$('.tn'), $$('.sn'), {
		display: -1,
		alwaysHide: true
	});
	
	if (typeof(window['cat']) != "undefined")
	{
		if (cat == 'baby') { 
			window.setTimeout(function() {myAccordion.display(0)}, 1000);
		}
		else if (cat == 'kids') {
			window.setTimeout(function() {myAccordion.display(1)}, 1000);
		}
		else if (cat == 'me') {
			window.setTimeout(function() {myAccordion.display(2)}, 1000);
		}
	}
	
	if ($('pad') != null)
	{
		var pad = $('pad').getStyle('height');
		pad = Math.round(pad.substring(0, pad.length - 2));
		$('page').setStyle('min-height', (pad + 85) + 'px');
	}
	
	if ($('lstDimension1') != null)
	{
		bindDimension1();
	}
	
	topnavMouseOvers();
	
	flowProducts();
	
	if ($('txtSearch') != null)
	{
		$('txtSearch').addEvent('focus', function() {
			if (this.value == 'Search')
			{
				this.value = '';
			}
		});
		$('txtSearch').addEvent('blur', function() {
			if (this.value == '')
			{
				this.value = 'Search';
			}
		});
	}
	
	if ($('hideSubNav') != null)
	{
		if ($('hideSubNav').value == 'yes')
		{
			$('subcat').setStyle('display', 'none');
			$('catintro').setStyle('padding-right', '0');
		}
	}
});

function topnavMouseOvers() {
	var navs = $$('#fl_nav img');
	navs.each(function(item, index) {
		item.addEvent('mouseover', function() {
			var img = item;
			var src = img.getProperty('src');
			img.setProperty('old_src', src);
			img.setProperty('src', src.substring(0, src.indexOf('.png')) + '-o.png');
		});
		item.addEvent('mouseout', function() {
			var img = item;
			img.setProperty('src', img.getProperty('old_src'));
		});
	});
}

function bindDimension1() {
	dd = $('lstDimension1');
	dd.addEvent('change', function() {
		sel = dd[dd.selectedIndex].value;
		if (sel.indexOf('\\') > 0)
		{
			price = Number($('hidRetailPrice').value);
			total = Number(price) + Number(sel.substring(sel.indexOf('\\')+1));
			total = Math.ceil(total*100)/100;
			if (total % 1 == 0)
			{
				total = total + '.00';
			}
			$('txtPrice').set('html', '&pound;' + total);
		}
		else
		{
			price = $('hidRetailPrice').value;
			$('txtPrice').set('html', '&pound;' + price);
		}
	});
}

DoSifr();

function DoSifr() {
	var kk = {
		src: '/sifr/edwardian-script-itc.swf'
	};
	
	sIFR.delayCSS = true;
	sIFR.useDomContentLoaded = false;
	sIFR.activate(kk);
	
	sIFR.replace(kk, {selector: 'h2', wmode: 'transparent', css: '.sIFR-root {padding-bottom: -10px;}'});
	sIFR.replace(kk, {selector: 'h4', wmode: 'opaque', css: '.sIFR-root {}'});
	sIFR.replace(kk, {selector: 'h1', wmode: 'opaque', css: '.sIFR-root {}'});
	sIFR.replace(kk, {selector: 'h5.kk', wmode: 'transparent', css: '.sIFR-root {text-align: center;}'});

}

function flowProducts() {
	if ($('subcat') != null)
	{
		var subcat = $('subcat');
		var intro = $('catintro');
		
		var pl = intro.getStyle('height');
		pl = Math.round(pl.substring(0, pl.length - 2)) + 210;

		var ps = subcat.getStyle('height');
		ps = Math.round(ps.substring(0, ps.length - 2));
		
		var browserAdd = Browser.Engine.trident ? 47 : 45;
		
		if (ps > pl + browserAdd)
		{
			subcat.setStyle('height', ps + 196 + browserAdd + (pl - ps) + browserAdd);
		}
		else
		{
			if ((pl + browserAdd) > ps)
			{
				subcat.setStyle('height', ps + (pl - ps) + browserAdd);
			}
		}
	}
}

function copyDelivery() {
	if ($('UseCustomer').checked)
	{
		if ($('Repeater1_ctl00_lblForename') == null)
		{
			$('txtForename').value = $('lblForename').get('text');
			$('txtSurname').value = $('lblSurname').get('text');
			$('txtAddress1').value = $('lblAddress1').get('text');
			$('txtAddress2').value = $('lblAddress2').get('text');
			$('txtTown').value = $('lblTown').get('text');
			$('txtCounty').value = $('lblCounty').get('text');
			$('txtPostcode').value = $('lblPostcode').get('text');
			$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', 0);
			$$('#CountrySelect1_ddCountrySelect option').each(function(item, index) {
			    if (item.text == $('lblCountry').get('text'))
			    {
			        item.setProperty('selected', 'selected');
			        //$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', index);
			    }
			    else
			    {
			        item.setProperty('selected', '');
			    }
			});
		}
		else
		{
			$('txtForename').value = $('Repeater1_ctl00_lblForename').get('text');
			$('txtSurname').value = $('Repeater1_ctl00_lblSurname').get('text');
			$('txtAddress1').value = $('Repeater1_ctl00_lblAddress1').get('text');
			$('txtAddress2').value = $('Repeater1_ctl00_lblAddress2').get('text');
			$('txtTown').value = $('Repeater1_ctl00_lblTown').get('text');
			$('txtCounty').value = $('Repeater1_ctl00_lblCounty').get('text');
			$('txtPostcode').value = $('Repeater1_ctl00_lblPostcode').get('text');
			$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', 0);
			$$('#CountrySelect1_ddCountrySelect option').each(function(item, index) {
			    if (item.text == $('Repeater1_ctl00_lblCountry').get('text'))
			    {
			        item.setProperty('selected', 'selected');
			        //$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', index);
			    }
			    else
			    {
			        item.setProperty('selected', '');
			    }
			});
		}
	}
}