//********************************************************
// add jquery script
//********************************************************
var headID = document.getElementsByTagName("head")[0]; 
var mapScript = document.getElementById("jsMaxMap");  
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = mapScript.src.substring(0, mapScript.src.lastIndexOf("/")) + "/jquery1.3.2.min.js"; //"http://vanmapb1.vancouver.ca/hostcitymaps_wa/scripts/jquery1.3.2.min.js";
headID.appendChild(newScript);
//end of add jquery script

//**********************************************************************
// GIS Class
//   methods:
//      expandmapFrame(on) -- expand or collapse map frame
//      resizeMap          -- map resize
//      checkForMessages   -- detect command from map frame
//  properties:
//      full               -- map is in full size
//      mapHolder          -- map width and height
//      mapLoaded          -- map loaded 
var GIS={};
//***********************************************************************
// expandmapFrame
// parameters
//      on  -- either "#0" (to expand map) or "#1" ( to collapse map)
//*********************************************************************** 
GIS.expandmapFrame=function(on){
    var mapContainer = document.getElementById('mapframe') || null;
    var browseWidth;
    var browseHeight;
    if(mapContainer != null){
        if(on=="#0") 
        {
            //**********************************************
            //show map in full screen
            //custom code goes here to full screen map
	        mapContainer.style.position="absolute";
	        mapContainer.style.top="0px";
	        mapContainer.style.left="0px";
    	    $('body').css('overflow', 'hidden');
			//for roadahead
			//alert($('iframe[id$=projectSearch]').length);
			$('iframe[id$=projectSearch],.projectSearch,.span-2').hide();		
			$('.span-10.footer').hide();
			//end for roadahead
            browseWidth=$(window).width(); 
            browseHeight=$(window).height(); 

            mapContainer.style.height = browseHeight + "px";
            mapContainer.style.width = browseWidth + "px";
            //end custom code to expand map
            //***********************************************
        }
        else{
            //**********************************************
            //show map in default size
            //custom code goes here to set map size to default
            if(GIS.mapLoaded){//alert(GIS.mapLoaded);
                //window.scrollbars.visible=true;
                mapContainer.style.height = GIS.mapHolder.height + "px";
	            mapContainer.style.width = GIS.mapHolder.width +  "px";

                GIS.mapPosition = $(window).scrollTop(); 
	            mapContainer.style.position="relative";
	            $('body').css('overflow', 'auto');
	            mapContainer.zIndex = 99;
				
				//for roadahead
	            //$('#roadwork,iframe[id$=projectSearch],.projectSearch').show();
				$('iframe[id$=projectSearch],projectSearch,.span-2').show();
				$('.span-10.footer').show();
				//end for roadahead
				
	            window.scroll(0, GIS.mapPosition);
	        }
	        //end custom code to collapse map 
	        //**********************************************
	    }
	}
}

//******************************************************************
// resizeMap
//    when map resize
//******************************************************************
GIS.resizeMap=function()
{
    var mapContainer = document.getElementById('mapframe')||null;
	if(mapContainer==null)return;
	
    //if mapContainer is full screen then change mapContainer size by window size
    //otherwise no change
    if(mapContainer.style.position == "absolute")
    {
        var browseWidth;
        var browseHeight;

        browseWidth=$(window).width(); 
        browseHeight=$(window).height(); 

        //**********************************************
        //show map in full screen
        //custom code goes here to full screen map
        mapContainer.style.height = browseHeight + "px";
        mapContainer.style.width = browseWidth + "px";
        //end of custom code
        //**********************************************
      
    }
    else{
        //mapContainer.style.height = GIS.mapHolder.height + "px";
        //mapContainer.style.width = GIS.mapHolder.width + "px";
    }
}
//*******************************************************
// checkForMessages
//   check mapFrame has sent message(full screen, back)
//*******************************************************
GIS.checkForMessages=function(){
    if(GIS.full != null){
        if(location.hash != GIS.full && (location.hash == "#0" || location.hash == "#1")){
            
            //alert(location.hash + "     " + GIS.full);
            GIS.full = location.hash;
            GIS.expandmapFrame(GIS.full);
        }
        else if(location.hash == "#-1")
        {
            //GIS.expandmapFrame();
        }
    }
    else{ 
        GIS.full = "#1";
    }
}


//*******************************************************
// window onload
//  
//*******************************************************
window.onload=function(){
    //to detect hash changes
    setInterval(GIS.checkForMessages, 200);
    //map frame
    var mapContainer = document.getElementById('mapframe')||null;
    if(mapContainer==null)return;
    //define mapframe properties
    GIS.full=null;
    GIS.mapHolder = {width: mapContainer.width, height:mapContainer.height};
	
    GIS.mapLoaded = true;

    if(window.location.hash || null == null)
        window.location.hash = "#1";
    window.onresize = GIS.resizeMap;
	
	var ctrl=false;
	
	$(document).keydown(function(e){     
        // disable ctrl + +/- 
        if(ctrl && (e.keyCode == 107 || e.keyCode == 109)) { 
                //alert('Zoom is disabled!'); 
                return false; 
        } 
        if(e.keyCode == 17) { 
                ctrl = true; 
 
                // disable ctrl + scroll 
                $(document).bind('mousewheel', function() { 
                        if(ctrl) { 
                                //alert('Zoom is disabled!'); 
                                return false; 
                        }                                                                
                }); 
        } 
    }) 
 
    $(document).keyup(function(e) { 
        if(e.keyCode == 17) { 
                ctrl = false; 
                $(document).unbind('mousewheel'); 
        }                                   
    });        
}







