// Comic-Leader
	// version: 1.6 / last-update: 2005.11.22
	// (c) snow-materia "http://sm.useyan.com/"
	// This script may lead and help you to read the web comic or the consecutive images.


//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	default setting


// write the element-id of ...
var Comic_Default = {
 // for objects (necessary)
	image   : 'image',	// the image.

 // for objects (optional)
	image2  : 'image2',	// the image for double-page spread.
	id      : 'leader',	// the form.
	frame   : 'frame',	// the frame-name, if images is in another frame.

 // for setting (optional)
	first   : 'first',	// the number of the first image-file.
	last    : 'last',	// the number of the last image-file.
	dir     : 'dir',	// the directory with image-files.
	digit   : 'digit',	// the digits of sequential numbers for image-file name.
	extension : 'extension',	// the extension of image-file.
	prelimit : 'prelimit',	// the number of limits in which page is cached to memory.

 // for interface (optional)
	page    : 'page',	// for display the number of the current page.
	prev    : 'prev',	// to the previous page.
	next    : 'next',	// to the next page.
	zoom    : 'zoom',	// for zoom the image.
	cookie  : 'cookie',	// for save the page read at the last in cookie.
	spread  : 'spread',	// for double-page spread.
	gesture : 'gesture',	// for key-gesture on the image.
	preload : 'preload',	// for the preloaded page.

 // for allowing (optional)
	query   : 'query'	// for permit to change the setting with the query.
};




//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	new


// Comic-Leader
function Comic (set) {
	if (!set || !set['image']) return;
	var d = document;

	// DOM usable ?
	if (!d.getElementById || !d.nodeType) return;

	// Opera ?
	this.Opera = (window.opera) ? true : false;

	// IE ?
	this.IE = (d.all && !this.Opera) ? true : false;

	// setting
	this.set = set;

	// id
	this.id = set['id'] || null;
	this._id = null;
	if (this.id) {
		Comic.objects[ this.id ] = this;

		// form
		var form = (set['id']) ? d.getElementById(set['id']) : null;
		if (form && form.nodeName == 'FORM') {
			form.onsubmit = function () { return false; };	// not submit
			this._id = form;
		}
	}

	// new object
	this.renew();

	// not success ?
	if (!this.success) return;

	// set events
	this._set_events();
};

// default object
Comic._ = new Comic();

// objects
Comic.objects = new Object();


//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	public method


// renewal
Comic.prototype.renew = function () {
	// success
	this.success = false;

	if (!this || !this.set) return false;
	var set = this.set;
	var d = document;

	// form ?
	var form = this._id;

	// get elements
	for (var k in set) {
		this[ '_'+ k ] = (!set[k]) ? null :
			(form && form.elements[ set[k] ]) || d.getElementById( set[k] ) || null;
	}

	// if images is in another frame.
	this.frame = null;
	if (!this._image && this._frame) {
		var frame = get_element_value(this._frame);
		if (frame) {
			var w = window.top.frames[ frame ];
			if (w) {
				this._image  = w.document.getElementById( set['image'] )  || null;
				this._image2 = w.document.getElementById( set['image2'] ) || null;
				this.frame = w;
			}
		}
	}

	// image element (necessary)
	if (!this._image || this._image.nodeName != 'IMG') return false;

	// success
	this.success = true;

	// parent element is <A> ?
	var focus_ok = { A : 1, BUTTON : 1, INPUT : 1, LABEL : 1 };
	var p  = this._image;
	var p2 = this._image2;
	while (p  && !(focus_ok[ p.nodeName ]  && p.focus) ) { p  = p.parentNode;  }
	while (p2 && !(focus_ok[ p2.nodeName ] && p2.focus)) { p2 = p2.parentNode; }
	this._focus  = p;
	this._focus2 = p2;

	// image src
	this.src = this._image.getAttribute('src') || null;

	// permit the query ?
	this.query = (this._query && get_element_value( this._query ) - 0) ? true : false;

	// get this page from location
	if (this.frame && window.parent.location.search) {
		this._parse_query( window.parent.location.search.replace(/^\?/, '') );
	} else if (location.search) {
		this._parse_query( location.search.replace(/^\?/, '') );
	}
	// get this page from cookie
	else if (this.src && d.cookie) {
		var reg = new RegExp( escape(this.src) + '=([^;]*)' );
		if ( d.cookie.match(reg) ) this._parse_query( RegExp['$1'] );
	}

	// initialize
	this._init();

	// set init-values
	this._set_init_values();

	// go to this page
	this.go( this.page );

	// focus ?
	if (this.gesture) this.focus();

	return true;
};


