//control for forms
$(document).ready(function() {

$(":input").focus(function () {
	var atr = $(this).attr("value");

	switch (atr){
	case "Your Email Address?":
	$(this).attr("value", "")
  	break;
	case "Your Name?":
	$(this).attr("value", "")
  	break;
 	case "Subject?":
	$(this).attr("value", "")
  	break;
 	case "Your Comment?":
	$(this).attr("value", "")
  	break;
	
	case "Date?":
	$(this).attr("value", "")
  	break;
	case "Time?":
	$(this).attr("value", "")
  	break;
	case "Event Title?":
	$(this).attr("value", "")
  	break;
	case "Event Description?":
	$(this).attr("value", "")
  	break;
	}
	
	$(this).css("borderBottomColor", "#ffffff");
	
});


$(":input").blur(function () {
	var nme = $(this).attr("name");
	var atr = $(this).attr("value");
	
	//if nothing is entered
	if (atr == "") {
	
	switch (nme){
	case "email":
	$(this).attr("value", "Your Email Address?")
  	break;
	case "realname":
	$(this).attr("value", "Your Name?")
  	break;
 	case "subject":
	$(this).attr("value", "Subject?")
  	break;
 	case "Message":
	$(this).attr("value", "Your Comment?")
  	break;
	
	case "edate":
	$(this).attr("value", "Date?")
  	break;
	case "etime":
	$(this).attr("value", "Time?")
  	break;
	case "title":
	$(this).attr("value", "Event Title?")
  	break;
	case "description":
	$(this).attr("value", "Event Description?")
  	break;
	}
	
	}//end if
	
	$(this).css("borderBottomColor", "#23332D");
	
});


$(":input").mouseover(function () {
$(this).css("borderBottomColor", "#ffffff");
});

$(":input").mouseout(function () {
$(this).css("borderBottomColor", "#23332D");
});

$("#sendbutton").click(function(event){
 	 send_message(this.form)
	 event.preventDefault();
   });

});


$(document).ready(function() {
$("#calendar").datepicker({
onSelect: function(dateText, inst) {

adm = $('#iad').attr('name');

$('#events').load('./ajax/getSelDaysEvents.php', {dte: dateText, adm: adm}, function() {

//add trash event for each event
$(".trashIMG").each(function(index) {

$(this).click(function(event){
	eID = $(this).attr('name');
 	 deleteEvent(eID);
	 event.preventDefault();
   });

});

});


}

});
});


$(document).ready(function() {
 $("#sitemap_button").click(function(event){
	 smap('open');
	 event.preventDefault();
   });

$("#loginLink").click(function(event){
	 showLoginForm();
	 event.preventDefault();
   });
   
});



function initMap() {

            var max = 0,
                min = Number.MAX_VALUE,
                cc,
                startColor = [200, 238, 255],
                endColor = [0, 100, 145],
                colors = {},
                hex;
            for (cc in gdpData) {
                if (parseFloat(gdpData[cc]) > max) {
                    max = parseFloat(gdpData[cc]);
                }
                if (gdpData[cc] < min) {
                    min = parseFloat(gdpData[cc]);
                }
            }
            for (cc in gdpData) {
                if (gdpData[cc] > 0) {
                    colors[cc] = '#';
                    for (var i = 0; i<3; i++) {
                        hex = Math.round(startColor[i] + (endColor[i] - startColor[i])*(gdpData[cc] / (max - min))).toString(16);
                        if (hex.length == 1) {
                            hex = '0'+hex;
                        }
						
                        colors[cc] += (hex.length == 1 ? '0' : '') + hex;
                    }
                }
            }

            $('#map').vectorMap({
                values: gdpData,
                scaleColors: ['#C8EEFF', '#006491'],
                normalizeFunction: 'polynomial',
                hoverOpacity: 0.7,
                hoverColor: true,
				colors: {us:'#ffcc00', br:'#ffcc00', cn:'#ffcc00', jm:'#ffcc00', jp:'#ffcc00', pg:'#ffcc00', pt:'#ffcc00'},
				backgroundColor: '#ffffff',
				onRegionClick: showLocation
            });
           
		    $('#mapUS').vectorMap({
                map: 'usa_en',
				color: '#006491',
               
                hoverOpacity: 0.7,
                hoverColor: true,
				colors: {mo:'#ffcc00', ne:'#ffcc00', ks:'#ffcc00', tx:'#ffcc00'},
				backgroundColor: '#ffffff',
				onRegionClick: showLocationUS
            });
		   
}//end function
		
function showLocation(event,label){

//if us is selected change map
if (label == 'us') {
$('#info').empty();
$('#info2').show();
//switch maps
$('#map').fadeToggle('slow', function() {
    // Animation complete.
	$('#mapUS').fadeToggle('slow')
  });


} else {

//get info for country clicked
$('#info').load('./ajax/getMissions.php', {id: label}, function() { $('#info2').hide(); });
}

 
}//end function


		
function showLocationUS(event,label){

$('#info').load('./ajax/getMissionsUS.php', {id: label}, function() {$('#info2').hide(); });
 
}//end function



