window.addEvent('domready', function() {
	CreateNavigation();
	CategoryNavigation();
	ShopperNavigation();
	RandomBg();
	
	if (window.location.pathname == '/product.aspx') {
		var theTips = new TipsX3($$('.tip'), {showDelay: 0});
	}
	
	if ($('sBtn') != null) {
		$('sBtn').addEvent('click', function() {
			doSearch();
		 });
	}
});

function RandomBg() {
	var bgs = "/images/bgs/";
	var bts = "/images/skins/";
	var bg = new Date();
	bg = (bg.getDate() % 9) + 1;
	$$('body')[0].setStyle('background-image', 'url(' + bgs + bg + '.jpg)');
	$$('.bs, .bs2, .bse').each(function(item) { item.setStyle('background-image', 'url(' + bts + bg + '_single.jpg)'); } );
	$$('.bb').each(function(item) { item.setStyle('background-image', 'url(' + bts + bg + '_triple.jpg)'); } );
}

DoSifr();

function DoSifr() {
	var nm = {
		src: '/sifr/nessie-maclay.swf'
	};

	sIFR.delayCSS = true;
	sIFR.useDomContentLoaded = false;
	sIFR.activate(nm);

	sIFR.replace(nm, {selector: 'span.nmc, p.nmc, li.nmc', wmode: 'opaque', css: '.sIFR-root {font-size: 14; text-align: center; } .sIFR-root a:hover {color: #990099; text-decoration: underline} .sIFR-root a {color: #990099; text-decoration: none}'});	
	sIFR.replace(nm, {selector: 'h4.nmc', wmode: 'opaque', thickness: '200', css: '.sIFR-root {text-align: center}'});
	sIFR.replace(nm, {selector: 'span.nm, p.nm, li.nm', wmode: 'opaque', css: '.sIFR-root {font-size: 14; } .sIFR-root a:hover {color: #990099; text-decoration: underline} .sIFR-root a {color: #990099; text-decoration: none}'});	
	sIFR.replace(nm, {selector: 'h4.nm', wmode: 'opaque', thickness: '200'});
	sIFR.replace(nm, {selector: 'h5.em', wmode: 'opaque', thickness: '50', css: '.sIFR-root {font-size: 11; text-align: right; } a:hover {color: #990099; text-decoration: none} a {color: #000000; text-decoration: none}'});
	sIFR.replace(nm, {selector: 'h1.nm', wmode: 'opaque', thickness: '50', css: '.sIFR-root {text-align: center; }'});
	sIFR.replace(nm, {selector: 'div.f-center', wmode: 'transparent', forceWidth: 'true', offsetTop: '9', thickness: '200', css: '.sIFR-root {text-align: center; font-size: 16; width: 100%} a:hover {color: #990099; text-decoration: none} a {color: #000000; text-decoration: none}'});
	sIFR.replace(nm, {selector: '.prodlink', wmode: 'opaque', thickness: '200', offsetTop: '9', css: '.sIFR-root {text-align: center; font-size: 16 } a:hover {color: #990099; text-decoration: none} a {color: #000000; text-decoration: none}'});
	sIFR.replace(nm, {selector: '.f-right', wmode: 'opaque', thickness: '200', css: '.sIFR-root {text-align: right; font-size: 20; text-decoration: none } a:hover {color: #990099; text-decoration: none} a {color: #000000; text-decoration: none}'});
	sIFR.replace(nm, {selector: 'p.nm2', wmode: 'transparent', css: '.sIFR-root {text-align: center; font-size: 13} a:hover {color: #990099; text-decoration: none} a {color: #990099; text-decoration: none}'});	
	sIFR.replace(nm, {selector: 'span.nm2', thickness: '200'});	
	sIFR.replace(nm, {selector: 'p.catinfo', wmode: 'opaque', css: '.sIFR-root {margin-right: 180; font-size: 14;} .sIFR-root a:hover {color: #990099; text-decoration: underline} .sIFR-root a {color: #990099; text-decoration: none}'});	
	sIFR.replace(nm, {selector: 'h4.catinfo', wmode: 'opaque', thickness: '200', css: '.sIFR-root {margin-right: 180; font-size: 14;}'});
	sIFR.replace(nm, {selector: 'p.f-center', wmode: 'opaque', css: '.sIFR-root {text-align: center; font-size: 13}'});
	sIFR.replace(nm, {selector: 'h4.f-center, span.f-center', wmode: 'transparent', thickness: '200', css: '.sIFR-root {text-align: center; font-size: 14}'});
	sIFR.replace(nm, {selector: '.hm', wmode: 'transparent', thickness: '200', css: '.sIFR-root {text-align: center; font-size: 16; width: 100%} a:hover {color: #990099; text-decoration: none} a {color: #000000; text-decoration: none}'});
}

function doSearch() {
	if ($('sSearch') != null) {
		window.location.href = '/search.aspx?q=' + urlEncode($('sSearch').value);
	}
}

function urlEncode(str) 
{ 
    regular = new RegExp("/","g"); 
    val = escape(str); 
    val = val.replace(regular,"%2F"); 
    return val; 
}