// reinitialize
Comic.prototype.reinit = function () {
	if (!this || !this.success) return;

	// go to the first page
	this.go( this.first );

	// initialize
	this._init();

	// set init-values
	this._set_init_values();

	// go to this page
	this.go(0);

	// focus ?
	if (this.gesture) this.focus();
};


// go to any page
Comic.prototype.go = function (page) {
	if (!this || !this.success) return;

	// page to number
	page -= 0;
	if (!page) page = 0;
	else if (page < 0) page = this.last + page + 1;

	// page over ?
	if (page < this.first) page = this.first;
	else if (page > this.last) page = this.last;

	// all-pages align
	if (this.spread < 0) {
		return;
	}

	// double-page spread
	if (this.spread == 2) {	// even
		if (page % 2) page += 1;	// odd ?
	} else if (this.spread == 1) {	// odd
		if (page % 2 == 0) page += 1;	// odd ?
	}
	if (this.spread) {
		this._image.style['visibility']  = (page <= this.last) ? 'visible' : 'hidden';
		this._image2.style['visibility'] = (page > this.first) ? 'visible' : 'hidden';
	}

	// set value in element
	if (this.page != page) {
		this.page = (page <= this.last) ? page : this.last;
		if (this._page) set_element_values(this._page, this.page);
	}

	// change image
	if (page <= this.last) {
		this._image.setAttribute('src', this._file_path( page ));
		this._image.setAttribute('title',
			(page) + ((page != this.last) ? ' / next' : ' / last')  );
	}
	// double-page spread
	if (this.spread && page - 1 >= this.first) {
		this._image2.setAttribute('src', this._file_path( page - 1 ));
		this._image2.setAttribute('title',
			(page - 1) + ((page - 1 != this.first) ? ' / prev' : ' / first')  );
	}

	// disabled ?
	this._disabled();

	// preload images
	this.preload( page - ((this.spread) ? 2 : 1), true);

	// zoom
	if (!this.IE) this.change_zoom();
};

// go to previous page
Comic.prototype.prev = function () {
	if (!this || !this.success) return;
	var prev = this.page - ((this.spread) ? 2 : 1);
	this.go( (prev >= this.first) ? prev : this.first );
};

// go to next page
Comic.prototype.next = function () {
	if (!this || !this.success) return;
	var next = this.page + ((this.spread) ? 2 : 1);
	this.go( (next <= this.last) ? next : this.last );
};


// zoom image
Comic.prototype.change_zoom = function (zoom, one) {
	if (!this || !this.success) return;

	// page to number
	zoom -= 0;
	if (!zoom) zoom = this.zoom
	if (!zoom) return;
	var page = this.page;
	var imgs = this.images;

	// set value in element
	if (this.zoom != zoom) {
		this.zoom = zoom;
		if (this._zoom) set_element_values(this._zoom, zoom, 1, 1);
	}

	// all-pages align
	if (this.spread < 0) {
		if (this.IE && this.all_pages.list) {
			this.all_pages.list.style['zoom'] = zoom +'%';
		} else if (this.all_pages.images) {
			var first = this.first - 0;
			var last  = this.last - 0;
			var all_imgs = this.all_pages.images;
			if (typeof one == 'number') first = last = page;
			// all-pages
			for (var p = first; p <= last; p++) {
				var img = all_imgs[p];
				if (!img) continue;
				if (!imgs[p]) this.preload(p, false);	// preload
				if (imgs[p] && imgs[p].width) {
					var width  = imgs[p].width  - 0;
					var height = imgs[p].height - 0;
					img.style['width']  = Math.floor( width  * zoom / 100 ) +'px';
					img.style['height'] = Math.floor( height * zoom / 100 ) +'px';
				}
			}
		}
		return;
	}

	// zoom
	if (this.IE) {
		this._image.style['zoom'] = zoom +'%';
		if (this.spread) this._image2.style['zoom'] = zoom +'%';
	} else if (imgs[ page ] && imgs[ page ].width) {
		var width  = imgs[ page ].width  - 0;
		var height = imgs[ page ].height - 0;
		this._image.style['width']  = Math.floor( width  * zoom / 100 ) +'px';
		this._image.style['height'] = Math.floor( height * zoom / 100 ) +'px';
		if (this.spread) {
			var spread = (page - 1 >= this.first) ? page - 1 : -1;
		 	if (spread >= 0 && imgs[ spread ] && imgs[ spread ].width) {
				var width  = imgs[ spread ].width  - 0;
				var height = imgs[ spread ].height - 0;
				this._image2.style['width']  = Math.floor( width  * zoom / 100 ) +'px';
				this._image2.style['height'] = Math.floor( height * zoom / 100 ) +'px';
			}
		}
	}
}


