(function($) {
	"use strict";

    // For use within normal web clients 
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    
    // For use within iPad developer UIWebView
    // Thanks to Andrew Hedges!
    var ua = navigator.userAgent;
    var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
    _log('iPad or iPhone?: ' + isiPad);

	/* check for support before we move ahead */
	if (typeof history.pushState !== "undefined" && isiPad == true) {
    
    	$('nav').find('li').find('a').live('mouseover', function(event){
            var data = event.state;
            console.log('ref:' + $(this).parent('li').attr('refresh'));
    		if($(this).parent('li').attr('refresh') == 'true')
            {
        		var href = $(this).attr('href');
        		var href_split = href.split('?p=')[1];
                var pre_href = site_url();
                
        		$('#overal_content_container').html('<img src="images/loading.gif" alt="loading content">').load(pre_href + href_split + '.php', function(){
        			$(this).find('#overal_content_container').unwrap();
        			$('#overal_content_container').hide().fadeIn(500)
        			
        			// get the new page title
        			var title = $('nav#main_nav ul li.active').text();
        			
        			// update the page <title>
        			$('head').find('title').text(title);
        		
        			// do a history push to change the URL
        			history.pushState({page: (window.history.length+1)}, title, href);
        			   			
        		});
    
        		return false;
    		}
            else
                return false;
    	});

	}	
}(jQuery));
