$(document).ready(function() {

//SLIDESHOW's
  if($('#slideshow').children().size() > 1) {
    $('#slideshow').before('<a id="prev" href="#">prev</a><a id="next" href="#">next</a>');
  }
  if ($.browser.webkit) {
    $('#slideshow, .showcase-gallery').cycle({ 
        fx: 'fade', 
        timeout:  10000, 
        speed:    300,
        pause: 1,
        prev:    '#prev', 
        next:    '#next',
        cssBefore: { width: '100% !important', height: '100% !important'},
        cssAfter:{ width: '100% !important', height: '100% !important'}
    }); 	
  }
  else {
    $('#slideshow, .showcase-gallery').cycle({ 
        fx: 'scrollHorz', 
        timeout:  10000, 
        speed:    300, 
        pause: 1,
        prev:    '#prev', 
        next:    '#next'
    }); 
  }
  
  $('#slideshow').css("width","100%").css("height","100%");
  $(window).resize(function() {
    $('#slideshow').css("width","100%");
    //$('#slideshow div.testarnagot').css("width","100%");
    //document.location = document.location
  });

// Märkvärdig splash push
  $(".splashPush_mmm").show();
  if($('#slideshow').children('div').is('.meramarkvardig')){
    $(".splashPush_mmm").delay(2000).fadeOut(500);
  }else{
    $(".splashPush_mmm").hide();
  }


//CASES
  $(".case_img").hover(function(){
    $(this).prepend('<span class="focus_text">Läs mer om projektet</span><span class="focus_overlay"></span>')
  }, function(){
    $(this).find("span").remove();
  });
  $(".preview").fancybox({
    'transitionIn' : 'fade',
    'transitionOut' : 'fade',
    'speedIn' : 550, 
    'speedOut' : 550, 
    'overlayShow' : true,
    'titleShow' : false,
    'autoScale' : 'true',
    'centerOnScroll' : 'true'
  });
  $(".map").fancybox({
    'transitionIn' : 'fade',
    'transitionOut' : 'fade',
    'overlayShow' : true,
    'titleShow' : false,
    'padding': 0,
    'centerOnScroll' : 'true',
    'type' : 'iframe',
    'width' : '90%',
    'height' : '90%',
    'href' : 'http://maps.google.com/maps?q=meramedia&amp;hl=en&amp;cd=1&amp;ei=4cg1TNHQDtKIOMLHvYIB&amp;sig2=9trqOoRhLn1gvU7EF8mk-w&amp;sll=65.584545,22.146463&amp;sspn=0.000898,0.004128&amp;ie=UTF8&amp;view=map&amp;cid=8921343857805504608&amp;ved=0CCYQpQY&amp;hq=meramedia&amp;hnear=&amp;ll=65.584291,22.146811&amp;spn=0.006209,0.018239&amp;z=15&amp;iwloc=A&amp;output=embed'
  });

  if(typeof(twitterUsername) != 'undefined' && twitterUsername.length > 0 && tweetCount > 0) {
    //TWEETS
    $(".tweet").tweet({
      username: twitterUsername,
      join_text: false,
      avatar_size: 0,
      count: tweetCount,
      auto_join_text_default: "we said,",
      auto_join_text_ed: "we",
      auto_join_text_ing: "we were",
      auto_join_text_reply: "we replied to",
      auto_join_text_url: "we were checking out",
      loading_text: "Just a sec, gathering tweets..."
    });
  }


});

/*calculate the width of the inner gallery images*/
$(window).load(function(){
  var galleryWidth = $('.showcase-gallery img').width();
  if (galleryWidth < 622){    
    $('.showcase-gallery img').addClass('nom');
  }
});


if ($('#sidebar_test').length > 0) {
  var offset = $("#sidebar_test").offset();
  var topPadding = 15;
  $(window).scroll(function() {
    if ($(window).scrollTop() > offset.top) {
      $("#sidebar_test").stop().animate({
        marginTop: $(window).scrollTop() - offset.top + topPadding
      });
    } else {
      $("#sidebar_test").stop().animate({
        marginTop: 0
      });
    };
  });

$('.addthis_button_facebook_like').attr('fb:like:layout', 'button_count');
}

/*transform text*/
Cufon.replace('.rubrik','h2');


