function next(elem){    
        do{    
            elem=elem.nextSibling;    
        }while(elem&&elem.nodeType!=1);    
        return elem;    
    }    
    //---查找第一个子元素的函数---//    
    function first(elem){    
        elem=elem.firstChild;    
        return elem && elem.nodeType!=1?next(elem):elem;    
    }
	
	var Marquee = {
		init : function(id,toFollow,speed){
			this.speed = speed;
			this.boxID = id;
			this.toFollow=toFollow;
			this.scrollBox = document.getElementById(id);
			
			
			if(this.toFollow=="top"||this.toFollow=="bottom"){
				this.appendBox=first(this.scrollBox).cloneNode(true);
				this.scrollBox.appendChild(this.appendBox);
			}else{
				var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>"+this.scrollBox.innerHTML+"</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>"+this.scrollBox.innerHTML+"</td></tr></table>";
				this.scrollBox.innerHTML=templateLeft;
				this.appendBox=first(first(first(first(this.scrollBox))));
				
			}
			this.objs = {
				scrollBox : this.scrollBox,
				appendBox : this.appendBox,
				toFollow : this.toFollow,
				speed : this.speed,
				id : this.boxID
			};
			return this;
		},

		scrollUp : function( direction ){
			var self = this.objs;
			self.begin = function(){
				
				if(direction=="top"){
					self.doScr = setInterval(function(){
						if(self['appendBox'].offsetHeight<=self['scrollBox'].scrollTop){
							self['scrollBox'].scrollTop-=first(self['scrollBox']).offsetHeight;
						}else{
							self['scrollBox'].scrollTop++;
						}
					},self.speed);
				}else if(direction=="bottom"){
				self.doScr = setInterval(function(){
					if(self['scrollBox'].scrollTop<=0){
						self['scrollBox'].scrollTop=self['appendBox'].offsetHeight;
					}else{
						self['scrollBox'].scrollTop--;
					}
				},self.speed);
			}else if(direction=="left"){
				self.doScr = setInterval(function(){
					if(self['appendBox'].offsetWidth<=self['scrollBox'].scrollLeft){
						self['scrollBox'].scrollLeft-=self['appendBox'].offsetWidth;
					}else{
						self['scrollBox'].scrollLeft++;
					}
				},self.speed);
			}else if(direction=="right"){
				self.doScr = setInterval(function(){
					if(self['scrollBox'].scrollLeft<=0){
						self['scrollBox'].scrollLeft=self['appendBox'].offsetWidth;
					}else{
						self['scrollBox'].scrollLeft--;
					}
					
				},self.speed);
				
			}
			}
			self.begin();
			self.scrollBox.onmouseover = function(){
				clearInterval(self.doScr);
			}

			self.scrollBox.onmouseout = function(){
				self.begin();
			}
		}

	}
	
var mar, objs;
function roll( divid, direction, speed ){
	if( null == mar ){
		mar = Marquee.init( divid,direction, speed );
		objs = Marquee.objs;
	}
	var t = objs.doScr;
	clearInterval(objs.doScr);
	mar.scrollUp( direction );
	
	objs.scrollBox.onmouseover = function(){
		//clearInterval(big_roll);
		clearInterval(objs.doScr);
	}

	//objs.scrollBox.onmouseout = function(){
	//	big_roll = setInterval( roll_big_image, 8000 );
	//	objs.begin();
	//}
}

function mail_makajin( type, website, mail_input ){
	var email = jQuery.trim( jQuery("#" + mail_input).val() );
	reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if( email.length == 0 ){
		jQuery("#" + mail_input).addClass( "error" );
		jQuery("#" + mail_input).focus();
		return false;
	}

	if( !reg.test( email ) ){
		alert( "メールアドレスのフォマットが正しくないです。" );
		jQuery("#" + mail_input).addClass( "error" );
		jQuery("#" + mail_input).focus();
		jQuery("#" + mail_input).select();
		return false;
	}
		     		
	jQuery("#mail_title").ajaxStart(function() { 
		//jQuery(this).html( "<img src=\"" + images + "ajax-loader.gif\">" );
	}).ajaxError(function(request, settings) {
		jQuery(this).html( "&nbsp;" );
		jQuery("#" + mail_input).addClass( "error" );
		jQuery("#" + mail_input).focus();
		jQuery("#" + mail_input).select();
	});
	
	jQuery("#mobile_title").ajaxStart(function() { 
		//jQuery(this).html( "<img src=\"" + images + "ajax-loader.gif\">" );
	}).ajaxError(function(request, settings) {
		jQuery(this).html( "&nbsp;" );
		jQuery("#" + mail_input).addClass( "error" );
		jQuery("#" + mail_input).focus();
		jQuery("#" + mail_input).select();
	});
	
	var search_data = "type=" + type + "&email=" + jQuery("#" + mail_input).val() + "&_uuunonce=" + jQuery("#_uuunonce").val();
	jQuery.ajax({
	   type: "POST",
	   url: website + "/uuu_mail_man.php",
	   data: search_data,
	   success: function(msg){
			jQuery("#mail_title").html( "&nbsp;" );
			jQuery("#" + mail_input).removeClass( "error" );
			jQuery("#" + mail_input).val('');
			if( msg.length > 0 )
				alert( msg );
	   }
	});
}

function showWindow( location, biaoti ){
	Windows.closeAll();
	win = new Window({className: "alphacube", url: location, maximizable: false, minimizable: false, destroyOnClose: true, width:660, height:520, zIndex: 1000, resizable: true, title: biaoti, showEffect:Element.show, hideEffect: Effect.SwitchOff, draggable:true})
	win.showCenter(false, 0);
}
