$(document).ready(function(){

$("a.expandable").click(function(){
   if ($(this).parent().children('ul').css('display') == 'none') {
      var LINK = $(this).attr('href');
      document.title = $(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_in").html(ajaxOutput);
            $("a#link_email").attr('href', LINK);
            $("a#link_print").attr('href', LINK+'print/');
            $("a#link_pdf").attr('href', LINK+'pdf/');
         }
      });
   }
   else {
      $(this).parent().children('ul').slideUp('slow');
      $(this).removeClass('expanded');
   }	  
   return false;
});


//E-mail form show/hide
$("a#link_email").click(function(){
   if ($('#toemail').css('display') == 'none') {
      $('#toemail').fadeIn('slow');
      $('input#to_email').focus();
   }
   else {
      $('#toemail').fadeOut('fast');
   }
   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;
});


//Formular check
$("form#formular_form").submit(function(){
   $('#error_message').slideUp();
   $('tr').removeClass('tbl_error');
   $('tr td div').removeClass('tbl_error');
   ERROR = 0;

   if ($('input:checked[name="form[0]"]').length == 0) {$('input[name="form[0]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[2]"]').val() == '') {$('input[name="form[2]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[3]"]').val() == '') {$('input[name="form[3]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[4]"]').val() == '') {$('input[name="form[4]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[5]"]').val() == '') {$('input[name="form[5]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[6]"]').val() == '') {$('input[name="form[6]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[7]"]').val() == '') {$('input[name="form[7]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[8]"]').val() == '') {$('input[name="form[8]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input[name="form[10]"]').val() == '') {$('input[name="form[10]"]').parents('tr').addClass('tbl_error'); ERROR = 1;}
   if ($('input:checked[name="form[12]"]').length == 0) {$('input[name="form[12]"]').parent().addClass('tbl_error'); ERROR = 1;}
   if ($('input:checked[name="form[13]"]').length == 0) {$('input[name="form[13]"]').parent().addClass('tbl_error'); ERROR = 1;}
   if (ERROR == 0) $(this).submit();
   else {$(window).scrollTop('0'); $('#error_message').slideDown();}

   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;
}

