
var bg_pos=-1; // position in title bg list
var title={'links':0,'head':0,'main_container':1,'j6':1}; // title sub divs
var pkey=''; // current portfolio key
var ppos=-1; // position in current portfolio
var mimozemstan=''; // key of recent mimozemstan

var timer; // timer
var lp=1; // loading progress box size

timer=setInterval('loading_progress()',60);


function on_body_load() // body onload
{
	loaded();
	switch_title_bg();
	show_title();
}


function loaded() // turn off "loading..." div
{
	clearInterval(timer);
	var obj=document.getElementById('loading');
	obj.style.visibility='hidden';
}

function loading_progress()
{
	lp++;
	obj=document.getElementById('loading_progress');
	obj.style.width=lp+'px';
	obj.style.height=lp+'px';
}

function switch_title_bg() // switch title bg to next from list
{
	// counter
	bg_pos++;
	if(bg_conf.length<=bg_pos)
		bg_pos=0;
		
	show_title_bg();
}

function show_title_bg() // show current title body
{
	var obj=document.getElementById('body');
	obj.style.backgroundImage="url("+bg_conf[bg_pos]+")";
	obj.style.backgroundRepeat='repeat-x';
	
}

function switch_div(a,b) // hide div a, show div b
{
	var obj=document.getElementById(a);
	obj.style.display="none";
	var obj=document.getElementById(b);
	obj.style.display="block";
}

function show_title() // show title
{
	sh_title('block');
}

function hide_title() // hide title
{
	sh_title('none');
}

function sh_title(val)
{
	// switch title sub divs
//	for(var k=0; k<title.length; k++)
	for(var key in title)
	{
		if(!(title[key]==0 && val=='none'))
		{
			var obj=document.getElementById(key);
			obj.style.display=val;
		}
	}
	// switch areas
	for(var key in pconf)
	{
		var obj=document.getElementById('parea_'+key);
		obj.style.display=val;
	}
}


function switch_pitem(dir) // switch portfolio item to next from current portfolio list
{
	// hide prev item texts
	if(ppos!=-1)
		hide_current_pitem_texts();
				
	switch(dir)
	{
		default:
		case "+1":
			
			ppos++;
					
			if(pconf[pkey].length<=ppos) // was last?
			{
				ppos=-1;
				end_portfolio();
			}
			else // go next
			{
				show_pitem();
				show_current_pitem_texts();
			}
		break;
		
		case "-1":

			ppos--;
					
			if(ppos==-1) // was last?
			{
				end_portfolio();
			}
			else // go next
			{
				show_pitem();
				show_current_pitem_texts();
			}
		break;
	}
	
}



function show_pitem() // show current portfolio item
{
	var obj=document.getElementById('body');
	obj.style.backgroundImage="url("+pconf[pkey][ppos]['img']+")";
	obj.style.backgroundRepeat='repeat';
	
	
}

function show_current_pitem_texts() // show current portfolio item text
{
	var pitem_key=pconf[pkey][ppos]['key'];
	show_div('pitem_text_'+pitem_key);
}

function hide_current_pitem_texts() // hide current portfolio item text
{
	if(ppos!=-1)
	{
		var pitem_key=pconf[pkey][ppos]['key'];
		hide_div('pitem_text_'+pitem_key);
		hide_div('pitem_text_'+pitem_key+'_en');
	}
}

function start_portfolio(which) // start portfolio slideshow
{
	hide_title();
	pkey=which;
	switch_pitem();
	show_div('next_pitem');
	show_div('prev_pitem');
}

function end_portfolio() // end current portfolio slideshow
{
	hide_div('next_pitem');
	hide_div('prev_pitem');
	switch_title_bg();
	show_title();
	pkey='';
}

function break_portfolio()
{
	hide_current_pitem_texts();
	ppos=-1;
	end_portfolio();
}

function map_portfolio()
{
	hide_current_pitem_texts();
	ppos=-1;
	hide_div('next_pitem');
	hide_div('prev_pitem');
	show_title_bg();
	show_title();
	pkey='';
}

function force_title()
{
	break_portfolio();
	hide_mapa();
}

function show_div(which) // show div
{
	var obj=document.getElementById(which);
	obj.style.display='block';
}

function hide_div(which) // hide div
{
	var obj=document.getElementById(which);
	obj.style.display='none';
}

function inline_div(which)
{
	var obj=document.getElementById(which);
	obj.style.display='inline';
}

function pos_div(which,x,y)
{
	var obj=document.getElementById(which);
	obj.style.left=x+'px';
	obj.style.top=y+'px';
}


function link_detail(key) // show link detail
{
	show_div('link_img_long_'+key);
	link_short('none');
}

function link_all(key) // show all links
{
	hide_div('link_img_long_'+key);
	link_short('block');
}

function link_short(val) // show all links
{
	for(var k=0;k<lconf.length;k++)
	{
		obj=document.getElementById('link_img_short_'+lconf[k]);
		obj.style.display=val;
	}
}

function show_mimozemstan(pkey)
{
	if(bg_pos!=-1)
	{
		mimozemstan='parea_'+pkey+'_img_'+bg_pos;
		show_div(mimozemstan);
	}
	
}

function hide_mimozemstan()
{
	if(mimozemstan!='')
	hide_div(mimozemstan);
	mimozemstan='';
}


function show_mapa()
{
	map_portfolio();
	sh_title('none');
	

	var xx=700; // width of ellipse
	var yy=200; // height of ellipse
	var x0=100; // x offset
	var y0=200; // y offset
	var xover=200; // forbidden x overlay
	var yover=20; // forbidden y overlay

	var done=[];

	for(var k=0;k<mapa_links.length;k++)
	{
		var w=1;
		while(w==1)
		{
			var w=0;
			var x=Math.round(Math.random()*xx+x0);
			var y=Math.round(Math.random()*yy*Math.sin(3.14/xx*(x-x0+xx/3))+y0);
			for(var j=0;j<done.length;j++)
			{
				if(x<done[j][0]+xover*2 && x>done[j][0]-xover && y<done[j][1]+yover*2 && y>done[j][1]-yover)
				{
					var w=1;
				}
			}
		}
		
		pos_div('mapa_link_holder_'+mapa_links[k],x,y);
		show_div('mapa_link_holder_'+mapa_links[k]);
		done.push([x,y]);
	}
	
}

function hide_mapa()
{
	for(var k=0;k<mapa_links.length;k++)
	{
		hide_div('mapa_link_holder_'+mapa_links[k]);
	}
}



function mapa_link_color(key,color,bcolor)
{
	var obj=document.getElementById('mapa_link_a_'+key);
	obj.style.color=color;
	obj.style.backgroundColor=bcolor;
}
