var locations = new Array(7);locations['27'] = new Array("27", "29.6534854", "-95.2524612", "-117.0924", "3.058", "", "", "", "Your Storage Place", "Houston", "9330 Gulf Freeway Houston, TX 77017", "713-941-1001", "832-266-1351", "", "", "", "", "TX", "Texas", "77017", "9330", "Gulf Freeway"); locations['28'] = new Array("28", "29.9263230", "-95.4081180", "65.99", "3.4", "1", "29.926403", "-95.408969", "Your Storage Place", "Houston", "11820 Airline Rd. Houston, TX 77037", "281-447-0776", "832-327-8825", "", "", "", "", "TX", "Texas", "77037", "11820", "Airline Rd."); locations['29'] = new Array("29", "29.8160610", "-95.4681820", "220.2", "3.4", "", "29.817652", "-95.467291", "Your Storage Place", "Houston", "10901 Northwest Freeway Houston, TX 77092", "713-683-9950", "832-266-1384", "From 290 west towards San Antonio.  Exit 34th Street uturn under freeway and take the 1st right off the feeder.  Right behind the Blackeyed Pea.", "From the beltway take 290 to wards down town take the 34th street exit and make a right at the end of Deauville Plaza.  Right behind the Blackeyed Pea", "_NULL", "_NULL", "TX", "Texas", "77092", "10901", "Northwest Freeway"); locations['30'] = new Array("30", "29.7372253", "-95.5279111", "-144.8237991", "8.36509", "1", "29.737234", "-95.528036", "Your Storage Place", "Houston", "9333 Westheimer Rd. Houston, TX 77063", "713-783-9633", "832-266-1391", "Located in W Houston on Westheimer between Fondren and Gessner", "Located in W Houston on Westheimer between Fondren and Gessner", "Located in W Houston on Westheimer between Fondren and Gessner", "Located in W Houston on Westheimer between Fondren and Gessner", "TX", "Texas", "77063", "9333", "Westheimer Rd."); locations['24'] = new Array("24", "29.5124500", "-98.5712460", "-452.6937582565111", "5.3336719559974775", "1", "29.513471", "-98.569705", "Your Storage Place", "San Antonio", "8029 Fredericksburg Rd. San Antonio, TX 78229", "210-614-2579", "210-782-8573", "", "", "", "", "TX", "Texas", "78229", "8029", "Fredericksburg Rd."); locations['25'] = new Array("25", "29.5258820", "-98.4118840", "249.71", "3.38", "1", "29.525808", "-98.411031", "Your Storage Place", "San Antonio", "9423 Perrin Beitel San Antonio, TX 78217", "210-655-6640", "210-782-8469", "", "", "", "", "TX", "Texas", "78217", "9423", "Perrin Beitel"); locations['26'] = new Array("26", "29.4954680", "-98.4982110", "76.32000000000001", "-0.13999999999999702", "0", "29.496069", "-98.499267", "Your Storage Place", "San Antonio", "6414 San Pedro Ave. San Antonio, TX 78216", "210-342-7273", "210-782-8396", "", "", "", "", "TX", "Texas", "78216", "6414", "San Pedro Ave."); 

var facilities = new Array(27,28,29,30,24,25,26)



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

