//	==	shadeSelector.js	==
;(function($) {
	$.fn.extend({
		shadeSelector: function(options) {
			return this.each(function() {
				new $.myShadeSelector(this, options);
			});
		}
	});
	$.myShadeSelector = function(element, options) {
		var defaults = {
			selIndx: 0
		};
		this.options = $.extend({}, defaults, options || {});
		this.element = $(element);
		this.selIndx = this.options.selIndx;
		this.indx = 0;
		this.tempTitle = "";
		this.setup();
	};
	$.extend($.myShadeSelector.prototype, {
		setup: function() {
			var arr = new Array();
			$shadeObj = this.element;
			var self = this;
			$shadeObj.find(".variance_selector_btm a").each(function(i){
				arr[i] = $(this).attr("title");
				$shadeObj.find('.variance_select').append('<option value="'+arr[i]+'">'+arr[i]+'</option>');
				//if (arr[i].indexOf("NEW") != -1) {
				//	$(this).after('<img src="images/icn_new_texture.gif" width="28" height="11" alt="" />');
				//}
			});
			$shadeObj.find(".variance_selector_btm a").eq(this.selIndx).addClass("selected");
			$shadeObj.find("select[name='variance_select']")[0].selectedIndex = this.selIndx;
			$shadeObj.find(".variance_selector_btm a").bind("mouseover", function(){
				self.mOver($(this));
			});
			$shadeObj.find(".variance_selector_btm a").bind("mouseout", function(){
				self.mOut($(this));
			});
			$shadeObj.find(".variance_selector_btm a").bind("click", function(){
				self.mClick($(this));
			});
			$shadeObj.find(".variance_select").bind("change", function(){
				self.mSelect($(this));
			});
		},
		mOver: function(elm) {
			$shadeObj = this.element;
			this.indx = $shadeObj.find(".variance_selector_btm a").index($(elm));
			this.selIndx = $shadeObj.find("select[name='variance_select']")[0].selectedIndex;
			this.tempTitle = $(elm).attr("title");
				$(this).attr("title","");	// remove title temporary
				$shadeObj.find("select[name='variance_select']")[0].selectedIndex = this.indx;
		},
		mOut: function(elm) {
			$shadeObj = this.element;
			$shadeObj.find("select[name='variance_select']")[0].selectedIndex = this.selIndx;
			$(elm).attr("title",this.tempTitle);	// restore title
		},
		mClick: function(elm) {
			this.selIndx = this.indx;
			$shadeObj.find("select[name='variance_select']")[0].selectedIndex = this.selIndx;
			$shadeObj.find('.variance_selector_btm a').removeClass("selected");
			$(elm).addClass("selected");
		},
		mSelect: function(elm) {
			$shadeObj = this.element;
			$shadeObj.find('.variance_selector_btm a').removeClass("selected");
			this.selIndx = $shadeObj.find("select[name='variance_select']")[0].selectedIndex;
			$shadeObj.find(".variance_selector_btm a").eq(this.selIndx).addClass("selected");
		}
	});
})(jQuery);
