$(function() {

//$('textarea[title]').each(function() {
//if($(this).val() === '') {
//$(this).val($(this).attr('title'));
//}
//
//$(this).focus(function() {
//if($(this).val() == $(this).attr('title')) {
//$(this).val('').addClass('focused');
//}
//});
//$(this).blur(function() {
//if($(this).val() === '') {
//$(this).val($(this).attr('title')).removeClass('focused');
//}
//});
//});


//投稿画像にマウスオーバーでzoomアイコン表示
$("a.group, a.single").bind('mouseenter', function(){
$(this).children('.zoom').show();
});
$("a.group, a.single").bind('mouseleave', function(){
$(this).children('.zoom').hide();
});


//Noticeを閉じる ///////////////////////////////////////
$('.flash .cancel').click(function(){
$('.flash').hide();
});

//Follow, FllowerTab切り替え ///////////////////////////////////////
$('.followTab01').click(function(){
$('.followCont01').show();
$('.followCont02').hide();
$(this).addClass('active');
$('.followTab02').removeClass('active');
});
$('.followTab02').click(function(){
$('.followCont02').show();
$('.followCont01').hide();
$(this).addClass('active');
$('.followTab01').removeClass('active');
});

//削除ボタンの表示・非表示 ///////////////////////////////////////
$('.bdGrayBox .inner').bind('mouseenter',function(){
$(this).children('.delete').show();
});
$('.bdGrayBox .inner').bind('mouseleave',function(){
$(this).children('.delete').hide();
});

//IE6 PING FIX //////////////////////////////////////
if ($.browser.msie && $.browser.version <= 6){
DD_belatedPNG.fix('.pfix');
}

$('#search_condition_form .open').click(function(){
$(this).hide();
$('#search_condition_form .inner').show();
});

//Roll over 読み込み
PEPS.rollover.init();


commonEvent();

$('a').click(function(){
  commonEvent();
});

if (!$.browser.msie){
$.prettyLoader();
}

}); // documentready end




// Roll over ////////////////////////////////////////

PEPS = {};
PEPS.rollover = {
init: function(){
this.preload();

$(".over").hover(
function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
);},

preload: function(){
$(window).bind('load', function() {
$('.over').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
});},

newimage: function( src ){
return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_over' + src.match(/(\.[a-z]+)$/)[0];
},

oldimage: function( src ){
return src.replace(/_over\./, '.');
}
};



// Roll over end ////////////////////////////////////////

DD_roundies.addRule('.roundAll', '50px', true);
DD_roundies.addRule('.bdGreenBox', '10px', true);
DD_roundies.addRule('#tab a', '5px 5px 0 0', true);
DD_roundies.addRule('#statuses .item', '10px', true);
DD_roundies.addRule('#statuses li', '10px', true);
DD_roundies.addRule('#statuses li .content', '8px', true);
DD_roundies.addRule('#new_status', '10px', true);
DD_roundies.addRule('#status_user_id_links', '5px 5px 0 0', true);
DD_roundies.addRule('.bdGrayBox', '8px', true);
DD_roundies.addRule('.subBox', '10px', true);
DD_roundies.addRule('#follow .tab li a', '5px 5px 0 0', true);
DD_roundies.addRule('#status_user_id_links span', '5px 5px 0 0', true);
DD_roundies.addRule('#status_user_id_links a', '5px 5px 0 0', true);
DD_roundies.addRule('#new_status .round', '5px', true);
DD_roundies.addRule('.flash', '10px', true);
DD_roundies.addRule('#login_or_signup', '10px', true);
DD_roundies.addRule('#bigTitle', '10px', true);
DD_roundies.addRule('.brotherBox', '10px', true);
DD_roundies.addRule('#matching_event', '10px', true);
DD_roundies.addRule('#new_status .content', '10px', true);
DD_roundies.addRule('#search_condition_form', '10px', true);
DD_roundies.addRule('.status_protected', '10px', true);
DD_roundies.addRule('ul.notice', '10px', true);
DD_roundies.addRule('#familyRequest', '10px', true);
DD_roundies.addRule('#followRequest', '10px', true);
DD_roundies.addRule('#broRight', '5px', true);
DD_roundies.addRule('#more_list_loading', '10px', true );
DD_roundies.addRule('.round', '8px', true );
DD_roundies.addRule('.shareList', '8px', true);
// DD_roundies.addRule('.shareList a', '5px', true);
// DD_roundies.addRule('#search_filter_link a', '10px', true );
// DD_roundies.addRule('#search_filter_link span', '10px', true );

function showBros() {
  $('#brotherWrap .left').css({ top:'150px', left:'-260px'});
  $('#brotherWrap .right').css({ top:'150px', right:'-260px'});
  $('#brotherWrap .brotherBox').show();
  $('#brotherWrap .right').animate({ right:'+=290'},3000);
  $('#brotherWrap .left').animate({ left:'+=290'},3000, function(){
    $('#showEvent .btn').fadeIn(1000);
  });
}


function findBros(){
  $('#brotherWrap .brotherBox').hide();
  $('#find').show();
  $(".overlay").show();
  $(".close a").click(function(){
    //$("#find").hide();
    $(".overlay").hide();
  });
}