var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var markersArray = [];
  var latlng; 
  var map;
  var trafficLayer;
  var bounds = new google.maps.LatLngBounds();
  var infowindow = new google.maps.InfoWindow();

  
   
  
  function createMarker(page, id) {
  
  	var contentString = "<h3>"+ locations[id][8] +" - "+ locations[id][9] +"</h3>";
	contentString += '<img src="/images/gallery/'+ locations[id][0] +'/pic1.jpg" alt="'+ locations[id][8] +' - '+ locations[id][9] +' '+ locations[id][17] +'" width="100" border="1" style="float:left; margin-right: 13px;"/>';
	contentString += locations[id][20] +' '+locations[id][21]+'<br/>'+locations[id][9]+', '+locations[id][17]+'<br/>';
	contentString += ((locations[id][12] !== "--" ) ? locations[id][12] : locations[id][11]) +'<br/>'
	
	contentString += '<a href="/'+locations[id][9].replace(" ", "-")+'-'+locations[id][18]+'/'+locations[id][19]+'/'+locations[id][0]+'">More Information</a>';
	


	var position = new google.maps.LatLng(locations[id][1], locations[id][2])
    var marker = new google.maps.Marker({
        position: position,
        map: map,
        title: locations[id][8],
		icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=Y%7C000000%7Cffffff'
    });
	/*http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=U%7CD70000%7Cffffff*/
	
	/*var infowindow = new google.maps.InfoWindow({
        content: contentString
    });*/
    if (page != 'facility') { google.maps.event.addListener(marker, 'click', function() {
        infowindow.close()
		infowindow.setContent(contentString);
		infowindow.open(map, marker);

    }); }
	markersArray.push(marker);
	bounds.extend(position)
	//alert (id + locations[id])
}
  
  
  function initialize(page, id, state) {
  
    if (id) { latlng = new google.maps.LatLng(locations[id][1], locations[id][2]); }
	else { latlng = new google.maps.LatLng(0,0) } 
    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"));
	
	if (id) {
		createMarker(page, id)
	} else {
		
		for (var i=0; i<facilities.length; i++) {
			
			if (state == locations[facilities[i]][18]) {
				createMarker(page, facilities[i])
			}
			
			if (page == 'all_locations') {
				createMarker(page, facilities[i])
			}
			
		}
		map.fitBounds(bounds);
	}

	

	if (id) {
	 // 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(((locations[id][6]) ? new google.maps.LatLng(locations[id][6], locations[id][7]) : latlng));
	

    panorama.setPov({
      heading: ((locations[id][3]) ? parseFloat(locations[id][3]) : 16.5), 
      zoom: ((locations[id][5]) ? parseFloat(locations[id][5]) : 0),
      pitch: ((locations[id][4]) ? parseFloat(locations[id][4]) : 7.658284707444938)} //
    );
	
	}
	
   trafficLayer = new google.maps.TrafficLayer();
  
	
	google.maps.event.addListener(panorama, 'pov_changed', function() {
	document.getElementById("directionsPanel").innerHTML =  panorama.getPosition()+' '+panorama.getPov().heading +' '+ panorama.getPov().pitch
	
    }); 
	
	
if (page == 'state_locations' || page == 'all_locations') {} else {
// 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(start, id) {
    var end = locations[id][10];
    var start = start;
    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(id) { 
	directionsDisplay.setMap(null);
	
	if (markersArray) {
		for(i in markersArray) {
			markersArray[i].setMap(map);
		}
	}
	document.getElementById("directionsPanel").innerHTML = '';
	document.getElementById("directionsPanel").innerHTML = '<table cellpadding="5">' + 
	
	// 13 14 15 16
	
	((locations[id][13]) ? '<tr><td><b><span class="directions">From the North:</span></b> '+ locations[id][13] +'</td></tr>' : '') +
	((locations[id][14]) ? '<tr><td><b><span class="directions">From the South:</span></b> '+ locations[id][14] +'</td></tr>' : '') +
	((locations[id][15]) ? '<tr><td><b><span class="directions">From the East:</span></b> '+ locations[id][15] +'</td></tr>' : '') +
	((locations[id][16]) ? '<tr><td><b><span class="directions">From the West:</span></b> '+ locations[id][16] +'</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/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/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("TX").style.visibility='visible';
document.getElementById("state1").style.backgroundColor='yellow';
}
document.getElementById("state1").onmouseout = function() {
document.getElementById("TX").style.visibility='hidden';
document.getElementById("state1").style.backgroundColor='#000000';
}

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



}





