// JavaScript Document dosjefes map

	//Page set up
	new Page('home', 'homeMI');
	new Page('music', 'musicMI', new Array('musicSlide1','musicSlide1.1','musicSlide1.2','musicSlide1.3', 'musicSlide1.4', 'musicSlide1.7', 'musicSlide1.8','musicSlide1.9', 'musicSlide2',
										   'musicSlide3', 'musicSlide4', 'musicSlide4.5', 'musicSlide5', 'musicSlide6', 'musicSlide7', 
			 'musicSlide8', 'musicSlide9'));
	new Page('cigars', 'cigarsMI', new Array('cigarSlide8', 'cigarSlide10', 'cigarSlide9', 'cigarSlide1',
											 'cigarSlide3', 'cigarSlide4', 'cigarSlide5', 'cigarSlide6', 
											 'cigarSlide7'));
	new Page('libations', 'libationsMI', new Array( 'libationsSlide5', 'libationsSlide6', 'libationsSlide2','libationsSlide2.25', 'libationsSlide2.5', 'libationsSlide3', 'libationsSlide4'));
	new Page('private_parties', 'private_partiesMI',  new Array('partySlide1','partySlide2', 'partySlide3', 'partySlide4', 'partySlide5', 'partySlide6', 'partySlide7'));
	new Page('location', 'locationMI');
	new Page('cigarMenu', 'cigarsMI');
	new Page('featuredCigarDetails', 'cigarsMI');
	new Page('libationsMenuPage', 'libationsMI');
	new Page('gallery', 'galleryMI');
	
	//Maps
	var from = "maillist";
	var amp = '@';
	var domain = "dosjefescigarbar.com";
	var xmlHttp;
	var from = from + amp + domain
	var subject = "New Address for Dos Jefes' mail list.";

	function getXMLHttpRequest(){
		try{
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		}catch (e){
	  		// Internet Explorer
			try{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}catch (e){
				try{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){
					alert("Your Browser does not support the technology necessary to retrieve our music schedule.");
					return xmlHttp;
				}
			}
		}
		
		return xmlHttp;
	}
	
	function sendAddress(){
		
		var message  = document.getElementById('message').value;
		if(checkEmail(message)){
			
			request = getXMLHttpRequest();
			request.onreadystatechange=function(){
				if(request.readyState == 4){
					if(xmlHttp.responseText == "result=success"){
						alert("Your email address has succesfully been submitted. Thank you for joining our mailing list.");
						document.getElementById('message').value = "";
					}else{
						alert("We were unable to process your request at this time. Please try again later. If the problem persists please contact the site administrator.");
					}
				}
				}
		
			request.open("GET","/mailer/send_mail.htm?subject=" + subject + "&message=" + message);
			request.send(null);
		}
  	}
	
	
    function getErrorCodes(){
		var codes = new Hash();
		codes.set("200", "Your request was sucessfully completed.");
		codes.set("400", "Your directions request could not be completed. Make sure your address is enetered and properly formated and spelled correctly \"100 Some Ave, New Orleans, LA\"");
		codes.set("500", "There was an internal server error and your request could not be completed. Please try again latter.");
		codes.set("601", "Your directions request could not be completed. Make sure your address is enetered and properly formated and spelled correctly \"100 Some Ave, New Orleans, LA\"");
		codes.set("602", "Your address could not be found. Please check the spelling and make sure your address is properly formated.");
		codes.set("603", "Your location cannot be mapped due legal or contractual restritions.");
		codes.set("604", "A route could not be computed between your location and our location. This usually is because no route exsist or that we do not have data for your location.");
		codes.set("610", "Please contact the site administartors and inform them that Google code 610 was returned.");
		codes.set("620", "Please contact the site administartors and inform them that Google code 620 was returned.");
		return codes;
	}
	
	var map2 = null;
    var geocoder = null;
	var marker = null;
	var directions = null;
	var errorCodes = getErrorCodes();
	var dirDiv = null;
	var MapDiv = null;
	var mapDivWidth = 0;
	var map = null;
	var latlng = null;
	
    function loadMap() {
		map = null;
	latlng = new google.maps.LatLng(29.916473, -90.11818);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    	map = new google.maps.Map(document.getElementById("map"),
        myOptions);
	
	
	var marker = new google.maps.Marker({
    position: latlng,
    title:"Dos Jefes Uptown Cigar Bar",
	animation: google.maps.Animation.DROP});
	marker.setMap(map);
	

  
		/*if (GBrowserIsCompatible()) {
			//if(map2 == null){
				mapDiv = document.getElementById('map');
				mapDivWidth = mapDiv.style.width;
				map2 = new GMap2(mapDiv);
				latlng = new GLatLng(29.916473, -90.11818);
				map2.setCenter(latlng, 16);
				map2.enableContinuousZoom();
				map2.enableGoogleBar();
				map2.addControl(new GSmallMapControl());
				map2.addControl(new GMapTypeControl());
				marker = new GMarker(latlng);
				GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("Dos Jefes Uptown Cicar Bar<br/> 5535 Tchoupitoulas St.<br/>New Orleans, LA 70115<br/>(504) 891-8500");
				  });
			map2.addOverlay(marker);
			*/
			/*}else{
				if(dirDiv != null && mapDiv.style.width != mapDivWidth){
					dirDiv.style.visibility = 'hidden';
					mapDiv.style.left = "0px";
					mapDiv.style.width = mapDivWidth;
					map2.checkResize();
					m = directions.getMarker(0);
					for(i = 0; m != null; i++){
						map2.removeOverlay(m);
						m = directions.getMarker(i);
					}
					pl = directions.getPolyline();
					map2.removeOverlay(pl);
					map2.addOverlay(marker);
					map2.setCenter(latlng, 16);
				}
			}*/
				
	}
	
	function currentLocation(){
		var initialLocation;

		var browserSupportFlag =  new Boolean();
		
		if(navigator.geolocation) {
    		browserSupportFlag = true;
    		navigator.geolocation.getCurrentPosition(function(position) {
      		initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
			getDirections(initialLocation);
    		}, function() {
      		handleNoGeolocation(browserSupportFlag);
    		});
		}
		
		
	}
	
	function handleNoGeolocation(browserSupportFlag){
		alert("You or Your Browser Does Not Allow Geolocation Support");
	}
	
	function enterLocation(){
		var start = prompt("Enter Starting Location");
		getDirections(start);
	}
	
	function showLocation(){
		var mapDiv = document.getElementById("map");
		mapDiv.innerHTML = "";
		mapDiv.style.width = '732px';
		mapDiv.style.left = '0px';
		
		dirDiv.style.visibility = 'none';
		
		loadMap();
		
	}
	
	
	function getDirections(start) {
		var directionsDisplay;
		var directionsService = new google.maps.DirectionsService();
		
 	 	var end = "29.916473, -90.11818";
		var mapDiv = document.getElementById('map');
		mapDiv.style.width = '474px';
		mapDiv.style.left = '260px';
		directionsDisplay = new google.maps.DirectionsRenderer();
		directionsDisplay.setMap(map);
		 
	 	dirDiv = document.getElementById("directions");
		dirDiv.innerHTML = "";
		dirDiv.style.visibility = 'visible';
		dirDiv.setAttribute("float", "left");
  		directionsDisplay.setPanel(dirDiv);
  		var request = {
    		origin:start,
    		destination:end,
    		travelMode: google.maps.TravelMode.DRIVING
 		};
  
  		directionsService.route(request, function(result, status) {
		if (status == google.maps.DirectionsStatus.OK) {
		  directionsDisplay.setDirections(result);
		}
  });
		
  		/*var from = document.getElementById('dFrom').value ;
		mapDiv = document.getElementById('map');
		dirDiv = document.getElementById('directions');
		if(directions == null){
			directions = new GDirections(map2,dirDiv);
			GEvent.addListener(directions, "load", function(){
				if(directions.getStatus().code == 200){
					dirDiv.innerHTML = "";
					mapDiv.style.width = '474px';
					mapDiv.style.left = '260px';
					dirDiv = document.getElementById('directions');
					dirDiv.style.visibility = 'visible';
					map2.removeOverlay(marker);
					map2.checkResize();
				}
			});
			GEvent.addListener(directions, "error", function(){
				var message = errorCodes.get("" + directions.getStatus().code);
				alert(message);  });
		}else{
			directions.clear();
		}
		directions.load(from + " to 29.916473, -90.11818");
		
		*/
	 }
	 
	 //Email
	 
	function checkEmail (strng) {
		var error="";
		var emailFilter=/^.+@.+\..{2,3}$/;
		
		if (strng == "") {
		error = "You didn't enter an email address.\n";
		}
	
		if (!(emailFilter.test(strng))) { 
			error = "Please enter a valid email address.\n";
		}else {
			//test email for illegal characters
			var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
			if (strng.match(illegalChars)) {
				error = "The email address contains illegal characters.\n";
			}
		}
		
		if(error != ""){
			alert(error);
			return false;
		}
		
		return true;    
	}
	
	var playing = 0;
	function playMusic(tog){
		Sound.enable();
		Sound.play('media/summertime2.mp4');
		playing = 1;
		setTimeout("document.getElementById('soundToggle').innerHTML = 'Play Music';playing = 0;", 253000);
	}
	
	function stopMusic(){
		Sound.enable();
       	Sound.play('',{replace:true});
       	Sound.disable();
		playing = 0;
	}
	
	function toggleMusic(tog){
		if(playing == 0){
			playMusic(tog);
			tog.innerHTML = "Stop Music";
		}else{
			stopMusic();
			tog.innerHTML = "Play Music";
		}
	}
	
	
	var libationMenuPages = new Hash();
	var activeMenuPage = null;
	
	function addLibationMenuPages(pageName){
		var pageDiv = document.getElementById(pageName);
		libationMenuPages.set(pageName, pageDiv);
		if(activeMenuPage != null){
			pageDiv.style.display = 'none';
		}else{
			activeMenuPage = pageDiv;
		}
	}
	
	function setUpLibationMenuPages(){
		addLibationMenuPages("beer_1");
		addLibationMenuPages("beer_2");
		addLibationMenuPages("byTheGlass");
		addLibationMenuPages("whiteWine_1"),
		addLibationMenuPages("whiteWine_2");
		addLibationMenuPages("whiteWine_3");
		addLibationMenuPages("redWine_1");
		addLibationMenuPages("redWine_2");
		addLibationMenuPages("redWine_3");
		addLibationMenuPages("redWine_4");
		addLibationMenuPages("redWine_5");
		addLibationMenuPages("sparklingWine_1");
		addLibationMenuPages("fortifiedWine_1");
		addLibationMenuPages("fortifiedWine_2");
		addLibationMenuPages("spirits_1");
		addLibationMenuPages("spirits_2");
		addLibationMenuPages("spirits_3");
		addLibationMenuPages("spirits_4");
		addLibationMenuPages("spirits_5");
		addLibationMenuPages("spirits_6");
		addLibationMenuPages("spirits_7");
	}
	
	function nextMenuPage(nextPage){
		next = document.getElementById(nextPage);
		if(activeMenuPage != next){
			Effect.BlindLeft(activeMenuPage, {queue: { position: 'front', scope: 'open' } }); 	
			Effect.BlindOut($(nextPage), {queue: { position: 'end', scope: 'open' } });
		}
		activeMenuPage = document.getElementById(nextPage);
	}
	

