
$(document).ready(function(){
  
  //transparent form
  $('.form').css("opacity","0.8");
  
  //no mobile device is that big, yet
  if($(window).width() > 800) {
  
    $('.form h3').toggle(function(){
      $('.form dt').slideUp();
      $('.form').fadeTo("slow","0.1");
    },function(){
      $('.form dt').slideDown();
      $('.form').fadeTo("slow","0.8");
    });

    $('img[title]').qtip({
      style: {
        border: {
          width: 5,
          radius: 10
        },
        padding: 10, 
        name: 'blue',
        tip: true
      },
      position: {
        adjust: { screen: true },
        corner: { target: 'topRight', tooltip: 'bottomLeft' }
      }
    });
    
    //try{
    
    $('.body .function span:contains("No.")').each(function(){
      $(this).click(function() {
        $('#form_reply #form_body').val($('#form_reply #form_body').val() + '>>' + $(this).text() + '\n\n');
      });
    });
    
    var newlineindex = 0;
    $('.body .text p:contains(">>No.")').each(function(){
      newlineindex = ($(this).text().indexOf("\n") > 0) ? $(this).text().indexOf("\n") : $(this).text().length;
      
      $(this).qtip({
        content: $( '#item-'+$(this).text().substr(0,newlineindex).replace(/[^0-9]/g, '')+' .image, #item-'+$(this).text().substr(0,newlineindex).replace(/[^0-9]/g, '')+' .text' ),
        style: {
          width: 400,
          border: {
            width: 5,
            radius: 10
          },
          padding: 10, 
          name: 'blue',
          tip: true
        },
        position: {
          //adjust: { screen: true },
          corner: { target: 'topLeft', tooltip: 'bottomLeft' }
        }
      });
      
      $(this).click(function(){
        var destination = $('#item-'+$(this).text().substr(0,newlineindex).replace(/[^0-9]/g, '')).offset().top;
        $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
      });

    });

    //} catch (e) {}
   
  //endif
  } else {
  
    $('.form h3').toggle(function(){
      $('.form dt').slideUp();
      $('.form').fadeTo("slow","0.1");
    },function(){
      $('.form dt').slideDown();
      $('.form').fadeTo("slow","0.8");
    });
  
    //put it to the left
    $('#menu').css("position","static");
    $('.form').css({'position' : 'static', 'overflow' : 'hidden', 'min-width' : '100px', 'width' : '70%'});
    $('.body').css("overflow","visible");
    $('.text').css({'overflow' : 'visible', 'max-width' : '90%', 'clear' : 'both' });
  }
  
});