function showEvent(){
  //$("#find").hide();
  if ($.browser.msie && $.browser.version <= 6){
    $('#talk_with').hide();
  }
  $(".overlay").show();
  $('#showEvent').show();
  var flashvars = {};
  var params = { wmode: 'transparent' };
  var attributes = {};
  swfobject.embedSWF("meet.swf", "flashcontent", "744", "412", "9","", flashvars, params, attributes);
  $(".close a").click(function(){
    $("#showEvent").hide();
    $(".overlay").hide();
    if ($.browser.msie && $.browser.version <= 6){
      $('#talk_with').show();
    }
  });
  $("#showEvent .btn").click(function(){
    $("#showEvent").hide();
    $(".overlay").hide();
    if ($.browser.msie && $.browser.version <= 6){
      $('#talk_with').show();
    }
  });
}

$(window).load(function(){
$('#album .pic').each(function(){
  var imgHeight = $(this).parent('span').height();
  var imgWidth = 60
  var MarginH = -(imgHeight - 60) / 2+'px';
  if (imgHeight < imgWidth){
    $(this).removeAttr('width').attr('height','60');
    var imgWidth = $(this).parent('span').width();
    var MarginW = -(imgWidth - 60) / 2 +'px';
    $(this).css( 'margin-left',MarginW);

  }
  else {
    $(this).removeAttr('height').attr('width','60');
    $(this).css( 'margin-top',MarginH);
  }
});
});


function commonEvent(){
  //タブ：人とわんこの切り替えの現在表示
  var thisURL = location.href;
  var checkRoot = thisURL.indexOf('/home');
  var checkHome = thisURL.substring(checkRoot,100);
  var checkDomain = location.hostname;
  var userHome = $('#footer .none').html();
  var topURL = "http://"+checkDomain+"/";
  if( thisURL == topURL){
  $('#navigation a:first').addClass('current');
  }
  if( checkHome == '/home'){
  $('#navigation a:first').addClass('current');
  }
  if(checkHome == userHome){
  $('#navigation a:first').addClass('current');
  }
  $('#navigation a:not(:first)').each(function(){
  var thisLink = $(this).attr('href');
  if(thisLink == checkHome){
  $(this).addClass('current');
  }
  });
  //fancybox/////////////////////////////////////////
  $("a.group, a.single").fancybox({
  'zoomSpeedIn':300,
  'zoomSpeedOut':300,
  'overlayShow':true
  });

  //投稿画像にマウスオーバーでzoomアイコン表示
  $("a.group, a.single").bind('mouseenter', function(){
  $(this).children('.zoom').show();
  });
  $("a.group, a.single").bind('mouseleave', function(){
  $(this).children('.zoom').hide();
  });


  //Noticeを閉じる ///////////////////////////////////////
  $('.flash .cancel').click(function(){
  $('.flash').hide();
  });

  //Follow, FllowerTab切り替え ///////////////////////////////////////
  $('.followTab01').click(function(){
  $('.followCont01').show();
  $('.followCont02').hide();
  $(this).addClass('active');
  $('.followTab02').removeClass('active');
  });
  $('.followTab02').click(function(){
  $('.followCont02').show();
  $('.followCont01').hide();
  $(this).addClass('active');
  $('.followTab01').removeClass('active');
  });

  //削除ボタンの表示・非表示 ///////////////////////////////////////
  $('.bdGrayBox .inner').bind('mouseenter',function(){
  $(this).children('.delete').show();
  });
  $('.bdGrayBox .inner').bind('mouseleave',function(){
  $(this).children('.delete').hide();
  });

  //IE6 PING FIX //////////////////////////////////////
  if ($.browser.msie && $.browser.version <= 6){
  DD_belatedPNG.fix('.pfix');
  }

  $('#search_codition_form .open').click(function(){
  $(this).hide();
  $('#search_codition_form .inner').show();
  });

  //シェアの表示・非表示

  $(".shareList ul").show();
  $(".shareList ul").each(function(){
  $shareHeight = $(this).height();
  if($shareHeight > 30){
        $(this).parent().children('.switch').show();
        $(this).height('29px');
  }
  });

  $(".shareList .switch").click(function(){
  $(this).parent().children('ul').css('height','auto');
  $(this).hide();
  });

  //写真をさわると拡大してプロフィール表示 //////////////////////////////////////
  $('.card').mouseover(function(e){
  avHeight = $(this).children('a').height();
  avWidth = $(this).children('a').width();
  var digest = $(this).children('.userDigest')[0];
  if (digest.innerHTML.match(/^[ ]*$/)) {
      digest.id.match(/user_digest_(.*?)_(.*?)$/)
      var user_id = RegExp.$2;
      $(digest).load('/users/'  + user_id + '/avatar_card');
  }
  $(this).animate({
        width:'250px',
        height:'90px'
  },30,function(){
      $(digest).show();
  });
  $(this).css('z-index','29');
      return false;
  });

  $('.card').bind('mouseleave',function(){
  $(this).animate({
        width: avWidth,
        height: avHeight
  },30,function(){
  $(this).css('z-index','1');
  $(this).children('.userDigest').hide();
  });
  });



}