// double-page spread
Comic.prototype.change_spread = function (spread) {
	if (!this || !this.success) return;

	// page to number
	if (typeof spread != 'number') {
		spread = (this._spread) ? get_element_value( this._spread ) - 0 : 0;
	}
	spread -= 0;
	if (!spread) spread = 0;

	// set value in element
	if (this.spread != spread) {
		this.spread = spread;
		if (this._spread) set_element_values(this._spread, spread, 1, 1);
	}

	// all-pages ?
	this._all_pages( spread < 0 );

	// display
	this._image.style['visibility']  = 'visible';	// visibility
	this._image.style['display'] = (spread >= 0) ? 'inline' : 'none';	// display

	// image2 display
	if (this._image2) {
		this._image2.style['visibility'] = 'visible';	// visibility
		this._image2.style['display'] = (spread > 0) ? 'inline' : 'none';	// display
	}

	// reset zoom
	this.change_zoom();
};


// save cookie
Comic.prototype.save_cookie = function (days) {
	if (!this || !this.success) return;

	// expires
	var expires = '';
	if (this.page <= this.first || this.page >= this.last) {
		days = -1;
	} else if (typeof days != 'number') {
		var tmp = (this._cookie) ? get_element_value( this._cookie ) : null;
		days = (tmp) ? tmp - 0 : -1;
	}
	if (days) {
		var exp = new Date();
		exp.setTime( exp.getTime() + 86400000 * days );
		expires = '; expires=' + exp.toGMTString();
	}

	// cookie string
	var cookie = '';

	// permit the query ?
	if (this.query && this._id && this._id.nodeName == 'FORM' && this._id.elements) {
		var elength = this._id.elements.length - 0;
		for (var i = 0; i < elength; i++) {
			var el = this._id.elements[i];
			var name = el.name;
			var value = get_element_value(el, 1, 1);
			if (!value) continue;
			cookie += name +'='+ value +'&';
		}
	} else {
		cookie = this.page;
	}

	// save cookie
	document.cookie = escape(this.src) +'='+ cookie + expires;
};


