
//MAP//////////////

var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var markersArray = [];
  var latlng; 
  var map;
  var trafficLayer;
  
  function initialize(page) {
  
    latlng = new google.maps.LatLng(35.0286190,-80.8500950);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	directionsDisplay = new google.maps.DirectionsRenderer();
	directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
	
	
	

	var contentString = '<h3>Ballantyne Self Storage - Charlotte</h3>';
	contentString += '<img src="/images/gallery/69/pic1.jpg" alt="Ballantyne Self Storage - Charlotte NC 28277" width="100" border="1" style="float:left; margin-right: 13px;"/>';
	contentString += '16155 Lancaster HWY<br/>Charlotte NC. 28277<br/>';
	contentString += '(704) 323-5367<br/>';
	contentString += '<a href="/Charlotte-North-Carolina/28277/69">More Information</a>';
	

    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });
 
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: 'Ballantyne Self Storage',
		icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=B%7CB72F43%7Cffffff'
    });
    if (page != 'facility') { google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    }); }
	markersArray.push(marker);
	
	
	 // We get the map's default panorama and set up some defaults.
    // Note that we don't yet set it visible.
    panorama = map.getStreetView();
    panorama.setPosition(new google.maps.LatLng(35.028485279149166, -80.8515214920044));
    panorama.setPov({
      heading: 81.55235360097245,
      zoom:1,
      pitch:0.19708846424715762}
    );
	
   trafficLayer = new google.maps.TrafficLayer();
  
	
	/*google.maps.event.addListener(panorama, 'pov_changed', function() {
	document.getElementById("directionsPanel").innerHTML = panorama.getPov().heading +' '+ panorama.getPov().pitch
	
    }); */
	
	

// Create the DIV to hold the control and
  // call the HomeControl() constructor passing
  // in this DIV.
  var streetControlDiv = document.createElement('DIV');
  var streetControl = new StreetControl(streetControlDiv, map);

  streetControlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(streetControlDiv);
		if (page != 'facility') {
	// Create the DIV to hold the control and
  // call the HomeControl() constructor passing
  // in this DIV.
  var trafficControlDiv = document.createElement('DIV');
  var trafficControl = new TrafficControl(trafficControlDiv, map);

  trafficControlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(trafficControlDiv);
	
  
	
	// Create the DIV to hold the control and
  // call the HomeControl() constructor passing
  // in this DIV.
  var homeControlDiv = document.createElement('DIV');
  var homeControl = new HomeControl(homeControlDiv, map);

  homeControlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
	
	}

  
  
  }
  var traffic_state = 0;
  
  function toggleTraffic() {
	if (traffic_state == 0) {
		trafficLayer.setMap(map);
		traffic_state = 1;
	} else {
		trafficLayer.setMap(null);
		traffic_state = 0;
	}
  }
  
   function toggleStreetView() {
    var toggle = panorama.getVisible();
    if (toggle == false) {
      panorama.setVisible(true);
    } else {
      panorama.setVisible(false);
    }
  }
  
  function calcRoute() {
    var end = '16155 Lancaster HWY Charlotte, NC';
    var start = document.getElementById("end").value;
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
	    document.getElementById("directionsPanel").innerHTML = '';
        directionsDisplay.setDirections(response);
		 directionsDisplay.setMap(map);
		 if (markersArray) {
			for(i in markersArray) {
				markersArray[i].setMap(null);
			}
		 }
      }
    });
  return false;
  }
  
  function clearDirections() { 
	directionsDisplay.setMap(null);
	
	if (markersArray) {
		for(i in markersArray) {
			markersArray[i].setMap(map);
		}
	}
	document.getElementById("directionsPanel").innerHTML = '';
	document.getElementById("directionsPanel").innerHTML = '<table>' + 
	
		'<tr><td><b><span class="directions">From the North:</span></b> I-485 to Johnston Rd exit. Follow Johnston Rd. south for 4 miles. Facility is on left in Hunters Crossing shopping plaza. We across the parking lot from Dunkin Donuts.</td></tr>' + 
		'<tr><td><b><span class="directions">From the South:</span></b> From Lancaster, SC:  Take Lancaster HWY(521) North towards Ballantyne. Turn right at the intersection of Old Lancaster Highway and Lancaster Highway(Johnston Rd) into Hunters Crossing Shopping Plaza. We are across the parking lot from Dunkin Donuts.</td></tr>' + 
		'<tr><td><b><span class="directions">From the East:</span></b> From Pineville, NC: take Old Lancaster HWY towards Ballantyne until the roads interesects with Lancaster Highway(Old Lancaster ends). Go straight thru the intersection into Hunters Crossing shopping plaza. We are across the parking lot from Dunkin Donuts.</td></tr>' + 
		'<tr><td><b><span class="directions">From the West:</span></b> From Blakeny/Marvin/Waxhaw: Take Rea Rd to Ardrey Kell Rd. Go west(right onto Ardrey Kell if coming from Charlotte direction, left onto Ardrey Kell if coming from Blakeny direction) on Ardrey Kell until you reach the intersection of Ardrey Kell and Lancaster Hwy. Take right onto Lancaster Hwy. Take a right at the first light into Hunters Crossing shopping plaze. We are across the parking lot from Dunkin Donuts.</td></tr>' + 
		
	'</table>';
	
	

  }
  
