/* Author: 

*/
$('document').ready(function () {
	
	// Summary
	$('div.summary').summary();

	// Target blank
	$("a[href^='http:']").not("[href*='" + window.location.host + "']").attr('target','_blank');
	
	// Fancybox
	$("a[href*='.jpg']").fancybox({
		titlePosition: 'inside'
	});
	
  $('#news-page .read-more').each(function () {
  	$(this).prev().find('p').append($(this));
  });

/*
	var embedly_maxWidth = 740;
	var embedly_urlRe = /(http:\/\/(www\.)?vimeo.com\/.*)|(http:\/\/(www\.)?youtube.com\/.*)/i 
	var embedly_method = 'replace';
	var embedly_wrapElement = 'div';
	var embedly_className = 'embed';
	var embedly_addImageStyles = true;
	var embedly_cssSelector = 'a';
*/
});

$(window).load(function () {

	// Cycle
	$('#slideshow').show();
	$("#slideshow").cycle({
		fx: 'none',
		timeout: 0,
		pager: '#slideshow-nav ul', 
		next: '#slideshow-next',
		prev: '#slideshow-prev',
    pagerAnchorBuilder: function(idx, slide) { 
      // return selector string for existing anchor 
      return '#slideshow-nav ul li:eq(' + idx + ') a'; 
    },
    after: function (current, next) {
    	if ($(next).find('img').length > 0)
	    	$("#slideshow").height($(next).find('img').height()+20);
	    else
		    $("#slideshow").height(500);
    }     
	});
	
	// Embedly
	$('.media a.video, figure.video a').embedly({
		maxWidth: 740,
		maxHeight: 500
	});

	// Embedy Thumb
  $(".video-thumb").each(function() {
	  $(this).embedly({}, function(oembed, dict){
	    if ( oembed == null)
	      return;
	
	    var output = "<a class='embedly' href='"+dict["node"].attr('rel')+"'><img src='"+oembed.thumbnail_url+"' /></a>";
	    dict["node"].parent().html( output );
	  });
  
  });
  
	// IE
	$('.ie #contact-page article div:nth-child(2)').css('width', '100%')
});