function CategoryNavigation() {
    var navs = $$("div#cats img");
	navs.each(function(item, index) {
		navs[index].addEvent('mouseout', function(){
			navs[index].setProperty('src', navs[index].getProperty('src').replace('a.gif', '.gif'));
			});
		navs[index].addEvent('mouseover', function(){
			navs[index].setProperty('src', '/images/categories/' + GetBaseName(navs[index].getProperty('src')) + "a.gif");
			});
	});
}

function toggleVis(sender) {
    var item = $(sender).getParent().getNext();
    if (item.getStyle("display") == "none") {
        var items = $$("div.BasketInfo");
        items.each(function(item, index) {
            items[index].setStyle("display", "none");
        });
        item.setStyle("display", "block");
    }
    else {
        item.setStyle("display", "none");
    }
}

function custInfo(id) {
	win = window.open('custinfo.aspx?id=' + id, 'custinfo', 'width=500,height=650,status=0,toolbar=0,location=0,menubar=0,directories=0');
}

function toggleShopper() {
	var items = $$("div#shopper div#items");
	if (items.getStyle("display") == "none") {
		items.setStyle("display", "block");
	}
	else {
		items.setStyle("display", "none");
	}
}

function togglePostit() {
	var target = $$("div#postit");
	if (target.getStyle("display") == "none") {
		target.setStyle("display", "block");
	}
	else {
		target.setStyle("display", "none");
	}
}

function togglePostService() {
	if (document.getElementById("Repeater3_ctl00_PostForMe_UseService").checked) {
		document.getElementById("Repeater3_ctl00_PostForMe_Name").disabled = false;
		document.getElementById("Repeater3_ctl00_PostForMe_Address").disabled = false;
		document.getElementById("Repeater3_ctl00_PostForMe_Message").disabled = false;
		$("Repeater3_ctl00_Quantity").value = 1;
		$("Repeater3_ctl00_Quantity").disabled = true;
	}
	else {
		document.getElementById("Repeater3_ctl00_PostForMe_Name").disabled = true;
		document.getElementById("Repeater3_ctl00_PostForMe_Address").disabled = true;
		document.getElementById("Repeater3_ctl00_PostForMe_Message").disabled = true;
		$("Repeater3_ctl00_Quantity").disabled = false;
	}
}

function ShopperNavigation() {
    var navs = $$("div#shopper div#items img");
	navs.each(function(item, index) {
		navs[index].addEvent('mouseout', function(){
			navs[index].setProperty('src', navs[index].getProperty('src').replace('-a.gif', '.gif'));
			});
		navs[index].addEvent('mouseover', function(){
			navs[index].setProperty('src', '/images/dropdown/' + GetBaseName(navs[index].getProperty('src')) + "-a.gif");
			});
	});
}

function CreateNavigation() {
	var navs = $$("div#topnav img");
	navs.each(function(item, index) {
		navs[index].addEvent('mouseout', function(){
			navs[index].setProperty('src', navs[index].getProperty('src').replace('_a', ''));
			});
		navs[index].addEvent('mouseover', function(){
			navs[index].setProperty('src', navs[index].getProperty('src').replace('.gif', '_a.gif'));
			});
	});
}

function GetBaseName(filename) {
	return filename.substring(filename.lastIndexOf('/')+1, filename.lastIndexOf('.'));
}

function copyDelivery() {
	if ($('UseCustomer').checked)
	{
		if ($('Repeater1_ctl00_lblForename') == null)
		{
			$('txtForename').value = $('lblForename').getText();
			$('txtSurname').value = $('lblSurname').getText();
			$('txtAddress1').value = $('lblAddress1').getText();
			$('txtAddress2').value = $('lblAddress2').getText();
			$('txtTown').value = $('lblTown').getText();
			$('txtCounty').value = $('lblCounty').getText();
			$('txtPostcode').value = $('lblPostcode').getText();
			$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', 0);
			$$('#CountrySelect1_ddCountrySelect option').each(function(item, index) {
			    if (item.getText() == $('lblCountry').getText())
			    {
			        item.setProperty('selected', 'selected');
			        //$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', index);
			    }
			    else
			    {
			        item.setProperty('selected', '');
			    }
			});
		}
		else
		{
			$('txtForename').value = $('Repeater1_ctl00_lblForename').getText();
			$('txtSurname').value = $('Repeater1_ctl00_lblSurname').getText();
			$('txtAddress1').value = $('Repeater1_ctl00_lblAddress1').getText();
			$('txtAddress2').value = $('Repeater1_ctl00_lblAddress2').getText();
			$('txtTown').value = $('Repeater1_ctl00_lblTown').getText();
			$('txtCounty').value = $('Repeater1_ctl00_lblCounty').getText();
			$('txtPostcode').value = $('Repeater1_ctl00_lblPostcode').getText();
			$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', 0);
			$$('#CountrySelect1_ddCountrySelect option').each(function(item, index) {
			    if (item.getText() == $('Repeater1_ctl00_lblCountry').getText())
			    {
			        item.setProperty('selected', 'selected');
			        //$('CountrySelect1_ddCountrySelect').setProperty('selectedIndex', index);
			    }
			    else
			    {
			        item.setProperty('selected', '');
			    }
			});
		}
	}
}
