Event.observe(window, 'load', function() {

  if(!($('counter')==null) && !($('older_zone')==null) && !($('counter').value<30))
	$('older_zone').hide();

  if(!($('avatar')==null) && !($('avatar_edit')==null)){
  Event.observe('avatar', 'mouseover', function(){$('avatar_edit').show()});
  Event.observe('avatar', 'mouseout', function(){$('avatar_edit').hide()});
  }
  
  if(!($('avatar_edit')==null) && !($('avatar_edit')==null)){
  Event.observe('avatar_edit', 'mouseover', function(){$('avatar_edit').show()});
  Event.observe('avatar_edit', 'mouseout', function(){$('avatar_edit').hide()});
  }
  
  if(!($('prev_foto_album')==null)){
  	Event.observe('prev_foto_album', 'click', function(){show_prev("/fotografii_navigate.html", "album");});
  }
  
  if(!($('next_foto_album')==null)){
  	Event.observe('next_foto_album', 'click', function(){show_next("/fotografii_navigate.html", "album")});
  }
  
    if(!($('prev_foto_grup')==null)){
  	Event.observe('prev_foto_grup', 'click', function(){show_prev_grup("/grup_navigate.html", "grup");});
  }
  
  if(!($('next_foto_grup')==null)){
  	Event.observe('next_foto_grup', 'click', function(){show_next_grup("/grup_navigate.html", "grup")});
  }
  
    
  if(!($('cont_edit')==null)){
  	Event.observe('cont_edit', 'click', function(){cont_edit()});
  }
  
  if(!($('older')==null)){
  	Event.observe('older', 'click', function(){show_older_posts();return false;});
  }

  
    function show_prev(url, obj){
	new Ajax.Request(url+"?pozaId="+$('prevId').value+"&itemId="+$('itemId').value+"", 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('foto').innerHTML= resp;
				
				if($('prevId')==null || $('prevId').value==0)
					$('prev_foto_'+obj).style.visibility = 'hidden';
				else
					$('prev_foto_'+obj).style.visibility = 'visible';

				if($('nextId')==null || $('nextId').value==0)
					$('next_foto_'+obj).style.visibility = 'hidden';
				else
					$('next_foto_'+obj).style.visibility = 'visible';

				if($('delfoto')!=null)
					$('delfoto').href="/del_foto_user.html?id_foto="+$('pozaId').value;
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	if($('last_comm')!=null){
	new Ajax.Request('/comentarii_fotografii_all.html?id_foto='+$('pozaId').value, 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('last_comm').innerHTML= resp;
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	}
  }
  
  function show_next(url, obj){
	new Ajax.Request(url+"?pozaId="+$('nextId').value+"&itemId="+$('itemId').value+"", 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('foto').innerHTML= resp;
				
				if($('prevId')==null || $('prevId').value==0)
					$('prev_foto_'+obj).style.visibility = 'hidden';
				else
					$('prev_foto_'+obj).style.visibility = 'visible';

				if($('nextId')==null || $('nextId').value==0)
					$('next_foto_'+obj).style.visibility = 'hidden';
				else
					$('next_foto_'+obj).style.visibility = 'visible';
				
				if($('delfoto')!=null)
					$('delfoto').href="/del_foto_user.html?id_foto="+$('pozaId').value;

			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	if($('last_comm')!=null){
	new Ajax.Request('/comentarii_fotografii_all.html?id_foto='+$('pozaId').value, 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('last_comm').innerHTML= resp;
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	}

  }
  
  


    function show_prev_grup(url, obj){
	new Ajax.Request(url+"?pozaId="+$('prevId').value+"&itemId="+$('itemId').value+"", 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('foto').innerHTML= resp;
				
				if($('prevId')==null || $('prevId').value==0)
					$('prev_foto_'+obj).style.visibility = 'hidden';
				else
					$('prev_foto_'+obj).style.visibility = 'visible';

				if($('nextId')==null || $('nextId').value==0)
					$('next_foto_'+obj).style.visibility = 'hidden';
				else
					$('next_foto_'+obj).style.visibility = 'visible';
				
				if($('delfoto')!=null && $('ownP').value==1){
					$('delfoto').href="/del_foto_grup.html?id_poza="+$('pozaId').value+"&id_grup="+$('itemId').value;
					$('delfoto').show();
				}
				else
					$('delfoto').hide();
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	if($('last_comm')!=null){
	new Ajax.Request('/comentarii_fotografii_grup_all.html?id_foto='+$('pozaId').value, 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('last_comm').innerHTML= resp;
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	}
  }
  
  function show_next_grup(url, obj){
	new Ajax.Request(url+"?pozaId="+$('nextId').value+"&itemId="+$('itemId').value+"", 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('foto').innerHTML= resp;
				
				if($('prevId')==null || $('prevId').value==0)
					$('prev_foto_'+obj).style.visibility = 'hidden';
				else
					$('prev_foto_'+obj).style.visibility = 'visible';

				if($('nextId')==null || $('nextId').value==0)
					$('next_foto_'+obj).style.visibility = 'hidden';
				else
					$('next_foto_'+obj).style.visibility = 'visible';
				
				if($('delfoto')!=null && $('ownP').value==1){
					$('delfoto').href="/del_foto_grup.html?id_poza="+$('pozaId').value+"&id_grup="+$('itemId').value;
					$('delfoto').show();
				}
				else
					$('delfoto').hide();
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	if($('last_comm')!=null){
	new Ajax.Request('/comentarii_fotografii_grup_all.html?id_foto='+$('pozaId').value, 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('last_comm').innerHTML= resp;
			},
			contentType:'application/x-www-form-urlencoded' 
		}); 
	}

  }



 function cont_edit(){
	new Ajax.Request("/cont_edit.html", 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('about').innerHTML= resp;
			},
			contentType:'application/x-www-form-urlencoded' 
		});
		eval(Behaviour.register(rules));
		return false;
  }

   function show_older_posts(){
	new Ajax.Request("/show_older_posts.html?uid="+$('uid').value+"&page="+$('page').value, 
		{
			asynchronous:false, 
			method:'GET',
			onSuccess:function(transport) {
				var resp = transport.responseText;
				$('older_posts').innerHTML= $('older_posts').innerHTML + resp;
				$('page').value = $('page').value*1+1;
				$('older_posts').focus();
			},
			contentType:'application/x-www-form-urlencoded' 
		});
	return false;
   }
  
});

