(function($) {
$(function(){
 $('img[name="photo_j"]:not("#galleryImage")').css('height','100px');
 $('.largenews p > img').css('width', '200px');
 $('.block').css('width','145px');
 
 var result_count = '';	
 
 if( $('table#search_results').length == 1 ) {

  $.cookie('result_count_cookie',null);
  
  result_count = $('table#search_results > tbody > tr').length;
  
  if( $('.message-col').length > 0 ) {
    result_count = 0;
  }
  
  $('#new_posts').text(result_count).parent('a').attr('title','Nye innlegg ( '+result_count+' )').click(function() {
    $.cookie('result_count',null);
  });
  
  $.cookie('result_count_cookie',result_count, { expires: 1, path: '/' });
  
 } else if( $.cookie('result_count_cookie') ) {

  result_count = $.cookie('result_count_cookie');
  
  if( $('.message-col').length > 0 ) { 
    result_count = 0;
	$.cookie('result_count_cookie',null);
  }
  $('#new_posts').text(result_count).parent('a').attr('title','Nye innlegg ( '+result_count+' )');
 }
 
 $('div.postbody a[href*=".jpg"], div.postbody a[href*=".png"], div.postbody a[href*=".gif"], div.postbody a[href*=".jpeg"]').each(function(i,item) {
  if( $(this).closest('div.quote').length == 0 ) {
  	var src = $(this).attr('href'),
	w =  ( $(this).closest('td').width() ) - 20;
  	$('<img src='+src+'  />').css({
   		'width': w+'px',
  	}).appendTo(this);
  }
 });

 $('div.quote').find('img').each(function() {
  $('<a href="'+$(this).attr('src')+'">'+$(this).attr('src')+'</a>').after(this);
  $(this).remove();
 });

 $('a[href*="youtube.com/watch"]').each(function(){
  var video = $(this).attr('href');
  video = video.split('?v=')[1]; 
  var player = []; 
  player.push('<object width="560" height="340">');
  player.push('<param name="movie" value="http://www.youtube.com/v/'+ video +'&hl=en_US&fs=1&"></param>'); 
  player.push('<param name="allowFullScreen" value="true"></param>');
  player.push('<param name="allowscriptaccess" value="always"></param>');
  player.push('<embed src="http://www.youtube.com/v/'+ video +'&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed>');
  player.push('</object>');
  $(this).after(player.join(''));
 });
});		
})(jQuery);
