var $j = jQuery.noConflict();
Event.observe(window,'load', function(){
	$('SearchCharacterText').observe('focus',function(){this.value = '';});
	$('SearchCharacterText').observe('blur',function(){this.value = this.value.empty() ? 'Поиск игрока': this.value;});

	$('SearchCharacterInput').observe('click',function(){
		var name = $('SearchCharacterText').value;
		if(name.blank() || name == "Поиск игрока"){
			alert("Вы не ввели имя персонажа!");
			return;
		}
		showChar(name);
	});
    initSpoilers('body');
	lightgallery.init({
       enableZoom: true,
	   animate: false,
       fadeImage:false
	});
	
	var p = document.viewport.getDimensions();
	var s = document.viewport.getScrollOffsets();

	var res =	'window dimensions:'+p.width+'x'+p.height+' -> '+getClientWidth()+'x'+getClientHeight()+'\n'+
				'window scroll:'+s.left+'x'+s.top+' -> '+$j(window).scrollLeft()+'x'+$j(window).scrollTop()+'';

	// alert(res);
});

function getClientWidth(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}
function getClientHeight(){
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function clanCharInfo(id){
	var w = window.open("/info/staff/?w=like&id="+id+"","_blank", "width=600,height=660,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	w.focus();
}
function showChar(nickname){
	var w = window.open("http://aradon.wiw.ru/cgi-bin/personviews.cgi?nickname="+nickname+"","_blank", "width=510,height=480,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	w.focus();
}
function openLink(url,height,width) {
	if (url=="0") {return false;}
	var top = getClientHeight() / 2 - 300;
	var left = getClientWidth() / 2 - 300;
	var w = window.open("http://"+url,"_blank","resizable=yes,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,top="+top+",left="+left+",height="+height+"px,width="+width+"px");
	w.focus();
}
function showSubMenu(id, show){
	$('hiddenGeneric_'+id+'').style.display = show ? 'block':'none';	
}
function openLog(fid){
	var w = window.open("/afight/"+fid+"","_blank", "width=600,height=500,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	w.focus();
}
function staffGroupHidden(id){
	var cl = (id > 0)? '-dark':'';
	if($('staffGroup-'+id+'').hasClassName('glyphs-dropuparrow'+cl+'')){
		$('staffGroup-'+id+'').removeClassName('glyphs-dropuparrow'+cl+'').addClassName('glyphs-dropdownarrow'+cl+'');
	}else{
		$('staffGroup-'+id+'').removeClassName('glyphs-dropdownarrow'+cl+'').addClassName('glyphs-dropuparrow'+cl+'');
	}
	$('staff_'+id+'').toggle();
}
function toggleNews(id){
	if($('news_'+id+'').style.display !== 'none'){
		$('point_'+id+'').removeClassName('news-minus').addClassName('news-plus');
	}else{
		$('point_'+id+'').removeClassName('news-plus').addClassName('news-minus');
	}
	$('news_'+id+'').toggle();
}

/******************** SPOILER ****************************/
function initSpoilers(context){
    var context = context || 'body';
    $j('div.spoiler-head', $j(context))
        .click(function(){
            $j(this).toggleClass('unfolded');
            $j(this).next('div.spoiler-body').slideToggle('fast');
        });
}
/******************** SPOILER ****************************/
