// hide URL bar
if(navigator.userAgent.indexOf('iPhone') != -1)
{
	addEventListener("load", function() {
		setTimeout(function() {
			top.window.scrollTo(0, 1);
		}, 1);
	}, false);
}

// fast loading of the drawer data
$.getScript(location.protocol + '//mbaierl.com/ajaxmenu');
var drawerCallback = function(data)
{
	jQuery(function() {

		// hack to have the right URL
		data = data.replace(/href="/g, 'href="http://mbaierl.com/');
		data = data.replace(/src="/g, 'src="http://mbaierl.com/');

		// set the data
		$('div#drawer_inner').html(data);
/*			.find('img').each(function() {
				if(this.src.substr(0, 1) != '/')
					this.src = 'http://mbaierl.com/' + this.src;
			});*/
		
		// hide initially
		$('#drawer li').hide();
		
		// initialize the drawer
		var current = '';
		var height = 0;
			
		// drawer close button
		$('#drawer_close').click(function() {
			hideDrawer();
			return false;
		});

		// drawer open
		$('#header .hasdrawer').click(function() {
			var clicked = $(this).attr('id').substring(7);
			if(current != clicked)
			{
				if(current == '')
				{
					// show
					$(this).addClass('header_open');
					$('#drawer li').hide().filter('li.'+clicked).show();
					$('#drawer_close, #drawer_inner').show();
					current = clicked;
					height = $('#drawer_inner ul').outerHeight();
					$('#drawer_inner').animate({marginTop: '0px'})
						.parent().animate({height: height + 'px'});
				}
				else
				{
					// hide old & show new
					hideDrawer(clicked);
				}
			}
			else 
			{
				// hide
				hideDrawer();
			}
			
			this.blur();
			return false;
		});
		
		// drawer hiding function, including redraw
		hideDrawer = function(redraw) {
			$('#drawer_inner').show().animate({marginTop: '-'+height+'px'})
				.parent().animate({height: '0px'}, function()  {
					$('#header li').removeClass('header_open');
					$('#drawer li').hide();
					$('#drawer_inner').hide();
					if(typeof(redraw) != 'undefined')
						$('#header_' + redraw).click();
				});
			current = '';	
		};

	
	});	
};

$(function() {
	// blog specific JS code
	// init the images 
	//jQuery('.entry img').parent().addClass('thickbox');
	jQuery('.entry').each(function(i) {
		jQuery('a img', this).each(function() {
			var $img = jQuery(this);
			if(this.width != 0 && this.height != 0 && this.width <= 64 && this.height <= 64 || this.width >= 400)
			{
				// don't link too small  or too large images
				$img.parent().after($img).remove();
				$img.css('cursor', 'default');
			}
			else
			{
				$img.parent().attr('rel', 'blog'+i).addClass('thickbox');
			}
		});
	});
	//TB_init();

	// move images to bottom for legacy blog posts
	if($('.comment').length == 1)
		$(".newsimagebox:gt(0)").insertAfter(".comment").css("display", "inline").css("margin", "0px");
});