// preload images
Comic.prototype.preload = function (page, chain) {
	if (!this || !this.success) return;
	if (!this.prelimit || this.prelimit < 0) return;

	// page
	page -= 0;
	this.preloading = -1;
	if (typeof page != 'number') page = this.page;
	if (page > this.page + this.prelimit || page > this.last)  return;
	if (page < this.first) return (chain) ? this.preload(page + 1, true) : null;
	this.preloading = page;

	// preload limit, memory clear
	var prelimit = this.page - this.prelimit;
	for (var i = 0; i < prelimit; i++) {
		if (this.images[i]) this.images[i] = null;
	}

	// new image
	if (!this.images[page] || this.images[page].is_correct == -1) {
		this.images[page] = new Image();
		this.images[page].src = this._file_path( page );
		this.images[page].page = page;
		this.images[page].object = this;
		this.images[page].is_correct = (this.images[page].complete) ? 1 : 0;
	}

	// loading next image ?
	var next = this.page + ((this.spread) ? 2 : 1);
	if (next <= this.last && this._next) {
		var clas = this._next.className && this._next.className.match(/ ?\bloading\b/);
		// not complete ?
		if (!this.images[next] || this.images[next].is_correct == 0) {
			if (!clas) this._next.className += ' loading';
		} else if (clas) {
			this._next.className = this._next.className.replace(/ ?\bloading\b/, '');
		}
	}

	// preload next image
	if (this.images[page].complete) {	// complete ?
		if (this.images[page].is_correct == 1) {
			var next_image = this.images[ page + ((this.spread) ? 2 : 1) ];
			if (this._preload && (!chain || !next_image || next_image.is_correct == 0))
				set_element_value( this._preload, page );
			if (chain) this.preload(page + 1, true);
		}
	} else if (!this.images[page].onload) {	// onload ..
		this.images[page].chain = chain;
		this.images[page].onload  = Comic._onpreload;
		this.images[page].onerror = Comic._unpreload;
	}

	return;
};
// on preload event
Comic._onpreload = function () {
	if (!this || !this.object) return;	// this is "Comic.images[x]".
	if (this.is_correct != -1) this.is_correct = 1;

	// Comic object
	var that = this.object;

	// zoom ?
	if (this.page == that.page || (this.spread && this.page == that.page - 1)) {
		if (!that.IE) that.change_zoom(null, this.page);
	}

	// preloaded
	if (this.page == that.preloading) {
		if (that._preload) set_element_value( that._preload, this.page );
		if (this.chain) that.preload(this.page + 1, true);
	}
};
// on preload event
Comic._unpreload = function () {
	if (!this || !this.object) return;	// this is "Comic.images[x]".
	this.is_correct = -1;
};


// focus
Comic.prototype.focus = function (e) {
	if (!this || !this.success) return;
	if (this.spread < 0) return;
	var obj = null;

	// One
	if (!this.spread) {
		if (this._focus) obj = this._focus;
	}
	// double-page spread
	else {
		if (this._focus2) obj = this._focus2;
	}

	// focus
	if (obj && obj.focus) {
		obj.blur && obj.blur();
		if (this.IE || this.Opera) {
			obj.focus();
		} else {
			var display = obj.style['display'];
			var visibility = obj.style['visibility'];
			obj.style['visibility'] = 'hidden';
			obj.style['display'] = 'block';
			obj.focus();
			obj.style['display'] = display;
			obj.style['visibility'] = visibility;
		}
	}
};




//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	private method


// initialize
Comic.prototype._init = function () {
	if (!this || !this.success) return;

	// first page, last page, this page
	this.first = (this._first) ? get_element_value( this._first ) || null : null;
	this.last  = (this._last)  ? get_element_value( this._last  ) || null : null;
	this.page  = (this._page)  ? get_element_value( this._page  ) || null : null;

	// image-preload
	this.images = new Array();

	// digit
	this.digit = (this._digit) ? get_element_value( this._digit ) - 0 : 0;

	// directory
	this.dir = (this._dir) ? get_element_value( this._dir ) : '';

	// extension
	this.extension = (this._extension) ? get_element_value( this._extension ) : '';

	// preload limit
	this.prelimit = (this._prelimit) ? get_element_value( this._prelimit ) - 0 : 0;
	if (!this.prelimit) this.prelimit = 20;

	// image src
	this.src = this._image.getAttribute('src') || null;

	// unless, find from the default image-src.
	if (this.src) {
		var path = this.src.match(/^((?:.*[\\\/])?[^\.\\\/]*?)(\d+)(?:\.([^\\\/]*))?$/);
		if (path && path[0]) {
			if (!this.dir && path[1]) this.dir = path[1];	// directory
			if (!this.digit && path[2]) this.digit = path[2].length;	// digit
			if (!this.extension && path[3]) this.extension = path[3];	// extension
			if (!this.first && path[2]) this.first = path[2];	// first page
		}
	}
	// unless last-page
	if (!this.last && this._image2) {
		this.src2 = this._image2.getAttribute('src') || '';
		var path = this.src2.match(/(\d+)(?:\.[^\.\\\/]*)*$/);
		if (path && path[0]) {
			if (path[1]) this.last = path[1];	// last page
		}
	}

	// is not yet
	if (!this.extension) this.extension = 'jpg';
	this.first = (this.first) ? this.first - 0 : 1;
	this.last  = (this.last)  ? this.last  - 0 : 999;
	this.page  -= 0;
	if (!this.first || this.first < 0) this.first = 0;
	if (!this.last  || this.last  <= this.first) this.last  = 999;
	if (!this.page) this.page = this.first;

	// zoom
	this.zoom = (this._zoom) ? get_element_value( this._zoom ) - 0 : 0;
	if (this.zoom) this.change_zoom();

	// all-pages align
	this.all_pages = new Object();

	// double-page spread
	this.spread = 0;
	if (this._spread) this.change_spread();

	// key-gesture
	this.gesture = (this._gesture) ? get_element_value( this._gesture ) - 0 : 0;
};


