var navs = ['/ns/','/stock/','/colours/','/factory/','/team/','/about/'];
var myAccordion;

window.addEvent('domready', function() {
	$$('body')[0].setStyle('background-image', 'url(/images/' + (window.location.href.indexOf('/factory/') > 0 ? 'om' : 'bgs') + '/bg' + $random(1, 13) + '.jpg)');
	//alert(window.location.href);
	if (window.location.href.indexOf('/factory/') > 0) $('ns').setProperty('src', '/images/om/om-small.png');
	myAccordion = new Accordion($$('.tl'), $$('.sl'), {show: -1, alwaysHide: false});
	showNav();
    bindLightbox();
});

window.addEvent('load', function() {
	if (Browser.Engine.trident && Browser.Engine.version < 5) {
		//pngFix();
	}
});

doSifr();

function bindLightbox() {
	$$('a > img').each(function(item, index) {
		var a = item.getParent('a');
		if (a != null) {
			href = item.getParent('a').getProperty('href');
			if ((href.substr(href.length - 4) == '.jpg') || (href.substr(href.length - 4) == '.gif')) {
				a.slimbox();
			}
		}
	});
}

function doSifr() {
	var microgramma = {
	  src: '/js/microgramma.swf'
	};
	var square721 = {
	  src: '/js/square721.swf'
	};
	sIFR.activate(microgramma);
	sIFR.activate(square721);
	sIFR.replace(microgramma, {selector: 'div.model h2, div.model h3', wmode: 'transparent', thickness: '200', tuneHeight: -4, css: '.sIFR-root {text-align: center; color: #3366ff; letter-spacing: 1;} .sIFR-root a {color: #3366ff; text-decoration: none;} .sIFR-root a:hover {color: #93aeff;}'});
	sIFR.replace(microgramma, {selector: 'div#content h1, div#content h2, div#content h3', wmode: 'transparent', thickness: '200', tuneHeight: -4, css: '.sIFR-root {color: #3366ff; letter-spacing: 1;} .sIFR-root a {color: #3366ff; text-decoration: none;} .sIFR-root a:hover {color: #93aeff;}'});
	sIFR.replace(microgramma, {selector: 'h1, h2, h3', wmode: 'transparent', thickness: '200', tuneHeight: -4, css: '.sIFR-root {color: #ffffff; letter-spacing: 1;} .sIFR-root a {text-decoration: none;}'});
	sIFR.replace(microgramma, {selector: 'span#web, span#tel', wmode: 'transparent', thickness: '200', css: '.sIFR-root { color: #ff0000; letter-spacing: 2;} .sIFR-root'});
	sIFR.replace(square721, {selector: 'span#hl', wmode: 'transparent', css: '.sIFR-root {color: #ffffff;} a {color: #ffffff; text-decoration: none;}  a:hover {color: #ffffff;}'});
	sIFR.replace(microgramma, {selector: 'div#tag', wmode: 'transparent', css: '.sIFR-root {color: #ffffff; text-align: center;}'});
}

function pngFix() {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
}

function showNav() {
	navs.each(function(item, index) {
		if (window.location.href.indexOf(navs[index]) > 0 ) {
			myAccordion.display(index);
		}
	});
}