// Rewritten version
// By @mathias, @cheeaun and @jdalton
//this function fixes the weird iOS behavior when switching orientations
(function(doc) {

	var addEvent = 'addEventListener',
	    type = 'gesturestart',
	    qsa = 'querySelectorAll',
	    scales = [1, 1],
	    meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];

	function fix() {
		meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
		doc.removeEventListener(type, fix, true);
	}

	if ((meta = meta[meta.length - 1]) && addEvent in doc) {
		fix();
		scales = [.25, 1.6];
		doc[addEvent](type, fix, true);
	}

}(document));



//This function makes embedded videos responsive in size. See: http://css-tricks.com/NetMag/FluidWidthVideo/demo.php

$(document).ready(function() {

	$(function() {
	    var $allVideos = $("iframe[src^='http://player.vimeo.com'], iframe[src^='http://www.youtube.com'], object, embed"),
	    //this element must change based on which containing element is fluid.
	 	$fluidEl = $(".hentry");

		$allVideos.each(function() {
		  $(this)
		    // jQuery .data does not work on object/embed elements
		    .attr('data-aspectRatio', this.height / this.width)
		    .removeAttr('height')
		    .removeAttr('width');
		});

		$(window).resize(function() {
		  
			$allVideos.each(function() {
				//I moved this line to within the function so that each video would figure out it's fluid context
				var newWidth = $(this).parents($fluidEl).width();
			    var $el = $(this);
			    $el
			        .width(newWidth)
			        .height(newWidth * $el.attr('data-aspectRatio'));
		  });

		}).resize();

	});
 
});


function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
window.onload = externalLinks;