// set initialized values in elements
Comic.prototype._set_init_values = function () {
	if (!this || !this.success) return;

	// set values
	var names = new Array(
		'page', 'first', 'last', 'digit', 'dir', 'extension', 'zoom', 'spread', 'gesture'
	);
	for (var i = names.length; i--;) {
		var name = names[i];
		if (this[ '_'+ name ]) set_element_values(this[ '_'+ name ], this[name], 1, 1);
	}

	// preload
	if (this._preload) set_element_values(this._preload, this.first, 1, 1);
};


// set events
Comic.prototype._set_events = function () {
	if (!this || !this.success) return;

	//--> for setting (necessary)

	// closure
	var that = this;

	// prev / next
	var prevnext = function (e) {
		if (!that || !that.gesture || (!e && !(e = window.event)) || !e.keyCode) return;
		else if (that.key_event[ e.keyCode ]) {
			that.focus();
			that.key_event[ e.keyCode ]();

//			if (e.preventDefault)  e.preventDefault();
//			if (e.stopPropagation) e.stopPropagation();
//			e.cancelBubble = true;
//			e.returnValue = false;
			return false;
		}
	};

	// image
	var focus = this._focus || this._image;
	Comic._addEvent('keydown', prevnext, false, focus);
	Comic._addEvent('click',   function () { that.next(); }, false, focus);
	focus.oncontextmenu =
		function (e) { that.prev(); if (e) e.cancelBubble = true; return false; };

	// image2
	if (this._image2) {
		var focus2 = this._focus2 || this._image2;
		Comic._addEvent('keydown', prevnext, false, focus2);
		Comic._addEvent('click',   function () { that.prev(); }, false, focus2);
		focus2.oncontextmenu =
			function (e) { that.next(); if (e) e.cancelBubble = true; return false; };
	}

	//--> for interface (optional)

	// current page
	if (this._page) {
		if (this._page.nodeName == 'INPUT' || this._page.nodeName == 'TEXTAREA')
			Comic._addEvent('change', function () {
				that.go( get_element_value(that._page) );
			}, false, this._page);
	}
	// previous page
	if (this._prev) {
		Comic._addEvent('mouseup',  function () { that.prev(); }, false, this._prev);
		Comic._addEvent('keypress', function () { that.prev(); }, false, this._prev);
	}
	// next page
	if (this._next) {
		Comic._addEvent('mouseup',  function () { that.next(); }, false, this._next);
		Comic._addEvent('keypress', function () { that.next(); }, false, this._next);
	}

	// zoom
	if (this._zoom) {
		Comic._addEvent('change', function () {
			that.zoom = get_element_value(that._zoom) - 0;
			that.change_zoom();
		}, false, this._zoom);
	}

	// cookie
	if (this._cookie) {
		Comic._addEvent('unload', function () { that.save_cookie(); }, false, window);
	}

	// preload
	if (this._preload) {
		if (this._preload.nodeName == 'INPUT' || this._preload.nodeName == 'TEXTAREA')
			Comic._addEvent('change', function () {
				that.preload( get_element_value(that._preload), true );
			}, false, this._preload);
	}

	// double-page spread
	if (this._spread) {
		Comic._addEvent('change', function () {
			that.change_spread();
			that.go( that.page );
		}, false, this._spread);
	}

	// key-gesture
	if (this._gesture) {
		Comic._addEvent('change', function () {
			that.gesture = get_element_value(that._gesture) - 0;
		}, false, this._gesture);
	}

	// event by key-code for key-gesture
	this.key_event = {
		37 : function () { this._.prev(); },	// <-
		39 : function () { this._.next(); },	// ->
		36 : function () { this._.go(0);  },	// home
		35 : function () { this._.go(-1); },	// end

		66 : function () { this._.prev(); },	// Back
		78 : function () { this._.next(); },	// Next
		70 : function () { this._.go(0);  },	// First
		76 : function () { this._.go(-1); },	// Last
		77 : function () { this._.change_zoom(this._.zoom - 5); },	// Minus
		80 : function () { this._.change_zoom(this._.zoom + 5); },	// Plus

		_  : this
	};
	if (!this.Opera) {
		this.key_event[109] = function () { this._.change_zoom(this._.zoom - 5); };	// -
		this.key_event[107] = function () { this._.change_zoom(this._.zoom + 5); };	// +
	}
};


