// Document ready

$(function() {

$('.hover_action').hover(function(ev) {
  $(this).closest('li').find('.firma').css('color', '#cc0000');
});

$('.right_list').mouseout(function(ev) {
  $('.firm').find('a').css('color', '#000000');
});

// Slideshow code

$('#previousnext_slideshow p').after('<div id="pic_nr">').cycle({
	fx:     'scrollLeft',
    speed:   300, 
    timeout: 0,
    next:   '.slideshow_nav_next', 
    prev:   '.slideshow_nav_prev',
    pager:  '#pic_nr'
});

if ($('#previousnext_slideshow').find('img').length == 1) {
  $('#pic_nr').append('<a href="#" class="activeSlide">1</a>')
}  

if ($('.slideshow_nav_prev').length){
  var i = 0;
  $('.previousnext_slideshow').find('img').each(function(index){
    i = i - 1;
  });
  if (i > 0){
    $('.slideshow_nav_prev').show();
  } else {
    $('.slideshow_nav_prev').hide();
  }
}



if ($('.slideshow_nav_next').length){
  var i = 0;
  $('.previousnext_slideshow').find('img').each(function(index){
    i = i + 1;
  });
  if (i <= 1){
    $('.slideshow_nav_next').hide();
  } else {
    $('.slideshow_nav_next').show();
  }
}

if ($('.slideshow_nav_next_pro').length){
   $('.slideshow_nav_next_pro').show();
}

if ($('.slideshow_nav_prev_pro').length){
   $('.slideshow_nav_prev_pro').show();
}

$('.fu').live('click', function(ev){
  alert('BAR');
});

$('.slideshow_nav_next_pro').live('click', function(ev){
  document.location.href = $(this).find('a').attr('href');
  return false;
});    

$('.slideshow_nav_prev_pro').live('click', function(ev){
  document.location.href = $(this).find('a').attr('href');
  return false;
});    
    
    
// End slideshow code


// make sidebar menu out of each h3 element on page
$('.bread').find('h3').each(function(index){

  $val = $(this).html();
  $(this).prepend('<a style="display:block; position:absolute; margin-top:-20px;" name="'+$val+'"></a>');
  $h3 = $(this).find('a').attr('name');
  $html = '<li class="client tags"><a href="#'+$h3+'">'+$h3+'</a></li>';
  $('.jq_right_list').append($html);

});
// end sidebare generator


// ajax_search for frontpage 

if ($('#jq_ajax_search_articles').length){
$.ajax({
  url:('/artikkel/ajax_search'),
  type: 'get',
  data: {
    rows: 5,
    page: 1
  },
  dataType: 'html',
    success: function(response){
      $('#jq_ajax_search_articles').append(response);
    }

});

}
// ajax_search 5 more articles

$('.jq_more_articles').live('click', function(ev){

  var nextpage = $(this).attr('data-id');
  
  $.ajax({
    url:('/artikkel/ajax_search'),
    data: {
    rows: 5,
    page: nextpage
    },
    dataType: 'html',
      success: function(response){
        responseresult = '<div class="showme" style="display:none;">' + response + '</div>';
        $('#jq_ajax_search_articles').append(responseresult);
        $('.showme').slideDown('slow');
        $('html, body').animate({scrollTop: 6000000}, 800);
        FB.init({appId: null, status: true, cookie: true,xfbml: true});

        
      }
  });
  
  $(this).fadeOut();
return false;
});


// End document ready
});
