function updateFile(elemID) {
  $(elemID+'x').value = $(elemID).value;
  if ($(elemID).value != '') {
    $(elemID+'btn').style['display'] = 'inline';
  }
}

function clearFile(elemID) {
  $(elemID).value = '';
  $(elemID+'x').value = '';
  $(elemID+'btn').style['display'] = 'none';
}

function __deleteContact(imgElm) {
  m = imgElm.parentNode.parentNode;
  tblElm = m.parentNode;
  m.parentNode.removeChild ( m );
  reSetRows ( tblElm );
}

function __addContact(rowElm) {
  rowElm.parentNode.appendChild ( rowElm.cloneNode ( true ) );
  rowElm.onclick = function () { };
  reSetRows ( rowElm.parentNode );
  rowElm.getElementsByTagName ( 'img' ) [ 0 ].style [ 'display' ] = 'inline';
}

// Function to reSet the row colors
function __reSetRows ( tblElm ) {
  trs = tblElm.getElementsByTagName('tr');
  b = 'row0';
  for (a = 0; a < trs.length; a++)
    trs[a].className = (b = b == 'row0' ? 'row1' : 'row0');
}

// Function for updating function
function __changeFunctionField ( drpdwnElm ) {
  inptElm = drpdwnElm.parentNode.getElementsByTagName('input')[0];
  // If vwb is --other-Holder-- then show textfield
  if (drpdwnElm.value == '--other-Holder--') {
    // Show textfield
    inptElm.type = 'text';

    // Hide select
    drpdwnElm.style['display'] = 'none';
  } else  {
    if (drpdwnElm.options[0].value == '' && drpdwnElm.options[0].text == 'Selecteer') {
      drpdwnElm.options [ 0 ] = null;
    }

    // Just set the value
    inptElm.value = drpdwnElm.value;
  }
  return false;
}

function cyclePreviewPhotos(x) {
  pics = $$('.photoHolder');
  if (pics.length >0)
  {
	  if (pics.length <= 1) {
		pics[0].fade('in');
		return false;
	  }
	  pics[(x-1) % pics.length].fade('out');
	  pics[x % pics.length].fade('in');
	  (function(){ cyclePreviewPhotos(x+1); }).delay(4000);
  }
}

function submitForm(formID) {
  $(formID).submit();
}


function showComments(photoID) {
	var urlAjax = PHOTO_ROOT+'comments/';
   var myRequest = new Request.HTML({
                         url:urlAjax,
                         method:'get',
                         update:'light',
						 onComplete: function(result) {
							$('light').setStyle('display', 'block');
							loadEmoticons();
						 }
                       });
   myRequest.send('photoID='+photoID);
   return false;
}

function loadEmoticons() {
    $each($$('.emoticon'), function(img) {
      img.addEvent('click', function() {
        $('message').value += ':'+img.title+':';
      });
    });
    $('emoticons').style['display'] = 'block';
}


window.addEvent('domready', function() {
  $each($$('.hide'), function(elem) {
    elem.fade('hide').removeClass('hide');
  });

  if ($('emoticons')) {
	loadEmoticons();
  }

  if ($('fotoHider')) {
    $('fotoHider').style['display'] = 'block';
    cyclePreviewPhotos(1);
  }
});
