// JavaScript Document
var Comic = new Object();

Comic = {
	object     : null,
	aryComic   : new Array(),
	ComicSRC   : "",
	objImage   : null,
	sTo_Reload : null,
	Setup : function(){
		if( document.getElementById( "ComicImg" ) != undefined ){
			this.object = document.getElementById( "ComicImg" );
			this.aryComic[  1 ] = "01_support.jpg";
			this.aryComic[  2 ] = "02_always.jpg";
			this.aryComic[  3 ] = "03_schedule.jpg";
			this.aryComic[  4 ] = "04_reservation.jpg";
			this.aryComic[  5 ] = "05_rival.jpg";
			this.aryComic[  6 ] = "06_evolution.jpg";
			this.aryComic[  7 ] = "07_nanako.jpg";
			this.aryComic[  8 ] = "08_ambition.jpg";
			this.aryComic[  9 ] = "09_campain.jpg";
			this.aryComic[ 10 ] = "10_nippo.jpg";
			this.ComicSRC      = "/viva7/images/manga/" + this.aryComic[ this.getRandom( 1, this.aryComic.length - 1 ) ];
			this.objImage      = new Image();
			this.objImage.src  = this.ComicSRC;
			this.Reload();
		}
	},
	Reload : function(){
		if( this.objImage.height != 0 ){
			this.object.style.height          = ( this.objImage.height + 10 ) + "px";
			this.object.style.backgroundImage = "url("+ this.ComicSRC + ")";
		}else{
			this.sTo_Reload = setTimeout( "Comic.Reload()", 1000 );
		}
	},
	getRandom : function( ARG_iStart, ARG_iEnd ){
		rValue = 0;
		while( rValue <= 0 ){
			rValue = Math.ceil( Math.random() * ( ( ARG_iEnd - ARG_iStart ) + 1 ) ) + ARG_iStart - 1;
		}
		return rValue;
	}
}

ORUF = new Object();

ORUF.Event = {
	addListener : function( ARG_Element, ARG_EventType, ARG_Function ){
		var WrappedFunction = function( e ){
			return ARG_Function.call( ARG_Element, e );
		}
		this.addEvent( ARG_Element, ARG_EventType, WrappedFunction, false );
	},
	addEvent : function(){
		if( window.addEventListener ){
			return function( ARG_Element, ARG_EventType, ARG_Function, ARG_Capture ){
				ARG_Element.addEventListener( ARG_EventType, ARG_Function, ( ARG_Capture ) );
			};
		}else if( window.attachEvent ){
			return function( ARG_Element, ARG_EventType, ARG_Function ){
				ARG_Element.attachEvent( "on" + ARG_EventType, ARG_Function );
			};
		}else{
			return function(){};
		}
	}(),
	removeEvent : function(){
		if( window.removeEventListener ){
			return function( ARG_Element, ARG_EventType, ARG_Function, ARG_Capture ){
				ARG_Element.removeEventListener( ARG_EventType, ARG_Function, ( ARG_Capture ) );
			};
		}else if( window.detachEvent ){
			return function( ARG_Element, ARG_EventType, ARG_Function ){
				ARG_Element.detachEvent( "on" + ARG_EventType, ARG_Function );
			};
		}else{
			return function(){};
		}
	}(),
	Cancel : function( e ){
		if( window.removeEventListener ){
			e.preventDefault();
			e.stopPropagation();
		}else if( window.detachEvent ){
			e.returnValue  = false;
			e.cancelBubble = true;
		}else{
			return false;
		}
	}
	
}
ORUF.Event.add = ORUF.Event.addListener;

ORUF.Event.add( window, "load", function(){ Comic.Setup(); } );
