FastInit.addOnLoad(siteInit);

function siteInit(e) {
	
	img = new Image();
	img.src = "lib/img/site/bkg_header.gif";
	prepare_logboard();
	prepare_search();
	if ($('thumbview_popdown')) Event.observe($('thumbview_popdown'), 'click', toggle_thumbview_popdown);
}

function toggle_thumbview_popdown(e) {
	if($('sortbycombo')) $('sortbycombo').style.visibility = 'hidden';

	Event.stop(e);
	
	if($('thumbviewcombo').style.visibility == 'visible') {
		$('thumbviewcombo').style.visibility = 'hidden';
	} else {
		$('thumbviewcombo').style.visibility = 'visible';
	}
}

function prepare_logboard () {
	if ($('login_button')) {
		Event.observe($('login_button'), 'click', show_login);
		
//		$('login').style.display = 'none';
//		$('log_warning').style.display = 'none';
		
	}
}

function prepare_search() {
	if($('search')) {
		Event.observe($('search'), 'submit', do_search);
		Event.observe($('search'), 'focus', remove_roba);
	}
}


function show_login(e) {	
	
	if( !e ) { e = window.event; }
	
	$('login').style.display = 'block';
	$('log_warning').style.display = 'block';
	$('log_menu').style.display = 'none';
}

function do_search(e) {
	
	if( !e ) { e = window.event; }
	
	if($('q').value == '') {
		Event.stop(e);
	}
	
}

function remove_roba(e) {
	
	if( !e ) { e = window.event; }
	
	if($('q').value == 'search e-store') {
		$('q').value = '';
		Event.stop(e);
	}
	
}

function change_view(status) {
	var url = 'change_tview.ajax';
	var pars = 'thumbview='+status;

	var myAjax = new Ajax.Updater(
			'notz',
			url,
			{
				method: 'get', 
				parameters: pars,
				evalScripts: true
			});
	
}
