function populateOrase($tara, $oras, def) {
  $tara.change(function() {
    $oras.html('');
    if (def) {
      $oras.append('<option value="">' + def + '</option>');
    }
    $.getJSON('/main/oraseJson', {tara_id: $(this).val()}, function(orase) {
      for (i in orase) {
        oras = orase[i];
        $oras.append('<option value=' + oras.id + '>' + oras.nume + '</option>');
      }
    });
  });
}
  
function addComment(id, table) {
	if ($('#desc').val() == "") {
    return;
  }
  val=$('#nr1').html();
  $.get('/comment/adauga' + table, {id: id, comment: $("#desc").val(), ajax: true},
    function (response) {
      $('#nr1').html(parseInt(val)+1);
      $('#nr2').html(parseInt(val)+1);
      $('#comment').hide();
      $('#comments').prepend(response);
      $('#desc').val("");
      $('#noComm').hide();
    }
  );
}
  
function addSmiley(text, $box) 
{
  if (! $box) {
    $box = $("#desc");
  }
  $box.val($box.val() + text + ' ');
  $box.trigger('keyup');  
} 
   
function animateThumbnails()
{  
  $("li.animateThumbnails a img").bind("mouseover", function(){
    $(this).everyTime(500, 'controlled', function(){
      id = $(this).attr('id');
      videoId = id.split("_")[1];
      i = parseInt(id.split("_")[2]);
      nextI = i + 1;
      
      nextSrc = $('#' + videoId + '_' + nextI).val();
      if (! nextSrc){
        nextI = 0;
        nextSrc = $('#' + videoId + '_' + nextI).val();
      }
      if (i != nextI) {
        $(this).attr('src', nextSrc);
        $(this).attr('id', 'img_' + videoId + '_' + nextI);
      }
    });
  }).bind("mouseout", function(){
    $(this).stopTime('controlled');
    
    id = $(this).attr('id');
    videoId = id.split("_")[1];
    firstSrc = $('#' + videoId + '_' + 0).val();
    $(this).attr('src', firstSrc);
    $(this).attr('id', 'img_' + videoId + '_' + 0);
  });
}
   
$(document).ready(function() {
  $('.blink').blink();
  animateThumbnails();
  
  var cur_img_src = '';
  var cur_id = 0;  
	$("div.image-list1 ul a img").bind("mouseover",function(){
		var i=1;
		cur_id=$(this).attr('id');
		cur_id=cur_id.split("_")[0];
		var img=cur_id+'_0';
		cur_img_src=$('#'+img).attr('src');
 
		$('#'+img).everyTime(500, 'controlled', function(){
			if($('#'+cur_id+'_'+i).val()!="" || i==0){
				if(i==0){
					$('#'+img).attr('src',cur_img_src);
				}else{
					$('#'+img).attr('src',$('#'+cur_id+'_'+i).val());
				}
			}
			if(i>4) i=0;
			else i++;
		});
	}).bind("mouseout",function(){
		$(this).stopTime('controlled');
		$('#'+cur_id+'_0').attr('src',cur_img_src);
	});  
});

