$(document).ready(function() {
	var ua = navigator.userAgent;
	var isPhone = new Boolean;
	var isPad = new Boolean;
	if((ua.match(/iPhone/i)) || (ua.match(/iPod/i)) || /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua)) {
	   isPhone = true;
	} else {
		isPhone = false;
	}
	if((ua.match(/iPad/i))) {
	   isPad = true;
	} else {
		isPad = false;
	}
	
	// Object detection for CSS3 properties
	var supports = (function() {
	  	   	var div = document.createElement('div'),
	 	   	vendors = 'Khtml Ms O Moz Webkit'.split(' '),
	 	   	len = vendors.length;
	 
	 	  return function(prop) {
	   	   if ( prop in div.style ) return true;
	 
	    	  prop = prop.replace(/^[a-z]/, function(val) {
	    	     return val.toUpperCase();
	    	  });
	 
	    	  while(len--) {
	       	  if ( vendors[len] + prop in div.style ) {
	           	 // browser supports property. Do what you need.
	           	 // Or use a bang (!) to test if the browser doesn't.
	           	 return true;
	         	} 
	      	}
	      	return false;
	   	};
		})();
		
	// Is QuickTime installed? 
		var quicktimeVersion = 0;
	   	var agent = navigator.userAgent.toLowerCase(); 
	   
	   	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Quicktime plugin in plugin array
	   	if (navigator.plugins != null && navigator.plugins.length > 0) {
	      	for (I=0; I < navigator.plugins.length; I++ ) {
	         	var plugin =navigator.plugins[I];
	         	if (plugin.name.indexOf("QuickTime") > -1) {
	           	 	quicktimeVersion = parseFloat(plugin.name.substring(18));
	         	}
	      	}
	   	}
	   
	   	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	   	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	     	document.write('<scr' + 'ipt language="VBScript"\> \n');
	      	document.write('on error resume next \n');
	      	document.write('dim obQuicktime \n');
	      	document.write('set obQuicktime = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1") \n');
	      	document.write('if IsObject(obQuicktime) then \n');
	      	document.write('   if obQuicktime.IsQuickTimeAvailable(0) then \n');
	      	document.write('      quicktimeVersion = CInt(Hex(obQuicktime.QuickTimeVersion) / 1000000) \n');
	      	document.write('   end if \n');
	      	document.write('end if \n');
	      	document.write('</scr' + 'ipt\> \n');
	  	}
	
	   // Can't detect in all other cases
	   else {
	      quicktimeVersion = quicktimeVersion_DONTKNOW;
	   }
	   
	if (isPhone) {
		$('head').append('<link rel="stylesheet" href="style-phone.css" type="text/css" />');
		
		//alert(getDirPath(window.location.href));
		
		if (getDirPath(window.location.href).indexOf("http://aaroncorsi.com/journal") != -1) {
			$('head').append('<link rel="stylesheet" href="/styles/single-phone.css" type="text/css" />');
		}
		
		//$('head').append('<meta name="apple-mobile-web-app-capable" content="yes" />');
		//$('head').append('<meta name="apple-mobile-web-app-status-bar-style" content="black" />');
		$('head').append('<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable:no;">');
		window.scrollTo(0,1);
		$.getScript('/js/jquery.retina.js',function(){
		});
	}
	if (isPad) {
		$('head').append('<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable:no;">');
		$('head').append('<link rel="stylesheet" href="style-pad.css" type="text/css" />');
		window.scrollTo(0,1);
//		$.getScript('/js/jquery.retina.js',function(){
//		});
		
		if (getDirPath(window.location.href).indexOf("http://aaroncorsi.com/journal") != -1) {
			$('head').append('<link rel="stylesheet" href="/styles/single-pad.css" type="text/css" />');
		}
	}
	if ($('#mainbanner_hype_container')){
		if (isPhone) {
		} else if (isPad) {
		} else if (supports('transform') &&  quicktimeVersion > 5) {
			$('#mainbanner_hype_container').html('<script type="text/javascript" src="MainBanner_Resources/mainbanner_hype_generated_script.js?27832"></script>');
		}
	}
	if ($('#thundroidbanner_hype_container')){
		if (isPhone) {
		} else if (isPad) {
		} else if (quicktimeVersion > 5) {
			$('#thundroidbanner_hype_container').html('<script type="text/javascript" src="ThunDroid_banner_Resources/thundroidbanner_hype_generated_script.js?54185"></script>');
		}
	}
	if ($('#navigation')){
		$.getScript('/js/navigation.js',function(){});
	}
	if ($('.accordion')){
		$.getScript('/js/accordion.js',function(){});
	}
	if ($('.screenshot')){
		$.getScript('/js/screenshotPopup.js',function(){});
	}
	if ($('.persist-area')){
		//$.getScript('/js/sectionHeader.js',function(){});
	}
});

function getDirPath(URL) {
    var result = unescape(URL.substring(0,(URL.lastIndexOf("/")) + 1))
    return result
}

