var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
	if (IE) {
	 	tempX = event.clientX + (document.documentElement||document.body).scrollLeft;
	  	tempY = event.clientY + (document.documentElement||document.body).scrollTop;
	} else {
	  tempX = e.pageX;
	  tempY = e.pageY;
	}
	if (tempX < 0){
		tempX = 0;
	}
	if (tempY < 0){
		tempY = 0;
	}
	return true;
}

function getWindowHeight() {
	if( typeof( window.innerWidth ) == 'number' ) {
	   	return window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		return document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		return document.body.clientHeight;
	} else {
		return 0;
	}
}

function getWindowWidth() {
   var myWidth = 0;
   if( typeof( window.innerWidth ) == 'number' ) {
       myWidth = window.innerWidth;
   }
   else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       myWidth = document.documentElement.clientWidth;
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
       myWidth = document.body.clientWidth; }
   return myWidth;
}

function getTopFromHeight(H)
{
    var result = getWindowHeight() / 2;
    result = result - (H/2);
    result = parseInt(result);
    return result;
}

function getTopFromWidth(W)
{
    var result = getWindowWidth() / 2;
    result = result - (W/2);
    result = parseInt(result);
    return result;
}

$(function($){

    function displayMaps()
    {
        jQuery('#bgTransparent').css('display', 'block');
        jQuery('#bgContent').css('display', 'block');

        var window_w = getWindowWidth();
        var left = getTopFromWidth(window_w-100);
        var window_h = getWindowHeight();
        var top = getTopFromHeight(window_h-100);



        

        $.ajax({
          url: '/attractions/mapsframe',
          success: function(data)
                   {
                        jQuery('#bgContent').html(data);
                        jQuery('#maps_content').css('width', window_w-100 + 'px');
                        jQuery('#maps_content').css('height', window_h-100 + 'px');    
                        jQuery('#maps_content').css('margin-top', top + 'px');
                        jQuery('#maps_content').css('margin-left', left + 'px');
                        jQuery('#maps_content iframe').css('width', window_w-100 + 'px');
                        jQuery('#maps_content iframe').css('height', window_h-100 + 'px');
                        var url = '/attractions/maps?w=' + (window_w-102) + '&h=' + (window_h-102);
                        jQuery('#maps_content iframe').attr('src', url);

                   }
        });

        
        //jQuery('#maps_content').css('height', window_h-100 + 'px');

        //alert(maps_content);
        //jQuery('#bgTransparent').append(maps_content);

    }

    function hideMaps()
    {
        jQuery('#bgTransparent').css('display', 'none');
        jQuery('#bgContent').css('display', 'none');
    }

    jQuery('#attractionMaps').click(function ()
    {
        displayMaps();
        return false;
    });

    jQuery('#bgTransparent').click(function ()
    {
        hideMaps();
    });



})

