jQuery.noConflict();

var hold = false;
var opened = false;
var mapLoaded = false;
var normalMapUrl = '/TestingGoogleMaps/TestingGoogleMaps2.php?cId=';
var streetViewLink = '';
var custId = 0;

jQuery(function()

{    
	jQuery('#mapImageLoader').hide();
    var showMap = jQuery('#map_container');
    
    showMap.attr('style', showMap.attr('style') + '; height: ' + showMap.height() + 'px').hide();    

    jQuery('#showMap').click(function(event)
    {
    	if(!opened){
    		showMap.slideDown();    		
    		opened = true;
    		if(!mapLoaded){
    			ShowLoading();
    			var mapSrc = jQuery('#mapCustHidden')[0].value;
    			var mapSrcUrl = jQuery('#mapSrcHidden')[0].value;
    			custId = mapSrc;
    			jQuery('#iframe_mapcontainer')[0].src = normalMapUrl + mapSrc+'&big=0';
	    		/*
	    		var hrefParts = mapSrc.split("?", 2);			
				var qs = hrefParts[1];
				var full = "/TestingGoogleMaps/TestingStreetView.php?"+qs;			
				document.getElementById('map_street_container').innerHTML='<iframe id="iframe_popup_mapcontainer" height="350" frameborder="0" width="550" scrolling="no"  marginwidth="0" marginheight="0" src="'+full+'" ></iframe>';
				*/
	    		streetViewLink = 'http://maps.google.com.au/maps/sv?cbp='+gup( 'cbp' , mapSrcUrl)+'&amp;cbll='+gup( 'cbll' , mapSrcUrl)+'&amp;panoid='+gup( 'panoid' , mapSrcUrl)+'&amp;v=1&amp;hl=en&amp;gl=au';
	    		
	    		if(browserFullName == 'IE 7' || browserFullName == 'IE 6'){
	    			/*extraMsgForIE = '<small>Microsoft Internet Explorer may not show the exact location. <a href="'+mapSrcUrl+'" target="_blank">Click Here</a> for exact location</small>';
	    			var hrefParts = mapSrcUrl.split("?", 2);			
					var qs = hrefParts[1];*/
	    			
	    			streetViewLink = '/TestingGoogleMaps/TestingStreetView.php?cId=' + mapSrc;
	    			
	    		}
	    		
	    		/*var extraMsgForIE='<div style="float:right;font-size:12px;" ><a id="theMapLink" name="toggleStreetLink" href="javascript:;" onclick="toggleStreet(this)">Map</a> | <a id="theStreetViewLink" style="font-weight:bold;" name="toggleStreetLink" href="javascript:;" onclick="toggleStreet(this)">Street View</a></div>';
	    		 * */
	    		
				document.getElementById('map_street_container').innerHTML='<iframe id="theStreetViewIframe" width="550" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+streetViewLink+'"></iframe>';
				
	    		setTimeout('RemoveLoading()', 5000);
	    		mapLoaded = true;
	    		
    		}    		
    	}else{
    		jQuery('#map_container').slideUp('slow');
    		opened = false;
    	}
    });
    
    jQuery('#showMap').hover(function(event)
    {
    	jQuery('#showMap').css('text-decoration','underline');
    	jQuery('#showMap').css('cursor','pointer');    	
    },
    function(event)
    {
    	jQuery('#showMap').css('text-decoration','none');
    	jQuery('#showMap').css('cursor','default');
    });
    
    jQuery('#btn_street_view').hover(function(event)
    {
    	hold = true;
    },
    function(event)
    {
    	hold = false;
    });
    
    jQuery('#iframe_mapcontainer').hover(function(event)
    {
    	hold = true;
    },
    function(event)
    {
    	hold = false;
    });
    
    showMap.mouseout(function(event)
    {
    	setTimeout('hideMapContainer()',1500);
    });    

});
function toggleStreet(theLink){
	var theUrl = streetViewLink;
	if(theLink.id == 'theMapLink'){theUrl = normalMapUrl + custId + '&big=1';}
	
	jQuery('[name=toggleStreetLink]').css('font-weight','normal');
	jQuery(theLink).css('font-weight','bold');
	document.getElementById('md_popup_content').innerHTML='<iframe id="theStreetViewIframe" width="550" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'+theUrl+'"></iframe>';
}

function hideMapContainer()
{
	if(!hold){
		jQuery('#map_container').slideUp('slow');
		opened = false;
	}
}

function InitMap(){
	var showMap = jQuery('#map_container');
	showMap.attr('style', showMap.attr('style') + '; height: ' + showMap.height() + 'px').hide();
	
}
function RemoveLoading()
{
	jQuery('#iframe_mapcontainer').css('filter',''); 
	jQuery('#iframe_mapcontainer').css('-moz-opacity','');
	jQuery('#iframe_mapcontainer').css('opacity','');
	
	jQuery('#mapImageLoader').hide();	
}

function ShowLoading()
{
	jQuery('#iframe_mapcontainer').css('filter','Alpha(Opacity=40)'); 
	jQuery('#iframe_mapcontainer').css('-moz-opacity','0.4');
	jQuery('#iframe_mapcontainer').css('opacity','0.4');
	
	jQuery('#mapImageLoader').show();
}
/*jQuery('#btn_street_view').hide();jQuery('#btn_street_view').show();*/

function gup( name , url)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( url );
  if( results == null )
    return "";
  else
    return results[1];
}