// make file path
Comic.prototype._file_path = function (page) {
	if (!this || !this.success) return;

	// page
	if (typeof page == 'undefined') page = this.page;
	page += '';	// to string

	// digit
	if (this.digit) {
		while (page.length < this.digit) { page = '0' + page; }
	}

	// make file path
	return this.dir + page + '.' + this.extension;
}


// disabled prev-element or next-element
Comic.prototype._disabled = function () {
	if (!this || !this.success) return;

	// even page spread ?
	var subpage = (this.spread == 2 && this.page - 1 <= this.first) ? 1 : 0;

	//--> not IE
	if (!this.IE) {
		if (this._prev)
			this._prev.disabled = (this.page - subpage > this.first) ? false : true;
		if (this._next)
			this._next.disabled = (this.page < this.last) ? false : true;
		return;
	}

	//--> for IE
	var ie_disable = false;

	// prev
	if (this._prev) {
		if (this.page - subpage > this.first) this._prev.disabled = false;
		else ie_disable = true;
	}
	// next
	if (this._next) {
		if (this.page < this.last) this._next.disabled = false;
		else ie_disable = true;
	}

	// not IE
	if (!ie_disable) return;

	// disable ? (for IE)
	var that = this;
	if (this._disabled_id) clearTimeout( this._disabled_id );
	this._disabled_id = setTimeout(
		function () {
			// even page spread ?
			var subpage = (that.spread == 2 && that.page - 1 <= that.first) ? 1 : 0;
			// disabled
			if (that._prev && that.page - subpage <= that.first)
				that._prev.disabled = true;
			if (that._next && that.page >= that.last)
				that._next.disabled = true;
		} , 10
	);
};


// all-pages
Comic.prototype._all_pages = function (display) {
	if (!this || !this.success) return;
	if (!this.all_pages) this.all_pages = new Object();

	// no display ?
	if (typeof display == 'undefined') {
		display = (this.spread < 0) ? true : false;
	}

	// abbr
	var target = this.all_pages.target || null;
	var parent = this.all_pages.parent || null;

	// target
	if (!target) {
		parent = (this._focus || this._image).parentNode;
		target = parent.lastChild;
		this.all_pages.target = target;
	}
	if (!target) return;

	// parentNode
	if (!parent) {
		parent = target.parentNode;
		this.all_pages.parent = parent;
	}

	// delete following elements from last child.
	if (target != parent.lastChild) {
		var tmp = null;
		while ((tmp = parent.lastChild) && target != tmp) parent.removeChild(tmp);
	}

	// display false
	if (!display) return;

	// document
	var d = (!this.frame) ? document : this.frame.document;

	// ordered-list-element
	var ol = d.createElement('OL');
	ol.className = 'all-pages';
	parent.appendChild(ol);

	// original element
	var df = document.createDocumentFragment();
	var li = d.createElement('LI');	// list-element
	var img = d.createElement('IMG');	// image-element

	// abbr
	var first = this.first;	// first
	var last  = this.last;	// last
	var imgs  = this.images;	// images
	var all_imgs = new Array();

	// add image's lists
	for (var p = first; p <= last; p++) {
		var _li  = li.cloneNode(false);
		var _img = img.cloneNode(false);

		// append
		_li.appendChild(_img);
		df.appendChild(_li);

		// store image
		all_imgs[p] = _img;
	}
	ol.appendChild(df);

	// set all_pages
	this.all_pages.list = ol;	// ol
	this.all_pages.images = all_imgs;	// images

	// set image at first
	all_imgs[first].src = (imgs[first]) ? imgs[first].src : this._file_path(first);

	// set image by timer
	var timer = function (obj, img, p) {
		setTimeout( function () { obj.src = img; }, p * 100);
	};
	for (var p = first + 1; p <= last; p++) {
		new timer(all_imgs[p], (imgs[p]) ? imgs[p].src : this._file_path(p), p);
	}
};


