
var supersleight;
if(Browser.Engine.trident4) {
	supersleight	= function() {
		
		var root = false;
		var applyPositioning = true;
		
		// Path to a transparent GIF image
		var shim			= '/content/themes/breathe/img/x.gif';
		
		// RegExp to match above GIF image name
		var shim_pattern	= /x\.gif$/i;
		
		
		
		var fnLoadPngs = function() { 
			if (root) {
				root = document.getElementById(root);
			}else{
				root = document;
			}
			for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {
				// background pngs
				if (obj.currentStyle.backgroundImage.match(/\.png/i) !== null) {
					bg_fnFixPng(obj);
				}
				// image elements
				if (obj.tagName=='IMG' && obj.src.match(/\.png$/i) !== null){
					if(obj.className == 'fixPNG'){
						el_fnFixPng(obj);
					}
				}
				// apply position to 'active' elements
				if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.style.position === ''){
					obj.style.position = 'relative';
				}
			}
		};
	
		var bg_fnFixPng = function(obj) {
			var mode = 'scale';
			var bg	= obj.currentStyle.backgroundImage;
			var src = bg.substring(5,bg.length-2);
			if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
				mode = 'crop';
			}
			obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
			obj.style.backgroundImage = 'url('+shim+')';
		};
	
		var el_fnFixPng = function(img) {
			var src = img.src;
			img.style.width = img.width + "px";
			img.style.height = img.height + "px";
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
			img.src = shim;
		};
		
		var addLoadEvent = function(func) {
			var oldonload = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = func;
			} else {
				window.onload = function() {
					if (oldonload) {
						oldonload();
					}
					func();
				};
			}
		};
		
		return {
			init: function() { 
				addLoadEvent(fnLoadPngs);
			},
			
			limitTo: function(el) {
				root = el;
			},
			
			run: function() {
				fnLoadPngs();
			}
		};
	}();
	
	// limit to part of the page ... pass an ID to limitTo:
	// supersleight.limitTo('header');
	
	supersleight.init();
}

window.addEvent('domready', function() {
	if($type($('matColor'))){								 
		var matColors = $('matColor').getElement('ul').getElements('li');
		matColors.each(function(matColor, index){
			matColor.addEvent('mouseenter', function(){
				removeActive(matColors);
				matColor.addClass('active');
				var activeColor = matColor.getElement('img').get('src').split('_')[1];
				var colorString = 'content/themes/breathe/img/mat_' + activeColor.split('.')[0] + '.png';
				$('matImage').set('src', colorString);
				
				if(Browser.Engine.trident4) {		
					var src = $('matImage').src;
					$('matImage').style.width = $('matImage').width + "px";
					$('matImage').style.height = $('matImage').height + "px";
					$('matImage').style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
					$('matImage').src = '/content/themes/breathe/img/x.gif';
				}
			});	
		});
	}
	
	
	if($type($('product_listing'))){
		
		$('product_listing').addEvent('change', function(){
			new Request.HTML({
				url: 'index.php?page=catalog_item&pId=' + this.get('value'),
				onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
					$('quantity').set('html', responseHTML);
				},
				onFailure: function(){
					$('quantity').set('text', 'The request failed.');
				}
			}).send();													   
	   	});
	}
});
function removeActive(myAry){
	myAry.each(function(myElm, index){
		if(myElm.hasClass('active')){
			myElm.removeClass('active');
		}
	});	
}