(function() {
	
	$.bind_function = function(method, object) {
	  return function() {
	    return method.apply(object, arguments);
	  };
	}

	$.fn.fakeSelect = function(refresh) {
		return this.each(function() {

			var e = $(this);

			e.find('ul.options li').click(function(event) {
				if($(this).hasClass('unselectable')) { return; }
				var newValue = $.trim($(this).children('.value').text() || $(this).text());
				if(e.find('input').val() == newValue) return;
				var newContent = $(this).children().filter(':not(.value)').clone();
				e.find('.currentOption').html(newContent);
				e.find('input').val(newValue).trigger('change');
			}).hover(function(){
					if($(this).hasClass('unselectable')) return;
					if($.browser.msie && $.browser.version < 7) {
						$(this).css('background-color', '#edbb47')
					} else {
						$(this).css({backgroundPosition: "0 -50px"}); 
					}
				},function(){
					if($(this).hasClass('unselectable')) return;
					if($.browser.msie && $.browser.version < 7) {
						$(this).css('background-color', 'transparent')
					} else {
						$(this).animate({backgroundPosition: "0 75px"},250);
					}
			});
			
			// simplified, hackish way of making sure we only attach these on initial load
			if(refresh != 'refresh') {			
				e.hover(function(){
						$(this).css("background-position", "0px -88px");
						$("ul.options", this).slideDown(120);
					},function(){
						$(this).css("background-position", "0px 0px");
						$("ul.options", this).slideUp(120);			
				});
			}
		});
	}

})();


/**
 * @author Alexander Farkas
 * v. 1.1
 */

(function($){
	
	if(!document.defaultView || !document.defaultView.getComputedStyle){
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
})(jQuery);

(function($) {
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			
			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

// onchange() on select boxes is handled in a variety of retarded ways by different browsers.
// this patch (hopefully) makes them all work like you would expect them to.
$.event.special.change = {
  setup: function() {
    // only monkeypatch if we're dealing with a select element and we're not dealing with Safari.
    if(this.tagName.toLowerCase() != 'select' || $.browser.safari) return false;
    $(this).data('oldVal', $(this).val());
    $(this).bind("click keydown", $.event.special.change.handler);
    return true;
  },

  teardown: function() {
    $(this).unbind("click keydown", $.event.special.change.handler);
  },

  handler: function(event) {
    var args = arguments;
    setTimeout($.bind_function(function() {
      if($(this).val() != $(this).data('oldVal')) {
        $(this).data('oldVal', $(this).val());
        args[0].type = 'change';
        return $.event.handle.apply(this, args);
      } else {
        return true;
      }
    }, this), 1);
    return true;
  }
};

jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: '/images/blank.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

$(function() { $('.png24').supersleight(); })