// parse query and set
Comic.prototype._parse_query = function (query) {
	if (!this || !this.success) return;
	query += '';
	query = query.replace(/^\s+/, '').replace(/\s+$/, '');
	if (!query) return;

	// only number
	if ( query.match(/^\d+$/) ) {
		if (this._page) set_element_value(this._page, query - 0, 1, 1);
		return;
	}
	if (!this.query) return;

	// parse
	var data = new Object();
	var datas = query.split(/&/);
	var reg = new RegExp(/^([^=]+)(?:=(.*))?$/);
	for (var i = datas.length; i--;) {
		if (!datas[i]) return;
		if (!datas[i].match(reg)) return;
		var name  = RegExp['$1'];
		var value = RegExp['$2'] || '';
		name  =  name.replace(/\+/g, ' ');
		value = value.replace(/\+/g, ' ');
		name  =  name.replace(/%([0-9A-Fa-f][0-9A-Fa-f])/g,
					function (z, v) { return String.fromCharCode( parseInt(v, 16) ); });
		value = value.replace(/%([0-9A-Fa-f][0-9A-Fa-f])/g,
					function (z, v) { return String.fromCharCode( parseInt(v, 16) ); });
		if ( value.match(/^[-+]?\d+$/) ) value -= 0;

		// set data
		data[name] = value;

		// set the value only in public elements.
		if (this[ '_'+ name ]) set_element_value(this[ '_'+ name ], value, 1, 1);
	}
	return data;
};


// addEvents
Comic._addEvent = function (type, func, capt, obj) {
	if (!obj || typeof obj != 'object') return;

	// elements ?
	if (!obj.nodeType && obj.length) {
		for (var i = obj.length; i--;) {
			Comic._addEvent(type, func, capt, obj[i]);
		}
		return;
	}

	// add event
	if (window.addEventList) window.addEventList(type, func, false, obj);	// Trick ?
	else if (obj.addEventListener) obj.addEventListener(type, func, false);	// DOM2 ?
	else if (obj.attachEvent) obj.attachEvent('on'+type, func);	// ie ?
	else {	// Other
		var prev = obj['on'+type];
		obj['on'+type] = (prev) ? function (e) { prev(e); func(e); } : func;
	}
};




//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	items


// get element's value
function get_element_value (element, xname, xtype) {
	var vs = get_element_values(element, xname, xtype);
	return (vs) ? vs[0] : null;
}

// set element's value
function set_element_value (element, value, xname, xtype) {
	return set_element_values(element, value, xname, xtype);
}