function HomeControl(controlDiv, map) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';

  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Reset Map';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = 'Reset';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to

  google.maps.event.addDomListener(controlUI, 'click', function() { map.setCenter(latlng); map.setZoom(15) } );
}
  
  function StreetControl(controlDiv, map) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';

  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Street View';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = 'Street View';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to

  google.maps.event.addDomListener(controlUI, 'click', function() { toggleStreetView(); } );
}
  
function TrafficControl(controlDiv, map) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';

  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Traffic';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = 'Traffic';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to

  google.maps.event.addDomListener(controlUI, 'click', function() { toggleTraffic() } );
}

function myclick(i) {
	
		google.maps.event.trigger(markersArray[i], "click");
	
}






// SLIDESHOW ////////////////

var slideshow2_noFading = false;
var slideshow2_timeBetweenSlides = 2000;	// Amount of time between each image(1000 = 1 second)
var slideshow2_fadingSpeed = 10;	// Speed of fading	(Lower value = faster)


var slideshow2_stats = new Array();

var slideshow2_slideIndex = new Array();	// Index of current image shown
var slideshow2_slideIndexNext = new Array();	// Index of next image shown
var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
var slideshow2_currentOpacity = new Array();	// Initial opacity
var slideshow2_imagesInGallery = new Array();	// Number of images in gallery
var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
function createParentDivs(imageIndex,divId)
{
	if(imageIndex==slideshow2_imagesInGallery[divId]){	
		showGallery(divId);
	}else{
		var imgObj = document.getElementById(divId + '_' + imageIndex);	
		if(Opera)imgObj.style.position = 'static';
		if(!slideshow2_imageDivs[divId])slideshow2_imageDivs[divId] = new Array();
		slideshow2_imageDivs[divId][slideshow2_imageDivs[divId].length] =  imgObj;

		imgObj.style.visibility = 'hidden';	
		imageIndex++;
		createParentDivs(imageIndex,divId);	
	}		
}

function showGallery(divId)
{
	if(slideshow2_slideIndex[divId]==-1)slideshow2_slideIndex[divId]=0; else slideshow2_slideIndex[divId]++;	// Index of next image to show
	if(slideshow2_slideIndex[divId]==slideshow2_imageDivs[divId].length)slideshow2_slideIndex[divId]=0;
	slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId]+1;	// Index of the next next image
	if(slideshow2_slideIndexNext[divId]==slideshow2_imageDivs[divId].length)slideshow2_slideIndexNext[divId] = 0;

	
	slideshow2_currentOpacity[divId]=100;	// Reset current opacity

	// Displaying image divs
	slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'visible';
	if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'inline';
	if(navigator.userAgent.indexOf('Opera')<0){
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.visibility = 'visible';
	}
	
	if(document.all){	// IE rules
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity=100)';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity=1)';
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = 0.01;
	}		
	

	setTimeout('revealImage("' + divId + '")',slideshow2_timeBetweenSlides);		
}

function revealImage(divId)
{

	if(slideshow2_noFading){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'hidden';
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'none';
		showGallery(divId);
		return;
	}
	slideshow2_currentOpacity[divId]--;
	if(document.all){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity='+slideshow2_currentOpacity[divId]+')';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity[divId])+')';
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = Math.max(0.01,slideshow2_currentOpacity[divId]/100);	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity[divId]/100)));
	}
	if(slideshow2_currentOpacity[divId]>0){
		setTimeout('revealImage("' + divId + '")',slideshow2_fadingSpeed);
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'hidden';	
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'none';		
		showGallery(divId);
	}
}

function initImageGallery(divId)
{
	var slideshow2_galleryContainer = document.getElementById(divId);
	
	
	slideshow2_slideIndex[divId] = -1;
	slideshow2_slideIndexNext[divId] = false;
	
	var galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
	for(var no=0;no<galleryImgArray.length;no++){
		galleryImgArray[no].id = divId + '_' + no;
	}
	
	slideshow2_imagesInGallery[divId] = galleryImgArray.length;
	createParentDivs(0,divId);		
	
}





////// COUPON ///////////////////////

function func_coupon (id) {

	window.open("/coupon/"+id,"coupon","menubar=no,width=630,height=610,toolbar=no,scrollbars=no");

}





function GetXmlHttpObject2()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4)
{ 

}
}

function print_coupon(str,location)
{

xmlHttp=GetXmlHttpObject2();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="templates/1-2/coupon_print.php";
url=url+"?barcode="+str;
url=url+"&location="+location;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
window.print();
}




// AJAX UNIT SIZES /////////////////////////////

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("cs_units").innerHTML=xmlHttp.responseText;
}
}

function showUnits(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/templates/1-2/unit_sizes.php";
url=url+"?id="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


/// NEW DROP DOWN MENU//////////////////////////////////////////////////

// Copyright 2006-2007 javascript-array.com

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}



function addEvents() {
//onmouseover="mcancelclosetime()" onmouseout="mclosetime()
document.getElementById("m1").onmouseover = mcancelclosetime;
document.getElementById("m1").onmouseout = mclosetime;


document.getElementById("state1").onmouseover = function() {
document.getElementById("NC").style.visibility='visible';
document.getElementById("state1").style.backgroundColor='yellow';
}
document.getElementById("state1").onmouseout = function() {
document.getElementById("NC").style.visibility='hidden';
document.getElementById("state1").style.backgroundColor='#000';
}

document.getElementById("NC").onmouseover = function() {
document.getElementById("NC").style.visibility='visible';
}
document.getElementById("NC").onmouseout = function() {
document.getElementById("NC").style.visibility='hidden';
}



}





