$(document).ready(function ()
{
	
var resizeTime = 5;     // total duration of the resize effect, 0 is instant
var resizeDelay = 5;    // time to wait before checking the window size again
                          // the shorter the time, the more reactive it will be.
                          // short or 0 times could cause problems with old browsers.

var mobile = 767;
var width_medium = 991;
var width_high = 1199;
                          
$('#phd_frontpage_mapster').mapster({
    mapKey: 'state',
    fillOpacity: .3,
    fillColor: 'ffffff',
    clickNavigate: true
});

// Resize the map to fit within the boundaries provided

function resize(maxWidth,maxHeight) {
if($(window).width() <= mobile){
   	 var image =  $('#phd_frontpage_mapster'),
   	    imgWidth = image.width(),
   	    imgHeight = image.height(),
   	    newWidth=0,
   	    newHeight=0,
   	    winwidth = $(window).width();



    if (imgWidth/maxWidth>imgHeight/maxHeight) {    
        newWidth = (maxWidth - 15);
    } else {
        newHeight = maxHeight;
    }
 
    image.mapster('resize',newWidth,newHeight,resizeTime);   
}


if($(window).width() > mobile && $(window).width() <= width_medium) {
   	 var image =  $('#phd_frontpage_mapster'),
   	    imgWidth = image.width(),
   	    imgHeight = image.height(),

 
        newWidth = 500;
        newHeight = 294;
 
			


    image.mapster('resize',newWidth,newHeight,resizeTime);   
}

if($(window).width() > width_medium && $(window).width() <= width_high){
   	 var image =  $('#phd_frontpage_mapster'),
   	    imgWidth = image.width(),
   	    imgHeight = image.height(),
  
        newWidth = 710;
        newHeight = 418;
 
			


    image.mapster('resize',newWidth,newHeight,resizeTime);   
}

if($(window).width() > width_high){
   	 var image =  $('#phd_frontpage_mapster'),
   	    imgWidth = image.width(),
   	    imgHeight = image.height(),
   	    newHeight=0,

  
        newWidth = 900;
        newHeight = 530;


    image.mapster('resize',newWidth,newHeight,resizeTime);   
}

}


// Track window resizing events, but only actually call the map resize when the
// window isn't being resized any more

function onWindowResize() {
    
    var curWidth = $(window).width(),
        curHeight = $(window).height(),
        checking=false;
    if (checking) {
        return;
            }
    checking = true;
    window.setTimeout(function() {
        var newWidth = $(window).width(),
           newHeight = $(window).height();
        if (newWidth === curWidth &&
            newHeight === curHeight) {
            resize(newWidth,newHeight); 
        }
        checking=false;
    },resizeDelay );
}

$(window).bind('resize',onWindowResize);

});