$(document).ready(function() {
  //IE6 :hover Fix
  if ($.browser.msie && $.browser.version.substr(0,1)<7) {
    $('#highlight-projekte a').hover(
      function() {
        $(this).addClass('over');
      },
      function() {
        $(this).removeClass('over');
      });
    }

    $('#highlight-projekte').prepend('<a class="btn close">Ausblenden</a>');

    function close_projects(close, direct){
      if(close){
        $.cookie('hide_projects', 1);
        div = $('#highlight-projekte .close').text('Einblenden').parent().find('.toggle');
		(direct) ? div.hide() : div.slideUp();
      }else{
        $.cookie('hide_projects', null);
        $('#highlight-projekte .close').text('Ausblenden').parent().find('.toggle').slideDown();
      }
    }


    if($.cookie('hide_projects')){
      close_projects(true, true);
    }


    $('.close').click(function(){
      close_projects(($.cookie('hide_projects') ? 0 : 1));
    });



    //Suchfeld
    $('#search :text').each(function(){
      $(this).data('v',$(this).val()).bind('focus blur',v);
    });

    //Comment - Magic
    var mail = $("#email").val();
    if(mail){
      $('#vcard img').attr('src', 'http://www.gravatar.com/avatar/' + MD5(mail) + "?s=75&d=identicon"); 
      $("#commentform #email").blur(function() {
        mail = $("#commentform #email").val();
        $('#vcard img').attr('src', 'http://www.gravatar.com/avatar/' + MD5(mail) + "?s=75&d=identicon");  		
      });

      $('#vcard cite').html($("#commentform #author").val());
      $("#commentform #author").keyup(function() {
        var author = $(this).val();
        $('#vcard cite').html(author);  		
      });

      $('#url').val('Website').blur(function() {
        if($(this).val() ==""){
          $(this).val('Website');
        } 		
      });
      $('#commentform #url').focus(function() {
        if($(this).val() == "Website"){
          $(this).val('');
        }
      });
      $('#commentform #author').focus(function() {
        if($(this).val() == "Name"){
          $(this).val('');
        }
      });
      $('#commentform #email').focus(function() {
        if($(this).val() == "Email"){
          $(this).val('');
        }
      });

      $('#commentform #submit').click(function() {
        var tmp = $('#url').val();
        if(tmp == "Website"){
          $('#url').val('');
        }
      });	
    }
    
    $('a.retweet').retweet();
    
    $('#sponsoren').cycle({
      fx:'scrollHorz',
      speed:500,
      timeout:2000,
      pause:1,
      random: 1,
      easing: 'easeOutQuad'
    });

    FB_RequireFeatures(["XFBML"],
    function(){
      FB.Facebook.init("cd466f434c62d75c0ba59602150b4d66","http://www.du2010.de/xd_receiver.htm");
      //$('a.retweet').FBShare();
    }
  );	
});

function v(e){
  y=$(this);D=y.data('v');V=$.trim(y.val());
  if(!V||V==D)y.val((V==D&&!(e.type=='blur')?true:false)?'':D);}
