jQuery(document).ready(function($){
	var ua = navigator.userAgent;
	var isMobile = ua.match(/(iPhone|iPod|iPad|Android|Mobile|Blackberry|PalmOS|PalmSource|Symbian|SymbianOS|IEMobile)/i);
	var isiOS = ua.match(/(iPhone|iPod|iPad)/i);

	/* Make navigation bar sticky */
	if (!isMobile) {
	    var navTopOffset = $('.main-nav').offset().top + 7;
	    $(window).scroll(function() {
	        if ($(window).scrollTop() > navTopOffset) {
	            $('.main-nav').addClass('sticky').next().css("margin-top", "58px");
	
		    } else {
	            $('.main-nav').removeClass('sticky').next().css("margin-top", "0");
	        }
	    });
    }
    
    /* Fix video embed and z-index order */
	$("#content iframe").each(function() {
		$(this).attr("src",$(this).attr("src")+"&wmode=transparent");
	});
	$("object").each(function() {
		$(this).append('<param name="wmode" value="transparent" />');
	});

	/* Add callout message to the comment box */
	/** /
	$("#commentform #comment")
		.focus(
			function(e) {
				$(this).callout({
					className: "tooltip message-text",
					orient: "top",
					align: "left",
					width: 400,
	 	            nudgeHorizontal: -25,
		            nudgeVertical: 0,
					arrowHeight: 12,
					arrowInset: 26,
					text: "Hi. I will reply to your comment as soon as I come back from holiday. Thank you for taking the time to comment. Evita :)"
				});
			}
		)
		.blur(
			function(e) {
				$(this).closeCallout();
			}
		);
	/**/
	
	/* Initiate links to overlays that are right after the link and that has href="#overlay" */
	$("a[href='#overlay']").each(function(index) {
		var link = $(this);
		var overlay = link.parent().next();
		link.attr("rel", "#overlay-"+index).addClass("use-overlay");
		overlay.wrap('<div id="overlay-'+index+'" class="overlay"></div>');
	});
	
	/* Initiate normal overlays */
	$("a.use-overlay").overlay({
		effect: 'apple',
		speed: 'fast',
		expose: '#ddd'
	});
	
	/* Initiate overlays on all links that should use ajax */
	$("a.use-ajax-overlay").overlay({ 
	    target: '#ajax-overlay',
		effect: 'apple',
		speed: 'fast',
        onBeforeLoad: function() { 
            var wrap = this.getContent().find(".content-wrapper"); 
			var progress = this.getContent().find(".progress");
			var url = this.getTrigger().attr("href") + '?ajax=1';
			progress.show();
            wrap.empty().load(url, function() {
				progress.hide();
			}); 
        } 
	});
	
});

