jQuery(document).ready(function($){
   $('a.twitter-icon').click(function(e){
	window.open ($(this).attr('href'),"Follow Attwater on Twitter", "width=600, height=270");
	e.preventDefault();
   });
   
   
   $('.node-type-video #region-content').removeClass('grid-10').addClass('grid-16');
   
   
   //videos
   videos = $('a.yt-video');
   if(videos.length){
	mainTubeTop = $('#main-tube').offset().top;
	makeVideoCommentLink();
	videos.click(function(e){
	   playVideo($(this));
	   e.preventDefault();
	});
	$('div.yt-play').click(function(e){
	   playVideo($($(this).parents('.yt-container').find('a.yt-video')));
	   e.preventDefault();
	});
   }
   
   function playVideo(object){
	$('body').stop().animate({scrollTop: mainTubeTop-100}, 700, function(){
	});
	meta = object.siblings('div.video-meta');
	videoSrc = "http://www.youtube.com/embed/" + object.attr('id');
	 $('#main-tube').attr('src', videoSrc);
	 $('#video-meta h3').html($('a', meta).clone());
	 $('#video-meta p').not(':first').remove();
	 $('#video-meta p').text($('p', meta).text());
	 $('<a href="" class="add-comment">Add Comment...</a>').attr('href', $('a', meta).attr('href') + '#disqus_thread').appendTo($('#video-meta p').last());
   }
   
   function makeVideoCommentLink(){
	commentHREF = $('.view-id-media h3.block-title a').attr('href');
	$('a.add-comment').attr('href', commentHREF);
   }
   
   var comp = RegExp('^((f|ht)tps?:)?//(?!' + location.host + ')');
   
   if($('div.feature-gallery-item').length){
	$('div.feature-gallery-item').each(function(){
	   if($(this).find('a').length > 1){
		$(this).find('img').clone().appendTo($(this).find('a:first'));
		$(this).find('a:last-child').hide();
	   }else{
		link = $(this).find('a');
		if(comp.test(link.attr('href'))){
		   // a link that contains the current host           
		   link.attr('target','blank');
		}
	   }
	});
   }
   
   if($('section.block-flickr-4').length){
	morePics = '<footer><a href="http://www.flickr.com/photos/attwatermusic/sets/" target="blank" style="margin-top:20px;" class="button right clearfix">View All</a></footer>';
	$(morePics).appendTo($('section.block-flickr-4 div.content'));
   }




$('a.facebook.lightbox-share').click(function(e){
	e.preventDefault();
	//http://www.facebook.com/sharer/sharer.php?u=http://www.youtube.com/watch?feature=player_embedded&v=HU668DPbMQI&t=Countdown%20to%20the%20new%20Attwater%20video
	u=$(this).data('url');
		t=$(this).attr('title');
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436','sharer','toolbar=0,status=0,width=626,height=436');

}
);

});;

