//moving clouds
var agent=navigator.userAgent.toLowerCase();
var is_iphone = (agent.indexOf('iphone')!=-1);
var cloudssection=new Array();
var stagespace=1000;

cloudssection[1]=new Array(); cloudssection[1]['w']=70; cloudssection[1]['p']=630;
cloudssection[2]=new Array(); cloudssection[2]['w']=112; cloudssection[2]['p']=350;
cloudssection[3]=new Array(); cloudssection[3]['w']=141; cloudssection[3]['p']=900;
cloudssection[4]=new Array(); cloudssection[4]['w']=93; cloudssection[4]['p']=120;
cloudssection[5]=new Array(); cloudssection[5]['w']=70; cloudssection[5]['p']=230;

var movespace='';
var scrollspace=0;
pag_sections_height=new Array( 200,		750,				750,			750,				750					);
pag_sections_name=new Array(   'top',	'section_about',	'section_main',	'section_works',	'section_goodies'	);

function $(id) {
 return document.getElementById(id);
}

function smoothto(whereto) {
wheretoreal=whereto;
 if(scrollspace == 1) {return false;}
 if(whereto == 'section_about_who') { whereto='section_about';}
 if(whereto == 'section_about_contact') { whereto='section_about';}
 scrollspace=1;
 wheretoscroll=0;
 wherefromscroll=topget();
 for(smt=0;smt<pag_sections_name.length;smt++) {
  if(smt>0) {wheretoscroll+=pag_sections_height[smt-1]}
  if(pag_sections_name[smt] == whereto) {smt=pag_sections_name.length;}
 }
 if(wherefromscroll==wheretoscroll) {
  scrollspace=0;
  window.location='#'+wheretoreal;
  return false;
 }else{
	 window.paused=1;
	clearInterval(int_TJPfloat);
	clearInterval(int_TJPskys);
 }

 $('kolatv').style.height='0';
 tmp=new Array();
 steps=20;
 for(smt=1;smt<=steps;smt++) {
  pt=smt/steps;
  if(pt == .5) {
   multi=1.5
  } else {
   multi=(Math.sqrt(Math.abs(2*pt-1))*(2*pt-1)/Math.abs(2*pt-1)+1)/2;
  }
  multi=Math.sqrt(smt/steps);
  tmp[smt]='window.scroll(0,'+(wherefromscroll+(wheretoscroll-wherefromscroll)*multi)+');';
 }
 tmp[steps]+="window.location='#"+wheretoreal+"';$('kolatv').style.height='278px'; scrollspace=0;";
  tmp[steps]+=" window.int_TJPskys=undefined; window.int_TJPskys=setInterval('TJPskys();',200);";
tmp[steps]+="window.int_TJPfloat=undefined; window.int_TJPfloat=setInterval('TJPfloat();',50);";
tmp[steps]+="window.paused=0; ";
 //alert(tmp.join("\n"));
 ttt=Math.random();
 setTI(ttt,10);
 return false;
}

function topget() {
 return (self.pageYOffset)?(self.pageYOffset):((document.documentElement && document.documentElement.scrollTop)?(document.documentElement.scrollTop):(document.body.scrollTop));
}

function kolaresize() {
  d=document.body.clientWidth;
  if(d && d>1000) {
    stagespace=d;
  }
  if($('inter4')) {
   if (self.innerHeight) {
	ch = self.innerHeight;
   }
   else if (document.documentElement && document.documentElement.clientHeight) {
	ch = document.documentElement.clientHeight;
   }
   else if (document.body) {
	ch = document.body.clientHeight;
   }
   if(ch>600) {
    $('inter4').style.height=(ch-534)+'px';
   }
  }
}

function kolainit(section) {
 if(section == 'inter0' && !is_iphone) {
	
  kolaresize();
  window.onresize=kolaresize;
  for(i=1;i<cloudssection.length;i++) {
   cloudssection[i]['p']*=d/1000;
  }
  //if(tmp.split('#')[1] == '' || tmp.split('#')[1] == 'section_main') {
  // setTimeout('scroll(0,200);',100);
  //}
 
 }
 else if(section == 'about') {

  window.int_TJPfloat=setInterval("TJPfloat();",50);
  tmp=location.href+'#'; 
 }
}
window.paused=0;
function kolapapratio(vpr) {

		 ratios=new Array('16by10','4by3');
		 for(r in ratios) {
		  $('wpb_'+ratios[r]).className=((ratios[r] == vpr)?('active'):(''));
		 }
		 for(i=1;i<=8;i++) {
		  $('kolapaper_'+i).href='images/goodies/kolapaper'+i+'_-_'+vpr+'.png';
		 }
		 //$('kolapaper_9').href='images/goodies/kolapapers_-_'+vpr+'.zip';
		 return false;
		}
		function TJPmovecloud(cid,pos) {
		 if(pos > stagespace && window.paused>0 ) {
		  return;
		 }
		 if(pos+cloudssection[cid]['w']>stagespace) {
		  $('s_cloud'+cid).style.width=stagespace-pos+'px';
		 } else {
		  $('s_cloud'+cid).style.width=cloudssection[cid]['w']+'px';
		 }
		 $('s_cloud'+cid).style.left=pos+'px';

}

function TJPhandlemouse(evt,obj) {
 var evt = evt?evt:window.event?window.event:null; if(!evt) { return false; }
}

function TJPfloat() {
 
 if($('inter1')) {
  for(i=1;i<cloudssection.length;i++) {
   if(cloudssection[i]['p'] >= stagespace) {cloudssection[i]['p']=-cloudssection[i]['w'];}
   else if(cloudssection[i]['p'] <= -cloudssection[i]['w']) {cloudssection[i]['p']=stagespace;}
   cloudssection[i]['p']-=1+cloudssection[i]['w']/200;
   TJPmovecloud(i,cloudssection[i]['p']);
  }
 }
}

function projectselect (pid,pnum) {
 ext='jpg'; if(pid == 'imroz') {ext='png';}
 pidugyfel=pid.split('/#');
 if(!pidugyfel[1]) {pidugyfel[1]=pidugyfel[0];}
 //alert($('projectinfo_img'));
 setCookie('currentproject',pid); $('projectinfo_img').style.backgroundImage='url(refs/'+pidugyfel[0]+'/images/cover_'+pidugyfel[1]+'.'+ext+')';
$('projectinfo_img').style.cursor='pointer';
$('projectinfo_img').onclick=function(){document.location='refs/'+pid}
$('projectinfo_title').innerHTML=refs[pid]['title'];
 $('projectinfo_link').href='refs/'+pid;

 $('projectinfo_desc').innerHTML='';
 
 tmpi=0; tmp=new Array();
 for(di=0;di<=refs[pid]['desc'].length;di+=4) {
  tmp[tmpi]="$('projectinfo_desc').innerHTML=refs['"+pid+"']['desc'].substr(0,"+di+");";
  tmpi++;
 }
 tmp[tmpi]="$('projectinfo_desc').innerHTML=refs['"+pid+"']['desc']";

 for(psi=1;psi<=28;psi++) {
  $('ref_button_'+psi).className=(psi == pnum)?('active'):('');
 }
 return false;
}