// JavaScript Document

var map;

var info_window = new google.maps.InfoWindow({content: ''});

function roundTopCorners() {

try {

jQuery(".sideheader").corner("8px top");
jQuery(".calendar-month").corner("8px top");

}

catch(err){}//ie6 doesn't like this

} 

function hoverButton(imgDir){

	

	jQuery(".hoverbutton").hover(			   

      function () {

        jQuery(this).attr({ 

		src: imgDir + "/images/" + this.id + "-on.jpg"

		});



      }, 

      function () {

        jQuery(this).attr({ 

		src: imgDir + "/images/" + this.id + "-off.jpg"

		});

      }

    );

}

function goView(id) {

jQuery("#eventdetails").dialog("open");

   jQuery("#modalIframeId").attr("src","http://www.ismyrotaryclub.org/event/view.cfm?eventID=" + id + "&xsl=http://rotary5030.org/xsl/Event.xsl");

   return false;

}

function goMail(id, name) {

	//800098061

 /*jQuery("#rotaryemail").attr({ 

          action: "http://www.IsMyRotaryClub.org/SendMail.cfm?ID=800098061&rURL=http://rotary5030.org/support/"

       });   */	

  

  jQuery("#rotaryemail #tomember").text("Send email to " + name);	

  jQuery("#rotaryemail").attr({ 

          action: "http://www.IsMyRotaryClub.org/SendMail.cfm?ID="+id+"&rURL=http://rotary5030.org/support/"

       });   	

  

  jQuery("#sendemail").dialog("open");

 

}

 

function showEvents(data){

//alert('here');

var statusHTML = [];

for (var i=0; i<data.length; i++) {

    var p = data[i];



                   statusHTML.push('<div class="borderdiv">');
                     
                   statusHTML.push('<h3>District Govenor Visits</h3>') ;  

                              for (var j=0; j<p.length; j++) {



                                             var sd = Date.parseDate(p[j].STARTDATE, "F, d Y g:i:s");



                                  statusHTML.push('<ul class="menu"><li><span>'+ sd.dateFormat("F d") +'</span>');



 var eventName =   p[j].EVENTNAME.replace("DG Official Visit", "")                               

statusHTML.push(eventName+'</li></ul>');

   



                              }             

                  // statusHTML.push('<p><a href="http://www.directory-online.com/rotary/Calendar.cfm?C=L&T=D&D=5030&ClubID=0" target="_blank">View full calendar &raquo;</a></p>');

                   statusHTML.push('</div>');



               }

try {

 jQuery('#GovVisits').html(statusHTML.join(''));

}

catch(err) {}

}

function showLeaders(json){

	

var result = [];



var statusHTML = [];

 for (var i=0; i<json.length; i++) {

	

   var p = json[i];

  

   

   for (var j=0; j<p.length; j++) {

	

	 if (jQuery.trim(p[j].COMMITTEEPOSITION).match(/^((?!Area).)*$/i)  || jQuery.trim(p[j].COMMITTEEPOSITION).match(/\bArea\b\s+\d/i))	 {

	 statusHTML.push('<div class="clearleft" style="margin-bottom:20px;font-size:.9em;">');   

     if (p[j].IMAGE.length > 0) {

     statusHTML.push('<p><img  class="left gapright"  style="width:50px;margin-bottom:5px;" src="'+p[j].IMGPATH+p[j].IMAGE+'" /></p>');

     }

       statusHTML.push('<h3 class="Position">'+p[j].COMMITTEEPOSITION+'</h3>');

	   if (jQuery.trim(p[j].AREACLUBS) != "")  {

	       statusHTML.push('<p class="nogapbottom">' +p[j].AREACLUBS+'</p>');

	   }

// statusHTML.push('<tr><td class="Member">'+p[j].USERNAME+' </td></tr>');

       statusHTML.push('<p class="Member"><a href="#" id="'+p[j].USERID+'">'+p[j].USERNAME+'</a></p>');

          statusHTML.push('</div>');

   }

   }



 }

 try {

jQuery('#ClubLeaders').html(statusHTML.join(''));

}

catch(err) {}

}

function initialize() {

 if (jQuery("#map_canvas").length > 0) {
         var latlng = new google.maps.LatLng(47.6062095, -122.3320708);

         var myOptions = {

           zoom: 8,

          center: latlng,

           mapTypeId: google.maps.MapTypeId.ROADMAP

         };

         map = new google.maps.Map(document.getElementById("map_canvas"),  myOptions);

			for (i=0; i<data.length; i++) {

			  // alert(data[i].clubname);

			  

			  addMarker(data[i].lat, data[i].lng, data[i].clubname, data[i].address)





			}

       
 }
		 
  
}


function addMarker(lat, lng, title, note) {
 
	var myLatlng = new google.maps.LatLng(lat, lng)

			  var marker = new google.maps.Marker({

                 position: myLatlng, 

                 map: map, 

                 title:title

              }); 

			  marker.note = note;



              google.maps.event.addListener(marker, 'click', function() {

                 info_window.content = '<div>Directions to <a href="http://maps.google.com/maps?daddr=' +marker.note +'" target="_blank">' + marker.getTitle() +  '</a> </div>';

                 info_window.open(map, marker);

              });

	return marker;



}

jQuery(document).ready(function() {

var validator = jQuery("#rotaryemail").validate({ errorElement: "p"}); 	
jQuery.getJSON('http://www.IsMyRotaryClub.org/Event/Event.cfm?AccountID=5030&Mo=1&CAT=6' +"&callback=?", function(data) {

//showEvents handles dist gov visits which are over now
//showEvents(data);

 

});

/*jQuery('li.eventdesc a').live('click', function() {

	goView(jQuery(this).attr('id'));

	return false;

});



jQuery("#eventdetails").dialog({

           autoOpen: false,

           modal: false,

           height: 600,

           width: 620,

		   zindex: 39990

 });
*/
 jQuery("#sendemail").dialog({

           autoOpen: false,

           modal: false,

           height: 500,

           width: 620,close: function() {

				validator.resetForm();

                jQuery("#rotaryemail")[0].reset();

			}



 });

jQuery('p.sendbtn  a').live('click', function() {

	 if (!jQuery("#rotaryemail").valid()) {

       return false;

     } 

	 jQuery("#Submit").click();



}); 

jQuery('p.Member a').live('click', function() {

	goMail(jQuery(this).attr('id'), jQuery(this).text());

	return false;

});

jQuery.getJSON('http://www.IsMyRotaryClub.org/District/DLC.cfm?AccountID=5030' +'&callback=?', function(data) {

showLeaders(data);

 

});	

roundTopCorners();



hoverButton(imageDir);

jQuery("#sidebarright .borderdiv a").click(function() {

	jQuery("#sidebarright .borderdiv a").removeClass("current");

	jQuery(this).addClass("current");

});

jQuery('#quotes').innerfade({ speed: 5000, timeout: 15000, type: 'random'});

jQuery("#searchbtn").click(function() {

		jQuery("form")[0].submit();return false;

	});

 

jQuery('#slideshowcontainer').cycle({
	 slideExpr: '#slideshow',	
     fx: 'scrollLeft',
     timeout: 10000,
     delay: -2000
    });  

//map on club meetings page	

initialize();	
});
