$(document).ready(function(){

if ($('#content_in').height() < $('#rr_bl').height() - 21) $('#content_in').height($('#rr_bl').height() - 21);

//Fontsize change
$("#fontsize a").click(function(){
	var $val = parseInt($(this).attr('val')),
		 $currentSize = parseInt($('#content_in').css('fontSize'));
	if (($val == -1 & $currentSize > 11) || ($val == 1 & $currentSize < 19)) $('#content_in').css('fontSize', $currentSize + $val + 'px');
	$('#content_in').height('auto');
   return false;
});

//Search form send
$('#search_bl a.submit').click(function(){
   $('#search_bl form').submit();
	return false;
});

//Search form submit
$('#search_bl form').submit(function(){
	var $val = $(this).find('input[name=query]').val();
	if ($val != $(this).find('input[name=query]').attr('default_val') & $val.length > 0) window.location.href = $(this).attr('action') + $val + '/';
	return false;
});

//Form value switcher /input
$('input.switch').focus(function(){
   var defaultVal = $(this).attr('default_val'),
       currentVal = $(this).val();
   $(this).removeClass('error');
   if (currentVal == defaultVal) $(this).val('');
}).blur(function(){
   var defaultVal = $(this).attr('default_val'),
       currentVal = $(this).val();
   if (currentVal == '') $(this).val(defaultVal);
})


$("a.expandable").click(function(){
   if ($(this).parent().children('ul').css('display') == 'none') {
      var LINK = $(this).attr('href');
      document.title = $(this).text();
      $("h1").html($(this).text());
      $(this).addClass('expanded');
      $(this).parent().children('ul').slideDown('slow');
      $.ajax({
         url: '/index.php?ajax=content',
         data: 'url='+LINK,
         beforeSend: function(){},
         complete: function(){},
         success: function (ajaxOutput) {
            $("#content_text").html(ajaxOutput);
         }
      });
   }
   else {
      $(this).parent().children('ul').slideUp('slow');
      $(this).removeClass('expanded');
   }	  
   return false;
});


//E-mail send
$("form#email_form").submit(function(){
   var LINK = $("a#link_email").attr('href'),
       EMAIL = $('input#to_email').val();
   if (EMAIL == '') {
      $('input#to_email').focus();
      $('input#to_email').css('background', '#FFF399');
   }
   else {
      $.ajax({
         url: '/index.php?ajax=email',
         data: 'url='+LINK+'&email='+EMAIL,
         beforeSend: function(){},
         complete: function(){},
         success: function (ajaxOutput) {
            $("#email_form").html(ajaxOutput);
            $('#toemail').fadeOut(3000);
            $('a#link_email').fadeOut(3000);
         }
      });
   }
   return false;
});


picRotate();
//MAIN!
});

var PIC = 1;
function picRotate () {
      var PICS_NUM = $('#top_pic').attr('count_pics'),
          NEXT = PIC+1;
          if (PIC == PICS_NUM) NEXT = 1;
      var PIC_1 = '#top_pic_'+PIC,
          PIC_2 = '#top_pic_'+NEXT;

$(PIC_1).fadeTo(2000, 1, function () {
   $(PIC_1).fadeOut(3000);
   $(PIC_2).fadeIn(3000);
});

setTimeout(picRotate,15000);

PIC = NEXT;
}

