opac = new Array();
fader = new Array;
currentFader = 0;
currentEl = false;
faderArray = new Array();
searchValue = '';

function fadeObj(el)
{
  var id;
  var opacity = 0;
  this.go = go;
  this.update = update;
  this.reset = reset;
  this.opacity = opacity;
  this.el = el;
  
  
  function go()
  {
    fadeId = el + "fade";
    s = "faderArray['"+fadeId+"'].update('" + el + "')";
    this.id = setInterval(s, 25);
  }

  function update()
  {
    if (this.opacity >100) 
    {
      clearInterval(this.id);
      this.opacity = 0;
    }
    else
    {
      this.opacity += 10;
      changeOpac(this.opacity, el);
    }
  }
  
  function reset()
  {
    this.opacity = 0;
    changeOpac(0, this.el);
    clearInterval(this.id);
  }
}

function fadeMenu(el)
{
  fadeId = el + "fade";
  if (typeof faderArray[fadeId] == 'object')
  {
    faderArray[fadeId].reset();
    faderArray[fadeId].go();
  }
  else 
  {
    faderArray[fadeId] = new fadeObj(el);
    faderArray[fadeId].go();
  }
}
  
function openCenter(id, url, width, height, properties)
{
  if (screen)
  {
    x = (screen.availWidth - width) / 2;
    y = (screen.availHeight - height) / 2;
  }
  r = window.open(url, id, properties+',width='+width+',height='+height+',screenX='+x+',screenY='+y+',left='+x+',top='+y);
}

function toonProfiel(id){
	openCenter ('profiel', '/profile/?'+id, 520, 590, 'scrollbars=no,status=no,toolbar=no')
}

function toonMatch(id){
	openCenter ('profiel', '/profiel/match.php?'+id, 488, 560, 'scrollbars=no,status=no,toolbar=no')
}

function userSelect(){
        openCenter ('user', '/profiel/msg/popup.php?', 600, 520, 'scrollbars=no,status=no,toolbar=no')
}

function mailpopUp(id){
	openCenter ('mail', 'mail.php?id='+id, 300, 240, 'scrollbars=no,status=no,toolbar=no');
}

function favpopUp(id){
	window.open ('fav.php?id='+id, 'email', 'scrollbars=no,status=no,toolbar=no,width=300,height=240')
}

function ConfigCam(){
  openCenter ('cam', 'configcam.php', 400, 200, 'scrollbars=no,status=no,toolbar=no')
}

function ConfigMood(){
  openCenter ('moo', 'configmood.php', 400, 200, 'scrollbars=no,status=no,toolbar=no')
}

function addFav(id)
{
  if (confirm("Deze foto toevoegen aan je favorieten?"))
  window.open('/toon/fav.php?id='+id+'&add=1', 'fav', 'scrollbars=auto,status=no,toolbar=no,width=1,height=1');
}

function DoConfirm(url, text)
{
  if (confirm(text))
    location.href=url;
}


function regpopUp(){
	window.open ('/profiel/reg.php', 'reg', 'scrollbars=no,status=no,toolbar=no')
}
function nieuws(){
        window.open ('nieuws.php', 'nws', 'scrollbars=no,status=no,toolbar=no,width=500,height=400')
}
function privee(){
        window.open ('privee.php', 'privee', 'scrollbars=no,status=no,toolbar=no,width=256,height=256')
}

function toonProfielFoto(id){
	window.open ('/profiel/toon_profielfoto.php?'+id, 'profielfoto','scrollbars=auto,status=no,toolbar=no,width=640,height=480')
}

function toonExtraFoto(id){
	window.open ('/profiel/toon_extrafoto.php?'+id, 'extrafoto','scrollbars=auto,status=no,toolbar=no,width=640,height=480')
}

function openChat(){
	window.open ('/profiel/chat/chat.php', 'fdchat','scrollbars=auto,status=no,toolbar=no,width=650,height=510')
}

function openOnline(){
	window.open ('/profiel/online/index.php', 'online','scrollbars=auto,status=no,toolbar=no,width=220,height=210')
}

function delextraconfirm(id, type){
if (confirm("Deze extra optie verwijderen? Je krijgt maar 80% van de sterren terug!"))
 window.open('/profiel/bewerken/go_delextra.php?id='+id+'&t='+type,'delextra', 'scrollbars=auto,status=no,toolbar=no,width=650,height=450');
}

