Event.observe(window, 'load', function(){
	if ($('search')==undefined) return;
	var input = $('search').getElementsByTagName('input')[0];
	var button1 = $('search').getElementsByTagName('button')[0];
	
	if (typeof($('search').getElementsByTagName('button')[1]) == "undefined") {
		input.style.width = 513 - button1.offsetWidth + "px";
	}
	else {
		var button2 = $('search').getElementsByTagName('button')[1];
		input.style.width = 513 - button1.offsetWidth - button2.offsetWidth + "px";
	}
});

/*
Event.observe(window, 'load', function(){
	if ($('submenu')==undefined) return;
	var bookArrow = $A($('submenu').getElementsByClassName('book'));
	var bookCount = $A($('submenu').getElementsByTagName('div'));
	bookArrow.each(function(item, index){
		Event.observe(item, 'mouseover', function(){
				if (bookCount[index]!=undefined) {
					bookCount[index].style.display = "block";
				}
		});
		Event.observe(item, 'mouseout', function(){
				if (bookCount[index]!=undefined) {
					bookCount[index].style.display = "none";
				}
		});
	});
});
*/

Ajax.Responders.register({
	onCreate: function() {
		Ajax.activeRequestCount++;
		showLoading();
	},
	onComplete: function() {
		Ajax.activeRequestCount--;
		hideLoading();
	}
});

function updateElement(id, href) {
	new Ajax.Request(href, {
  		method: 'get',
  		onSuccess: function(transport) {
  			$(id).innerHTML = transport.responseText;
      	}
	});
	
}
function openLink(anchor) {
	window.open(anchor.href);
	return false;
}
function showLoading() {
	if (Ajax.activeRequestCount > 0) {
		$('ajax-saving').style.display = 'block';
	}
}

function hideLoading() {
	if (Ajax.activeRequestCount <= 0) {
		$('ajax-saving').style.display = 'none';
	}
}
//init
var selectedCount = 0;

function showButtons() {
	$('detail-tags-operations').style.display = 'block';
}
function hideButtons() {
	$('detail-tags-operations').style.display = 'none';			
}
function addTag(obj) {
	if (obj.style.textDecoration == 'underline') {
		obj.style.textDecoration = 'none';
		selectedCount--;
	} else {
		obj.style.textDecoration = 'underline';
		selectedCount++;
	}
	if (selectedCount > 0) {
		showButtons();
	} else {
		hideButtons();
	}
}
function showRecommend() {
	if ($('recommendCloud') != null)
		$('recommendCloud').style.display='block';
}
function hideRecommend() {
	if ($('recommendCloud') != null)
		$('recommendCloud').style.display='none';
}
function addTag(name) {
	var list = $('tagList').value;
	if (list.length > 0) {
		 $('tagList').value += ', '+name;
	} else {
		 $('tagList').value += name;
	}
}