// login
$(document).ready(function(){
	$("#sidebar-block-Login").css('display', 'none');
	$("#copyright").click(function(){
		$("html").animate({ scrollTop: 600 }, "slow");
		$("#sidebar-block-Login").show();
	});
});


// search
var width, widthFinal, elem, duration = 500, refresh = 20, div;
var moving = false, moving = false, open = false;

function searchOut(id, to)
{
	if(moving == false && open == false) {
		moving = true;
		widthFinal = to;
		div = duration/refresh;
		elem = getElem(id);
	
		elem.style.width = '0px';
		elem.style.display = 'block';
		setClass('site_search_button', 'shown');
		searchOutSlide(1);
	}
}

function searchOutSlide(current) {
	width = Math.round(Math.sin(Math.PI/2/div*current)*widthFinal);
	if(width > widthFinal) width = widthFinal;
	
	elem.style.width = width + 'px';
	current = current + 1;
	
	if(width < widthFinal) {
		setTimeout('searchOutSlide(' + current + ')', refresh);
	}
	else {
		moving = false;
		open = true;
	}
}

function searchIn(id, from)
{
	thenclose = false;
	if(moving == false && open == true) {
		moving = true;
		widthFinal = from;
		div = duration/refresh;
		elem = getElem(id);
	
		elem.style.display = 'block';
		elem.style.width = from + 'px';
		searchInSlide(1);
	}
}

function searchInSlide(current) {
	width = Math.floor(Math.sin(Math.PI/2 + Math.PI/2/div*current)*widthFinal);
	if(width < 0) {
		elem.style.width = '0px';
		elem.style.display = 'none';
		moving = false;
		open = false;
		setClass('site_search_button', 'hidden');
	}
	else {
		elem.style.width = width + 'px';
		current = current + 1;
		setTimeout('searchInSlide(' + current + ')', refresh);
	}
}

function setClass(id, className) {
	getElem(id).className = className;
}

function trySearchOut() {
	if(moving == false) {
		searchOut('site_search', 200);
	}
}

function trySearchIn() {
	if(moving == false) {
		searchIn('site_search', 200);
	}
}

// Monitor Search Box for Submission
function siteSearchMon(e, q) {
	var key = window.event ? e.keyCode : e.which;
	
	if(key == 13) siteSearchSubmit(q);
}

// Send Search Submission
function siteSearchSubmit(q) {
	window.location.href='/search/'+q;
}

// Preload
function searchPreLoad() {
	elem = getElem('site_search');
	elem.style.display = 'none';
}