
var map;
var geocoder;
var myPano;   
var markinfo;

function initialize() {
	if (GBrowserIsCompatible()) {
	  map = new GMap2(document.getElementById("map_canvas"));
	  map.setCenter(new GLatLng(38.959409, -98.876953), 3);
	  geocoder = new GClientGeocoder();
	  map.addControl(new GLargeMapControl());
	  map.addControl(new GMapTypeControl());
	}
}

function addAddressToMap(response) {
    map.clearOverlays();
    

	if (!response || response.Status.code != 200) {
		//alert("Sorry, we were unable to geocode that address");
	} else {
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		marker = new GMarker(point);
		map.addOverlay(marker);
		
		//GEvent.addListener(marker, "click", function() {
	
			marker.openInfoWindowHtml(markinfo);
			myPano = new GStreetviewPanorama(document.getElementById("pano"));
			myPano.setLocationAndPOV( marker.getLatLng(), null ); 
			GEvent.addListener(myPano, "error", handleNoFlash);

		//});
	}
}

function showLocation(address, info) {
    markinfo = info;
	geocoder.getLocations(address, addAddressToMap);
}

function handleNoFlash(errorCode) {
	if (errorCode == FLASH_UNAVAILABLE) {
		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
	}
} 


function fillMembers(){
    x = $('#MemberStates').val();
    //alert("handler.ashx?action=getmarks&st=" + st);
    var s = '<option value="Select...">Select...</opotion>';
    $.get("handler.ashx?action=getmarks&st=" + x, function(xml){
	    $('item', xml).each(function(data){ 
	        s = s + '<option value="' + $('ID', this).text() + '">'+ $('Organization', this).text() + ' - (' + $('City', this).text()  + ', ' + $('State', this).text() + ')' + '</option>' 
        });   
        //alert(s);
        $('#Members').html(s);
    });   
}

function setMark(){
    id = $('#Members').val();
    $.get("handler.ashx?action=getmarks&id=" + id, function(xml){
	    $('item', xml).each(function(data){ 
	        var info = '';
	        info = '<font class="text12"><b>Company: </b></font><font class="text12">' + $('Organization', this).text() + '</font><br>';
	        info = info + '<font class="text12"><b>Address: </b></font><font class="text12">' + $('Address1', this).text()  + ' ' + $('Address2', this).text() + ' ' + $('City', this).text() + ', ' + $('State', this).text() + ' ' + $('Zip', this).text() + '</font><br>';
	        info = info + '<font class="text12"><b>Phone: </b></font><font class="text12">' + $('Phone', this).text() + '</font><br>';
	        info = info + '<font class="text12"><b>Fax: </b></font><font class="text12">' + $('Fax', this).text() + '</font><br>';
	        info = info + '<font class="text12"><b>Website: </b></font><a target="_blank" href="' + $('WebSite', this).text() + '">' + $('WebSite', this).text() + '</font><br>';

	        showLocation($('Address1', this).text()  + ' ' + $('City', this).text() + ', ' + $('State', this).text() + ' ' + $('Zip', this).text(), info);
        });   
    }); 
}

$(document).ready(function () {

	if (queryString('pg') == 'membermap'){
	    var st = '<option value="Select...">Select...</opotion>';
	    $.get("handler.ashx?action=memberstates", function(xml){
  		    $('item', xml).each(function(data){ 
  		        st = st + '<option value="' + $('State', this).text() + '">' + $('State', this).text() + '</option>' 
            });   
            $('#MemberStates').html(st);
            fillMembers();
	    });  
	    
	    $("#MemberStates").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).attr('value');
          });
          fillMembers();
        }).change();
     
         $("#Members").change(function () {
              var str = "";
              $("select option:selected").each(function () {
                    str = $(this).attr('value');
              });
              setMark();
              $("#MemberStates").focus();
         }).change();  
	}	
	
	
	
							
	$('#accordion').accordion({ 
    	header: ".ui-accordion-header",
    	autoHeight: false
	});
	
	$(".topbarcell-body").mouseover(function () { 
    	$(this).addClass('topbar-rollover');
    });
	$(".topbarcell-body").mouseout(function () { 
    	$(this).removeClass('topbar-rollover');
    });
	
	$(".leftnav-item").mouseover(function () { 
		$('.greentext12', this).addClass('bluetext12');
    	$('.arrow', this).attr('src', 'layout/bluearrow.jpg');
    });
	$(".leftnav-item").mouseout(function () { 
		$('.greentext12', this).removeClass('bluetext12');
    	$('.arrow', this).attr('src', 'layout/greenarrow.jpg');
    });
	
	$(".leftnav-subitem").mouseover(function () { 
		$('.greentext12', this).addClass('bluetext12');
    	$('.diamond', this).attr('src', 'layout/bluediamond.jpg');
    });
	$(".leftnav-subitem").mouseout(function () { 
		$('.greentext12', this).removeClass('bluetext12');
    	$('.diamond', this).attr('src', 'layout/greendiamond.jpg');
    });

    $('#accordion').accordion("activate", 1)
	/*
	$.get("handler.ashx?action=isloggedin", function(data){
  		if (data=='true'){
			$('#accordion').accordion( "activate", 1)
		}else{
			$('#accordion').accordion( "activate", 0)
		}
	});
	*/
	
    $.ajax({
      url: "slideshow/slideshow.xml",
      success: function(xml){

        var htm = '';
        $('Image', xml).each(function(data){
            var tg = ''; 
            if ($('LinkTargetsSelf', this).text() == 'false'){
                tg = '_blank';
            } else {
                tg = '_self';
            }
            if ($('Link', this).text() != ''){
                htm = htm + '<a href="' + $('Link', xml).text() + '" target="' + tg + '">';
            }
            htm = htm + '<img src="' + 'slideshow/' + $('Src', this).text() + '" border="0" />';
            if ($('Link', this).text() != ''){
                htm = htm + '</a>';
            }
        });
        
        $('#slideshow').html(htm);        
        $('#slideshow').cycle({ 
            fx:    $('Effect', xml).text(), 
            speed:  $('Speed', xml).text()
        });
        
      }
    });

});

function queryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}