function smap(x) {

if (x == "open") {
$("#innerFooter").css("height", '30em');
$(".none").show();
$("#sitemap_button img").attr('src', './images/smapOpen.png')


//modify smap button
$("#sitemap_button").click(function(event){
	 smap('close');
	 event.preventDefault();
   });

} else {

$("#innerFooter").css("height", '6.5em');
$(".none").hide();
$("#sitemap_button img").attr('src', './images/smapClose.png')


//modify smap button
$("#sitemap_button").click(function(event){
	 smap('open');
	 event.preventDefault();
   });
  
}
 
}//end function


function send_message(frm) {
email = frm.elements[0].value;
name = frm.elements[1].value;
subject = frm.elements[2].value;
message = frm.elements[3].value;

imp_str = email+"|"+name+"|"+subject+"|"+message+"|";

//save imput
$.post("./ajax/send_message.php", {imp: imp_str}, function(){

$("#farea").html("<p>Your message has been sent</p><p> and will be reviewed as soon</p><p> as possible.</p>");

});

}//end function

//start events
$(document).ready(function() {
$( "#edate" ).datepicker();

$("#addevbutton").click(function(event){
 	 addEvent(this.form)
	 event.preventDefault();
   });

//add trash event for each event
$(".trashIMG").each(function(index) {

$(this).click(function(event){
	eID = $(this).attr('name');
 	  deleteEvent(eID);
	 event.preventDefault();
   });
   
});
   
   
});
///////////////////////////

function addEvent(frm) {
edate = frm.elements[0].value;
etime = frm.elements[1].value;
title = frm.elements[2].value;
description = frm.elements[3].value;

imp_str = edate+"|"+etime+"|"+title+"|"+description+"|";

//save imput
$.post("./ajax/addEvent.php", {imp: imp_str}, function(){

$(".red").text("Event added!  Add another event?");

$("#edate").attr("value", "Date?");
$("#etime").attr("value", "Time?");
$("#title").attr("value", "Event Title?");
$("#description").attr("value", "Event Description?");

});

}//end function


function deleteEvent(eID) {


$('body').append($("<div>").attr('id', 'mOverlay'));

$("#mOverlay").fadeIn('fast', function(){

$('#mOverlay').load('./templates/snips/delete_form.php', {eID: eID, act: 'form'}, function() {


});

});

}//end function


function killEvent(eID) {

$.post("./ajax/deleteEvent.php", {eID: eID}, function(){ 

$('#mOverlay').load('./templates/snips/delete_form.php', {eID: eID, act: 'killed'}, function() {


});


});


}//end function



//close overlay
function closeOver() {
//check for overlay, then close
if ($('#mOverlay').length) {
	$("#mOverlay").fadeOut('fast', function() {
	$('#mOverlay').remove();
	});
}//end if

}//end function


function showLoginForm() {

$('body').append($("<div>").attr('id', 'mOverlay'));

$("#mOverlay").fadeIn('fast', function(){

$('#mOverlay').load('./templates/snips/login_form.php', function() {



$('#float_form :input').focus(function () {
	var atr = $(this).attr("value");

	switch (atr){
	case "User Name...":
	$(this).attr("value", "")
  	break;
	case "Password...":
	$(this).attr("value", "")
  	break;
	}
	
	$(this).css("borderBottomColor", "#ffffff");
	
	
	
$('#float_form :input').blur(function () {
	var nme = $(this).attr("name");
	var atr = $(this).attr("value");
	
	//if nothing is entered
	if (atr == "") {
	
	switch (nme){
	case "user":
	$(this).attr("value", "User Name...")
  	break;
	case "pass":
	$(this).attr("value", "Password...")
  	break;
	}
	
	}//end if
	
	$(this).css("borderBottomColor", "#000000");
	
});
	
});
	
});


});

}//end function



function loadPlayer() {

//var scnt = $('#scnt').attr("name");

//AJAX get page content from database
$.get("./ajax/getSermons.php", function(data) {

x_sermon = $(data).find('sermon_info').each(function() {

	var x_sID = $(this).find('sID').text()
	var x_sdate = $(this).find('sdate').text()
	var x_stitle = $(this).find('stitle').text()

//sermon filename
var fnme = x_sdate+"-"+x_stitle;
	
//for( i=0; i < scnt; i++){
//var x = i+1;
 $("#jquery_jplayer_"+x_sID).jPlayer({
        ready: function () {
          $(this).jPlayer("setMedia", {
            mp3: "http://www.parklanebaptistchurch.org/sermons/mp3/"+fnme+".mp3"
          });
        },
		play: function() { // To avoid both jPlayers playing together.
			$(this).jPlayer("pauseOthers");
		},
        swfPath: "./js",
        supplied: "mp3",
		cssSelectorAncestor: "#jp_container_"+x_sID,
		wmode: "window"
 });
 
 
//}//end loop

 });//end each loop
});//end get

}//end function
