

// ***********************************************************

(function() {

	var orientationTimer;
	var $body;
	var currentWidth=0;
	var currentHeight=0;

	console.log("initial setup - dom:loaded");
	
	document.addEventListener('dom:loaded', function(event) {

			$body = document.getElementsByTagName('body')[0];

			if (typeof window.onorientationchange == "object")
			{
				window.onorientationchange = orientChangeHandler;
				setTimeout(orientChangeHandler, 0);
			} else {
				setTimeout(checkOrientation, 0);
				orientationTimer = setInterval(checkOrientation, 300);
			}
		}, true);


	function orientChangeHandler()
	{
		var orient = window.orientation;
		switch(orient)
		{
			case 0:
				setOrientation('portrait');
				break;	
			case 90:
			case -90: 
				setOrientation('landscape');
				break;
		}
	}

	function setOrientation(orient)
	{
		$body.removeClass( orient=='portrait'?'landscape':'portrait' );
		$body.addClass( orient );
	}

	function checkOrientation()
	{
		if ((window.innerWidth != currentWidth) || (window.innerHeight != currentHeight))
		{	
			currentWidth = window.innerWidth;
			currentHeight = window.innerHeight;
			var orient = (currentWidth < currentHeight) ? 'portrait' : 'landscape';
			setOrientation(orient);
		}
	}

	var list = $('a[target="_blank"]');
	console.log("List: "+list.length);

/*
	$('a[target="_blank"]').click(function() {
		if (confirm('This link opens in a new window.')) {
			return true;
		} else {
			$(this).removeClass('active');
			return false;
		}
	});
*/
	document.onscroll = function() {
		if ( window.pageYOffset < 1 ) window.scrollTo(0,1);
		console.log("window.pageYOffset: "+window.pageYOffset);
	};
})();


