function isMatchUrl( str ) {
	var url = document.URL;
	return url.indexOf( str, 0 ) != -1 ? true : false;
}

function isMatchPlatform( str ) {
	var platform = navigator.platform;
	return platform.indexOf( str, 0 ) != -1 ? true : false;
}

function isMatchUserAgent( str ) {
	var user_agent = navigator.appName;
	return  user_agent.indexOf( str, 0 ) != -1 ? true : false;
}

function Button(){
	this.button_aggregater = new Object();
}
Button.prototype = {

	flush: function(id_name){
		var id_name                 = this.button_aggregater[id_name]['id_name'];
		var x                       = this.button_aggregater[id_name]['x'];
		var y                       = this.button_aggregater[id_name]['y'];
		var width                   = this.button_aggregater[id_name]['width'];
		var height                  = this.button_aggregater[id_name]['height'];
		var background_image_src    = this.button_aggregater[id_name]['background_image_src'];
		var background_image_x      = this.button_aggregater[id_name]['background_image_x'];
		var background_image_y      = this.button_aggregater[id_name]['background_image_y'];
		var background_image_width  = this.button_aggregater[id_name]['background_image_width']==0 ? 
			this.button_aggregater[id_name]['width'] : this.button_aggregater[id_name]['background_image_width'];
		var background_image_height = this.button_aggregater[id_name]['background_image_height']==0 ?
			this.button_aggregater[id_name]['height'] : this.button_aggregater[id_name]['background_image_height'];
		var link_url                = this.button_aggregater[id_name]['link_url'];
		var link_target             = this.button_aggregater[id_name]['link_target'];
		var cut_type                = this.button_aggregater[id_name]['cut_type'];
		var padding                 = this.button_aggregater[id_name]['padding'];
		var alt						= this.button_aggregater[id_name]['alt'];
		var html_document           = new String();
		html_document += '<div id='+id_name+' style="padding:'+padding+';margin:'+y+'px 0px 0px '+x+'px;">';
		html_document += '<a href="'+link_url+'" target="'+link_target+'" style="background-image:url('+background_image_src+');background-position:'+background_image_x+'px '+background_image_y+'px;margin:0px;padding:0px;width:'+width+'px;height:'+height+'px;display:block" ';
		html_document += 'onmouseout="this.style.backgroundPosition=\''+background_image_x+'px '+background_image_y+'px\'"';
		if(cut_type=='col'){
			html_document += 'onmouseover="this.style.backgroundPosition=\''+(background_image_x-background_image_width)+'px '+background_image_y+'px\'"';
		}else{
			html_document += 'onmouseover="this.style.backgroundPosition=\''+background_image_x+'px '+(background_image_y - background_image_height)+'px\'"';
		}
		html_document += '>';
		html_document += '<span class="alt">'+this.button_aggregater[id_name]['alt']+'</span>';
		html_document += '</a>';
		html_document += '</div>';
		return html_document;
	},

	id: function(id_name){
		delete this.button_data;
		this.button_data = new Object();
		this.button_data['id_name'] = id_name;
		this.button_data['background_image_src'] = '';
		this.button_data['background_image_x'] = 0;
		this.button_data['background_image_y'] = 0;
		this.button_data['background_image_width'] = 0;
		this.button_data['background_image_height'] = 0;
		this.button_data['link_url'] = '#';
		this.button_data['link_target'] = '_self';
		this.button_data['cut_type'] = 'col';
		this.button_data['width'] = 0;
		this.button_data['height'] = 0;
		this.button_data['x'] = 0;
		this.button_data['y'] = 0;
		this.button_data['padding'] = '0px';
		this.button_data['alt'] = '';
		this.button_data['commandout'] = '';
		this.button_data['commandover'] = '';
		this.button_aggregater[id_name] = this.button_data;
	},

	size: function(width,height){
		this.button_data['width'] = width;
		this.button_data['height'] = height;
	},

	position: function(x,y,background_image_x,background_image_y){
		this.button_data['x'] = x;
		this.button_data['y'] = y;

		this.button_data['background_image_x'] = background_image_x;
		this.button_data['background_image_y'] = background_image_y;
	},

	padding: function(position){
		this.button_data['padding'] = position;
	},

	backgroundImage: function(background_image){
		this.button_data['background_image_src'] = background_image;
	},

	backgroundImageSize: function(background_image_width,background_image_height){
		this.button_data['background_image_width'] = background_image_width;
		this.button_data['background_image_height'] = background_image_height;
	},

	link: function(link_url){
		this.button_data['link_url'] = link_url;
	},

	target: function(link_target){
		this.button_data['link_target'] = link_target;
	},

	alt: function(alt){
		this.button_data['alt'] = alt;
	},

	cutTypeOfBackgroundImage: function(cut_type){
		this.button_data['cut_type'] = cut_type;
	},

	aggregater: function(){
		return this.button_aggregater;
	},

	cleanup: function(){
		delete this.button_aggregater;
		this.button_aggregater = new Object();
	}

}

