var itxt=new Array();

function input_enable(id,txt){
	var inp = document.getElementById(id);
	if(inp){
		itxt[id]=txt;
		inp.className='inactive';
		inp.value=txt;
		inp.onfocus=function(){input_active(id);}
		inp.onblur=function(){input_inactive(id);}
	}
}

function input_active(id){
	var inp = document.getElementById(id);
	inp.value='';
	if(inp.className=='inactive')
		inp.className='';
	}

function input_inactive(id){
	var inp = document.getElementById(id);
	if(inp.value==''){
		inp.value=itxt[id];
		inp.className='inactive';
	}
}

var top_news_counter=0;
var top_news_group=1;
var top_news_limit=2;
function top_news_next(){
	var top_news = document.getElementById('top_news');
	if(!top_news)
		return;
	top_news_counter = top_news_counter==top_news_limit ? 0 : top_news_counter+1;
	show_news(top_news_counter);
}

function top_news_prev(){
	var top_news = document.getElementById('top_news');
	if(!top_news)
		return;
	top_news_counter = top_news_counter==0 ? top_news_limit : top_news_counter-1;
	show_news(top_news_counter);
}

function show_news(nr){
	var top_news = document.getElementById('top_news');
	if(!top_news)
		return;
	top_news_counter=nr;
	activate_page(nr);
	ajax_get('/ajax.php?item=news&k='+top_news_group+'&page='+nr,top_news,'',true);
}

function show_news_group(nr,btn){
	var top_news = document.getElementById('top_news');
	if(!top_news)
		return;
	top_news_counter=0;
	top_news_group=nr;
	ajax_get('/ajax.php?item=news&k='+nr,top_news,function(){ajax_get('/ajax.php?item=news_pages&k='+nr,'top_news_pages');});
	
	var menu = document.getElementById('top_news_menu');
	if(!menu || !btn)
		return;
	var btns = menu.getElementsByTagName('div');
	for(i=0;i<btns.length;i++){
		if(btns[i].className=='btn active')
			btns[i].className='btn';
	}
	btn.className = 'btn active';
}

function show_gallery_group(pos,btn){
	var user_gallery = document.getElementById('user_gallery');
	if(!user_gallery)
		return;
	ajax_get('/ajax.php?item=user_gallery&pos='+pos,user_gallery);
	if(!btn)
		return;
	var btns = btn.parentNode.getElementsByTagName('div');
	for(i=0;i<btns.length;i++){
		if(btns[i].className=='btn active')
			btns[i].className='btn';
	}
	btn.className='btn active';
}

function unactivate_page(){
	var page = document.getElementById('top_news_pages');
	if(!page)
		return;
	pgs = page.getElementsByTagName('a');
	for(i=0;i<pgs.length;i++){
		if(pgs[i].className=='active')
			pgs[i].className='';
	}
}

function activate_page(nr){
	var page = document.getElementById('top_news_page_'+nr);
	unactivate_page();
	if(!page)
		return;
	page.className='active';
}

function toggle_banners(pos,btn){
	var bottom_banners = document.getElementById('bottom_banners');
	if(!bottom_banners)
		return;
	ajax_get('/ajax.php?item=banners&pos='+pos,bottom_banners);
	if(!btn)
		return;
	var btns = btn.parentNode.getElementsByTagName('div');
	for(i=0;i<btns.length;i++){
		if(btns[i].className=='btn active')
			btns[i].className='btn';
	}
	btn.className='btn active';
}

function toggle_top_gallery(p){
	var top_gallery = document.getElementById('top_gallery');
	if(!top_gallery)
		return;
	ajax_get('/ajax.php?item=top_gallery&page='+p,top_gallery,'',true);
}

function bd_flash(path,w,h,transp,vars){
	var browser_ver = parseInt(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5,navigator.appVersion.length));
	var ie8less = navigator.appName=="Microsoft Internet Explorer" && browser_ver<=7;
	if(vars){
		var v = '';
		var s = '';
		for(i in vars){
			v += s;
			v += i+'='+vars[i];
			s = ','
		}
	}
	if(ie8less){
		document.write('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+w+'" height="'+h+'" id="banner">');
		document.write('<param name="movie" value="'+path+'"><param name="quality" value="high">');
		document.write(transp ? '<param name="wmode" value="transparent">' : '<param name="wmode" value="opaque">');
		if(vars)
			document.write('<param name="flashvars" value="'+v+'">');
	}
	document.write('<embed src="'+path+'" quality="high" ');
	document.write(transp ? 'wmode="transparent" ' : 'wmode="opaque" ');
	if(vars)
		document.write('flashvars="'+v+'" ');
	document.write('width="'+w+'" height="'+h+'" name="banner" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	if(ie8less)
		document.write('</object>');
}  