// get element's values
function get_element_values (elements, xname, xtype) {
	if (!elements || typeof elements != 'object') return null;
	if (elements.nodeType || !elements.length) elements = new Array(elements);

	// return values
	var rvalues = new Array();

	// add values
	var add = function (v) {
		if (!v) v = '';
		rvalues[ rvalues.length ] = v.replace(/^\s+/, '').replace(/\s+$/, '');;
	};

	// elements
	var types = (xtype) ? { text : 1, password : 1, radio : 1, checkbox : 1 } : null;
	var elength = elements.length - 0;
	for (var i = 0; i < elength; i++) {
		var el = elements[i];
		var tag = el.nodeName;
		// not element, (or no name) ?
		if (!tag || el.nodeType != 1 || (xname && !el.name && !el.id)) continue;
		// <input>
		else if (tag == 'INPUT' || tag == 'BUTTON') {
			if (xtype && !types[ el.type ]) continue;
			if ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) continue;
			add(el.value);
			continue;
		}
		// <textarea>
		else if (tag == 'TEXTAREA') {
			add(el.value);
			continue;
		}
		// <select>
		else if (tag == 'SELECT') {
			if (el.selectedIndex < 0 || !el.options) continue;
			if (!el.multiple) {	// one ?
				add(el.options[el.selectedIndex].value);
				continue;
			}
			// multiple ?
			var ops = el.options.length - 0;
			for (var i = 0; i < ops; i++) {
				if (el.options[i].selected) add(el.options[i].value);
			}
			continue;
		}
		// <xxx> ... <xxx /> or <xxx></xxx> , <xxx>abc</xxx> , <xxx>a<yyy>b</yyy>c</xxx>
		else {
			if (xtype) continue;
			if (!el.firstChild) {
				add('');
			} else if (el.childNodes.length == 1 && el.firstChild.nodeType == 3) {
				add( el.firstChild.nodeValue );
			} else {
				add( el.innerHTML.replace(/<[^<>]*>/g, '') );
			}
		}
	}
	return rvalues;
}

// set element's values
function set_element_values (elements, values, xname, xtype) {
	if (!elements || typeof elements != 'object') return null;
	if (elements.nodeType || !elements.length) elements = new Array(elements);
	var rvalues = (typeof values == 'object' && values.concat) ?
			values.concat() : new Array( values +'' );

	// return true ?
	var rbool = false;

	// remove values
	var remove = function (suffix) {
		rbool = true;
		if (rvalues.splice) return ( rvalues.splice(suffix, 1) )[0];
		var ret = tmp[suffix];
		var tmp = rvalues.concat();
		var tlength = tmp.length - 0;
		rvalues.length = 0;
		for (var i = 0; i < tlength; i++) {
			if (i != suffix) rvalues[ rvalues.length ] = tmp[i];
		}
		return ret;
	};
	// elements
	var types = (xtype) ? { text : 1, password : 1, radio : 1, checkbox : 1 } : null;
	var elength = elements.length - 0;
	var vlength = rvalues.length - 0;
	for (var i = 0; i < elength; i++) {
		var el = elements[i];
		var tag = el.nodeName;
		// not element, (or no name) ?
		if (!tag || el.nodeType != 1 || (xname && !el.name && !el.id)) continue;
		// <input>
		else if (tag == 'INPUT' || tag == 'BUTTON') {
			if (xtype && !types[ el.type ]) continue;
			if (el.type != 'radio' && el.type != 'checkbox') {
				el.value = remove(0);
			} else {
				el.checked = false;
				for (var j = 0; j < rvalues.length; j++) {
					if (rvalues[j] != el.value) continue;
					el.checked = true;
					remove(j);
					break;
				}
			}
			continue;
		}
		// <textarea>
		else if (tag == 'TEXTAREA') {
			el.value = remove(0);
			continue;
		}
		// <select>
		else if (tag == 'SELECT') {
			if (!el.options) continue;
			var multiple = el.multiple;
			var ops = el.options.length - 0;
			for (var i = 0; i < ops; i++) {
				var op = el.options[i];
				var selected = false;
				for (var j = 0; j < rvalues.length; j++) {
					if (rvalues[j] != op.value) continue;
					selected = true;
					remove(j);
					break;
				}
				op.selected = selected;
				if (!multiple && selected) break;
			}
			continue;
		}
		// <xxx> ... <xxx /> or <xxx></xxx> , <xxx>abc</xxx> , <xxx>a<yyy>b</yyy>c</xxx>
		else {
			if (!el.firstChild) {
				el.appendChild( document.createTextNode( remove(0) ) );
			} else if (el.childNodes.length == 1 && el.firstChild.nodeType == 3) {
				el.firstChild.nodeValue = remove(0);
			} else {
				el.innerHTML = remove(0);
			}
		}
	}
	return rbool;
}




//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	run


// run by default
Comic._addEvent('load', function () {
	Comic._ = new Comic( Comic_Default ); Comic_Default = null;
}, false, window);
