Prototype.Browser.IE6 = (Prototype.Browser.IE && navigator.appVersion.indexOf("MSIE 6")!=-1);
var Global = Class.create();

Global.prototype = {
	pngElements: [
		'h1', 'span.sash', '#navigation ul li a'
	],
	
	initialize: function() {
		this.png();
		this.externaliseLinks();
		this.productList();
	},
	
	png: function() {
		// Add the classname "png" to the necessary elements
		for ( var x = 0 ; x < this.pngElements.length ; x++ ) {
			var elements = $$(this.pngElements[x]);
			for ( var y = 0 ; y < elements.length ; y++ ) {
				elements[y].addClassName('png');
			}
		}

		if (typeof DD_belatedPNG != "undefined" && Prototype.Browser.IE6) {
			DD_belatedPNG.fix('.png');
		}
	},
	
	productList: function() {
		// This method fixes the stupid stacking order IE has
		// by placing a z-index on the relatively position parent
		// and the non-disappearing thumbnail
		if (Prototype.Browser.IE) {
			var products = $('products');
			if (products) {
				var elements = products.select('a');
				for ( var x = 0 ; x < elements.length ; x++ ) {
					var link = elements[x];
					Event.observe(link, 'mouseover', function() { 
						var siblings = this.up(1).select('a');
						// Reset the z-indexes on all of the links
						for ( var y = 0 ; y < siblings.length ; y++ ) {
							siblings[y].up().setStyle({zIndex:'1'});
							siblings[y].setStyle({zIndex:'1'});
						}
						// Set the z-index of the current link, and its parent to do
						this.setStyle({zIndex:'2'});
						this.up().setStyle({zIndex:'2'});
						var thumb = this.down('img.thumbnail');
						thumb.style.display = 'block';
					});
				
					Event.observe(link, 'mouseout', function() { 
						// Reset the z-indexes on all of the links
						var siblings = this.up().select('a');
						for ( var y = 0 ; y < siblings.length ; y++ ) {
							siblings[y].setStyle({zIndex:'1'});
							siblings[y].up().setStyle({zIndex:'1'});
						}
						var thumb = this.down('img.thumbnail');
						thumb.style.display = 'none';
					});
				}
			}
		}
	},
		
	flashCart: function() {
		var cart = $('cart');
		var fx = new Fx.Color(cart, 'background-color', { onComplete : this.deflashCart });
		fx.custom('#FFF', '#ffffcc');
	},
	
	deflashCart: function() {
		var cart = $('cart');
		cart.style.backgroundColor = '';
		if (typeof DD_belatedPNG != "undefined" && Prototype.Browser.IE6)
		    DD_belatedPNG.fix('#cart');
	},
	
	externaliseLinks: function() {
		var links = $$("a"); 
		for ( var x=0; x<links.length; x++ ) { 
			var link = links[x];
			if (link.getAttribute("href")) {
				var rels = link.getAttribute("rel");
				if (rels != null) {
					rels = rels.split(" ");
					for (var i=0; i<rels.length; i++) {
						if (rels[i] == "external") {
							link.target = "_blank"; 
							break;
						}
					}
				}
			}
		} 
	}
};