function deliconconfirm(id, type){
if (confirm("Dit icoon verwijderen?"))
 window.open('/profiel/bewerken/go_delextra.php?id='+id+'&t='+type,'delextra', 'scrollbars=auto,status=no,toolbar=no,width=650,height=450');
}

function submitSerieFeest(){
var form = document.fotoserie;
var optie=form.t.options[form.t.options.selectedIndex].value
if(optie) document.location.href='/dossier/?type='+optie;
}

function submitSerieJaar(){
var form = document.fotoserie;
var optie=form.j.options[form.j.options.selectedIndex].value
if(optie) document.location.href='/lijst/index.php?j='+optie;
}

function submitSerieAnders(){
var form = document.fotoserie;
var optie=form.a.options[form.a.options.selectedIndex].value
if(optie) document.location.href='/lijst/index.php?'+optie;
}

function jumpMaand(j)
{
  form = document.filter.mnd;
  var mnd=form.options[form.options.selectedIndex].value;
  if(mnd) document.location.href='/lijst/index.php?j='+j+'&mnd='+mnd;
}

function jump(url, p, e)
{
 var e = document.getElementById(e);
 var waarde = e.options[e.options.selectedIndex].value;
 if (waarde) document.location.href=url+'&'+p+'='+waarde;
}

function addFriend(id){
if (confirm("Dit profiel toevoegen aan je vriendenlijst?"))
 document.location.href='/profiel/addfriend.php?'+id;
}

function delFriend(id){
if (confirm("Dit profiel verwijderen uit je vriendenlijst?"))
 document.location.href='/profiel/delfriend.php?'+id;
}

function stealEmo(id)
{
  _extraChild = openCenter('extra', '/p/popup/extra.php?type=ico&id='+id, 640, 420, 'scrollbars=auto,status=no,toolbar=no');
}

function getInfo(url, toId, event)
{
  clearTimeout(fader);
  opac[currentFader] = 0;
  fader = false;
  changeOpac(0, toId);

  Xget(url, toId, function(){fadeMenu(toId)});
  openMenu(event, toId);
}

var infoT;

function getInfoStatic(url, toId)
{
  clearTimeout(infoT);
  clearTimeout(fader);
  opac[currentFader] = 0;
  fader = false;
  changeOpac(0, toId);

  Xget(url, toId, function(){ fadeMenu(toId); infoT = window.setTimeout( "killMenu('"+toId+"')", 3000) } );
  showFixedMenu(toId);
}

var pT;
function previewProfilePic(picId, toId, event)
{
  l = document.getElementById(toId);
  l.innerHTML = '<a href="javascript:Pg('+picId+')"><img class="thumb" src="/toon/pictn_extra.php?id='+picId+'" /></a>';
  
  clearTimeout(pT);
  clearTimeout(fader);
  opac[currentFader] = 0;
  fader = false;
  changeOpac(0, toId);
  openMenu(event, toId);
  fadeMenu(toId); 
  pT = window.setTimeout( "killMenu('"+toId+"')", 3000)
}

function staticMenu(event, toId)
{
  clearTimeout(fader);
  opac[currentFader] = 0;
  fader = false;
  changeOpac(0, toId);
  openMenu(event, toId);
  fadeMenu(toId);
}

function changeOpac(opacity, id) 
{
  var object = document.getElementById(id).style; 
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
}

function isEmail(src)
{
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
}

function X()
{
  return;
}

function submitQuickSearch()
{
  if (searchValue)
    window.location.href="/zoek/?q=" + searchValue;
}

// ruimte voor status van effecten/slides bij
var myEffects = [];
var slideState = [];

// schuift een element omhoog of naar benenden afhankelijk van zn status.
function slide( id )
{
  if ( !myEffects[ id ] )
  {
    if ( !slideState[ id ] )
    {
      slideState[ id ] = 0;
      myEffects[ id ] = new Effect.SlideDown( id,{duration:.5,afterFinish:slideCallback} );
    }
    else
    {
      myEffects[ id ] = new Effect.SlideUp( id,{duration:.5,afterFinish:slideCallback} );
    }
  }
  return false;  
}

function slideCallback ( obj )
{
  id = obj.element.id;
  myEffects[ id ] = null;
  slideState[ id ] = slideState[ id ] ? 0 : 1; // state swappen :)
}