var dropdown = new Class({
	initialize: function(id, iclass, sclass){
		var pnode = "#" + id + " ." + iclass;
		var cnode = "#" + id + " ." + sclass;
		
		$$(cnode).each(function(sub, i){
			sub._hold = false;
			sub._cid = parseInt(sub.id.substr((sub.id.length - 1), 1)) - 1;

			sub._effect = function(visible, mode, position){
				if(visible){
					this.setStyle("left", position + "px");
					this.setStyle("display", "");

					this.fade(mode);
					}
				else{
					this.fade(mode);
					}
				}

			sub.addEvent("mouseenter", function(){
				this._hold = true;
				});

			sub.addEvent("mouseover", function(){
				this._hold = true;
				});

			sub.addEvent("mouseleave", function(e){
				this._hold = false;
				this._effect(false, "out");
				});

			sub._effect(false, "hide");
			});


		$$(pnode).each(function(image, i){
			if(!image.src.match(/\.ovr.img/)) {
				image.enabled = true;
				}
			else {
				image.enabled = false;
			}

			image.addEvent("mouseover", function(){
				$$(cnode).each(function(sub, j){
					if(i == sub._cid){
						sub._hold = true;
						}
					});
				});

			image.addEvent("mouseout", function(){
				$$(cnode).each(function(sub, j){
					if(i == sub._cid){
						sub._hold = false;
						}
					});
				});

			if(image.className == "sub_image") {
				image.addEvent("mouseenter", function(){
					if(this.enabled) {
						this.src = this.src.replace(/.img/, ".ovr.img");
						}
	
					$$(cnode).each(function(sub, j){
						if(i == sub._cid){
							sub._effect(true, "in", image.getPosition($('sub_radio')).x);
							}
						else{
							sub._effect(false, "hide");
							}
						});
					});
	
				image.addEvent("mouseleave", function(){
					if(this.enabled) {
						this.src = this.src.replace(/.ovr.img/, ".img");
						}
	
					$$(cnode).each(function(sub, j){
						if((i == sub._cid)){
							(function(){
								if(!sub._hold){
									sub._effect(false, "hide");
									}
								}).delay(3000);
							}
						});
					});
				}
			});		
		}
	});

window.addEvent("load", function(){
	new dropdown("sub_radio", "sub_image", ".ssub");
	});