function bindImageSwapping(img, ext) {
	if (ext) {
		$(img).bind('mouseover focus', function() {
			$(this).attr('src', $(this).attr('src').replace("_off." + ext, "_on." + ext));
		});
		$(img).bind('mouseout blur', function() {
			$(this).attr('src', $(this).attr('src').replace("_on." + ext, "_off." + ext));
		});
	} else {
		$(img).bind('mouseover focus', function() {
			$(this).attr('src', $(this).attr('src').replace("_off.gif", "_on.gif"));
		});
		$(img).bind('mouseout blur', function() {
			$(this).attr('src', $(this).attr('src').replace("_on.gif", "_off.gif"));
		});
	}
}
function removeImageSwapping(img) {
	$(img).unbind('mouseover focus');
	$(img).unbind('mouseout blur');
}
var CURRENT_FRAGMENT = -1;
function changeFragment(to, max, ext) {
	if (CURRENT_FRAGMENT != to) {
		if (!(ext))
			ext = "gif";
		imgover($('#fragmentImg_' + to).get(0), ext);
		removeImageSwapping($('#fragmentImg_' + to).get(0), ext);
		$('#fragmentDetail_' + to).css('display', '');
		for ( var i = 1; i < max; i++) {
			imgout($('#fragmentImg_' + ((to + i) % max)).get(0), ext);
			bindImageSwapping($('#fragmentImg_' + ((to + i) % max)).get(0), ext);
			$('#fragmentDetail_' + ((to + i) % max)).css('display', 'none');
		}
		CURRENT_FRAGMENT = to;
	}
}
function download(uri) {
	var elemIF = document.createElement("iframe");
	elemIF.src = "/utility/download?uri=" + uri;
	elemIF.style.display = "none";
	document.body.appendChild(elemIF);
}

function trim(str) {
	if (str)
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	else
		return '';
}
function wrapAlphabet(obj, startTag, endTag) {
	var regExp1 = new RegExp('(' + endTag + startTag + ')', 'gi');
	var regExp2 = new RegExp('(' + endTag + ' ' + startTag + ')', 'gi');
	$(obj).find('*').contents().filter(function() {
		return this.nodeType == 3;
	}).each(function(idx) {
		var txt = trim($(this).text());
		if (!(txt))
			return;
		var str = '';
		for ( var i = 0; i < txt.length; i++) {
			var c = txt.charAt(i);
			if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
				str += startTag + c + endTag;
			} else {
				str += c;
			}
		}
		if (txt != str) {
			str = str.replace(regExp1, '');
			str = str.replace(regExp2, ' ');
			$(this).replaceWith(str);
		}
	});
}
