function loadGenres(id, selected){
  if (selected == null) {
    var selected = 0;
  }

  var url = 'ajax/loadGenres.php';
  $('#genres').load(url, {"id": id, 'selected': selected});

}

function addComments(count) {
  var url = 'ajax/addComments.php';;
  $('#comments').load(url, {"tid": $('#tid').val(), "count": count, "text": $('#text').val()});

}

function addThanks() {
  var url = 'ajax/addThanks.php';;
  $('#thanks').load(url, {"tid": $('#tid').val()});

}

function addRating(type, id) {
  if (type == 'up') {
    var url = 'comment.php?action=rateup';
  } else {
    var url = 'comment.php?action=ratedown';
  }
  $('#rating_' + id).load(url, {"cid": id});

}

function submitFilter(id) {
  $(':checkbox:checked').each(function(i){
    $(this).attr('checked', false);
  });
  
  $('#c' + id).attr('checked', true);
  
  document.filter.submit(); 
}

function showComment(id) {
  $('#c_' + id).show();
  $('#t_' + id).show();
  $('#a_' + id).hide();
}

$(document).ready(function(){

	//$('#imdb').hide();
	$('#simdb').click(function(){
	var scr=$('html,body').scrollTop();
	$('#imdb').toggle();
	if($('#imdb').is(':hidden'))
	{
		$('#simdbt').text("Rodyti");
		$('#simdbi').attr("src", "./pic/plus.jpg");
	
	}
	else
	{
		$('#simdbt').text("Slėpti");
		$('#simdbi').attr("src", "./pic/minus.jpg");
	}
	});

	$('#crit').hide();
	$('#scrit').click(function(){
		
	$('#crit').toggle();
	if($('#crit').is(':hidden'))
	{
		$('#scritt').text("Rodyti");
		$('#scriti').attr("src", "./pic/plus.jpg");
		//var xtr = 300; // 100 provides buffer in viewport
		//$('html,body').animate({scrollTop: xtr}, 50);
		$('html,body').scrollTop(scr);
	
	}
	else
	{
		$('#scritt').text("Slėpti");
		$('#scriti').attr("src", "./pic/minus.jpg");
		var xtr = $('#scritt').offset().top - 100; // 100 provides buffer in viewport
		$('html,body').animate({scrollTop: xtr}, 50);

	}
	});


	$('.story.cnt').hide();
	$('#acnt1').click(function(){
		$('.story.cnt').hide();
		$('#cnt1').show();
	});
	$('#acnt2').click(function(){
		$('.story.cnt').hide();
		$('#cnt2').show();
	});
	$('#acnt3').click(function(){
		$('.story.cnt').hide();
		$('#cnt3').show();
	});
	$('#acnt4').click(function(){
		$('.story.cnt').hide();
		$('#cnt4').show();
	});



});

function downscale_images()
{
	try {
		var a = document.getElementById('downscale');
		var f = a.getElementsByTagName('img');
		for (var i = f.length - 1; i >= 0; i--)
		{
			if (f[i].width > 710)
			{
				f[i].width = 710;
			}
		}
	} catch (e) { }
	
	try {
    var a = document.getElementById('downscale2');
    var f = a.getElementsByTagName('img');
    for (var i = f.length - 1; i >= 0; i--)
    {
      if (f[i].width > 128)
      {
        f[i].width = 128;
      }
    }
  } catch (e) { }
}

window.onload = downscale_images;


