<?php
function uplift_get_pixelratio() {
    if ( isset($_COOKIE["uplift_pixel_ratio"]) ) {
        $pixel_ratio = $_COOKIE["uplift_pixel_ratio"];
        
        $debug_mode = false;
        if ( isset($_GET['uplift_debug']) ) {
        	$debug_mode = $_GET['uplift_debug'];
        }
        
        if ( $debug_mode ) {
        	echo 'IMAGE DEBUG -- PIXEL RATIO (' . $pixel_ratio . ') '."\n";
        }
        
        if ( $pixel_ratio >= 2 ) {
           // echo "Is HiRes Device";

			/**
			* Include AQ Resizer
			*/
			require( get_template_directory() . '/includes/plugins/aq_resizer-2x.php' );

		}else{
            //echo "Is NormalRes Device";

			/**
			* Include AQ Resizer
			*/
			require( get_template_directory() . '/includes/plugins/aq_resizer-1x.php' );
        }
    } else {
		require( get_template_directory() . '/includes/plugins/aq_resizer-1x.php' );
?>
    <script>function uplift_writeCookie(){the_cookie=document.cookie,the_cookie&&window.devicePixelRatio>=2&&(the_cookie="uplift_pixel_ratio="+window.devicePixelRatio+";"+the_cookie,document.cookie=the_cookie)}uplift_writeCookie();</script>
<?php
    }//isset($_COOKIE["pixel_ratio"])
}//get_pixelratio
add_action( 'wp_enqueue_scripts', 'uplift_get_pixelratio' );
?>