function Menu(id_name){
	this.id_name = id_name;
	this.background_image_src;
	this.cut_type = 'col';
	this.interval_id;
	this.width;
	this.height;
}
Menu.prototype = {

	flush: function(button_object){
		this.open();

		var html_document = new String();

		if(button_object!=null){
			var arrgegater = button_object.aggregater();
			for(var prop in arrgegater){
				arrgegater[prop]['background_image_src'] = this.background_image_src;
				arrgegater[prop]['background_image_width'] = this.width
				arrgegater[prop]['background_image_height'] = this.height;
				arrgegater[prop]['cut_type'] = this.cut_type;
				document.write(button_object.flush(prop));
			}
		}
		this.close();
	},

	open: function(){
		document.write('<div id="'+this.id_name+'" style="background-image:url('+this.background_image_src+');overflow:hidden;display:block;width:'+this.width+'px;height:'+this.height+'px">');
	},

	close: function(){
		document.write('</div>');
	},

	size: function(width,height){
		this.width = width;
		this.height = height;
	},

	backgroundImage: function(background_image){
		this.background_image_src = background_image;
	},

	getBackgroundImage: function(){
		return this.background_image_src;
	},

	cutTypeOfBackgroundImage: function(cut_type){
		this.cut_type = cut_type;
	}

}

//プルダウン
function Pulldown(id_name){
	this.loop_id = 0;
	this.x = 0;
	this.y = 0;
	this.height = 0;
	this.id_name = id_name;
	this.container_id = id_name +'_container';
}
Pulldown.prototype = {

	flush: function(button_object){
		this.open();

		if(button_object!=null){
			var arrgegater = button_object.aggregater();
			for(var prop in arrgegater){
				this.height += arrgegater[prop]['height'];
				document.write(button_object.flush(prop));
			}
		}
		this.close();
	},

	open: function(){
		document.write('<div id='+this.id_name+' style="position:absolute;left:'+this.x+'px;top:'+this.y+'px;margin:0px;padding:0px;overflow:hidden">');
		document.write('<div id='+this.container_id+'>');
	},

	close: function(){
		document.write('</div>');
		document.write('</div>');
		with(document.getElementById(this.container_id).style){
			margin = -this.height+'px 0px 0px 0px';
			padding = '0px';
			display = 'none';
		}
	},

	position: function(x,y){
		this.x = x;
		this.y = y;
	},

	loop: function(){
	},

	loopStart: function(){
		clearTimeout(this.loop_id);
		this.loop_id = 
			setTimeout(this.id_name +'.loopStart('+ this.id_name +'.loop())', 30);
	},

	loopStop: function(){
		clearTimeout(this.loop_id);
	},

	up: function(velocity){
		var v = velocity!=null ? velocity : 4;
		var container = document.getElementById(this.container_id);
		this.loop = function(){
			if (parseInt(container.style.marginTop) >= -this.height+5) {
				var csmt = parseInt(container.style.marginTop);
				csmt += (-this.height+parseInt(container.style.marginTop))/v;
				container.style.marginTop = csmt;
			} else {
				container.style.marginTop = -this.height;
				container.style.display = 'none';
			}
		}
		this.loopStart();
	},

	down: function(velocity){
		var v = velocity!=null ? velocity : 2;
		var container = document.getElementById(this.container_id);
		container.style.display = 'block';
		this.loop = function(){
			if (parseInt(container.style.marginTop) <= -5) {
				var csmt = parseInt(container.style.marginTop);
				csmt -= (0+parseInt(container.style.marginTop))/v;
				container.style.marginTop = csmt;
			} else {
				if(isMatchUserAgent('Safari')){
					container.style.marginTop = '2px';
				}else{
					container.style.marginTop = '0px';
				}
			}
		}
		this.loopStart();
	}

};