/**
 * @author dana martinelli   ;
 */
$(document).ready(function(){


	var sid = $("#sid").val();
	var uid = $("#uid").val();
	var ts = $("#ts").val();
	var ru = $("#ru").val();       
	
    var city;
  	var zip;
    var state;
    var notice;
  	var lat;
  	var lng;
  	var catid = 0;
  	var post; 
  	var nestEnterIn;
  	var fresh;
  	var tagEnterIn;
  	var Nemail;
  	var AjaxUpload;
  	var	SMSname;
  	var	phone;


       startMe();
	     logo();
	     focusZip();
       keyUpZip();
       keyUpCity();
       createNest();
       saveUser(uid);
       checkUser();
       videoMe();
	     expandText();
	     countit();
	     sendText();
	     uploadImage();
	     getCities();
	     getTags();
	     getALLCityNests(7);
	     getGoodTime();
	     feedback();
	     keySearch();
	     clickSearch();
	     getAllNests();
	     topSearch();
	     minimize();
	     lookup(inputString);
       fill(thisValue);
    
       //aboutNestr();
        



// get the good time bro      
function getGoodTime(){
  
$("input#f-cityForm").autocomplete("auto/autocomplete-ajax.php");
  
  }	   

 //add images
 

function uploadImage(){

 $("#addImageButton2").click(function(){
    $("#upstatus").html("Uploading...").fadeIn(500);

});

               // bind 'myForm' and provide a simple callback function 
            $('#myForm').ajaxForm(function(data) {
                
                $("#imgBack").html(data).fadeIn(500);
                //$("#addImageButton2").attr("disabled", "true");
                  $("#upstatus").html("Done!").fadeOut(1000);
                
            }); 

} 

     

 
	function logo(){
	 //init
	$("#logo").click(function(){
	 cityHomeLink = 'no';   
	closeMarker()
	$("#alertMe").hide();
	$("#private").hide(); 
  $("#mainMapOverlay").fadeIn(200);
  $("#mainMap").hide();              
  $("#mustLogin").fadeOut(200); 
	$("#broadAdd").hide();                                                                     
	$("#broadAdd2").hide();
	$("#bigNestBox").hide();
	$("#castBox").hide();
	$("#nestBox").hide();
	 $("#catName").html("<strong>General (choose a category above to change)</strong>");
     startMe();
	 fadeOutReg();
	 clearCats();
	 $("#what").click(function(){
     $("#whatisNestr").toggle();
	
	});
	}); 

	}
	
	
	//find save user ...yeah
	function saveUser(uid){   
	  $("#logMeIn").click(function(){ 
   	
				f2_email = $("#f2_email").val();
				f_capForm = $("#f_capForm").val();
				
        $.post("i-register-email.php", {
				
 					f2_email: f2_email,
 					uid: uid,
 					sid: sid,                          
 					f_capForm: f_capForm
 					
				}, function(data){
				  
					$("#loginUpdate").html(data).fadeIn(100);
				});
			});	
			
		}
		
			//Login User

		


function checkUser() {

	$("#broadClose5").click(function(){
$("#mustLogin").fadeOut(400);
$("#nestBox").fadeIn(400);
$("#broadAdd").fadeIn(400);
});

  	  $("#broadAdd").click(function(){ 
  	  	bigSave();
  	 
  	  $("#broadAdd").fadeOut(400);


        $.getJSON("i-getUserInfo.php", {
        
            sid: sid
                               
        }, function(mm){ 

           
            confirmed = mm.confirmed;
            rusid = mm.rusid;
   

            if (confirmed == '1'  &&  rusid == sid  ) {                        

             // $("#myName").html('Hi There, '+reg_name+'!');
              $("#bigNestBox").slideDown(500);
          	  $("#broadAdd").fadeOut(200);
          	  $("#broadAdd2").fadeIn(400);
            }
            else {
            
                //make  the guest login
               $("#nestBox").fadeOut(200);
              $("#mustLogin").fadeIn(200);
            }
        });	  
		  });	
    
  }	
	function clearCats() {
	
	  $(".btn_market").removeClass("mainActive");
    $(".btn_op").removeClass("mainActive");
    $(".btn_meet").removeClass("mainActive");
    $(".btn_ev").removeClass("mainActive");
			
	}
	function startMe(){
		$('#markItUp').markItUp(mySettings);
	$("#f-cityForm").attr("value", "Palo Alto, CA");
	 $("#catBox").hide();
  $("#alertMe").hide();
    //$("#catBox").show();
    //$("#addImageButton1").attr("disabled", "false");
    //$("#addImageButton2").attr("disabled", "false");

		$("#bottom").fadeIn(300);
		$("#what").fadeIn(300);
    //$("#alertMe").html("<p>Welcome!</p>");
		$("#what").click(function(){
    $("#whatisNestr").toggle();
		 
		
	});
	}

// manage fades 

	function fadeOutIntro(){
		$("#mainMapOverlay").fadeOut(200);
		$("#mainMap").show(); 
		$("#bottom").fadeOut(200);
		$("#what").fadeOut(200);
		$("#whatisNestr").fadeOut(200);
		 $("#mustLogin").fadeOut(200);
	}

	function fadeOutReg(){
		$("#panel").fadeOut(500);
		$("#panelLogin").fadeOut(100);	


	}

	function resetMe(){
		fadeOutIntro();
		fadeOutReg();
		startMe();
		$("#private").hide();
		$("#broadAdd").hide();
		$("#broadAdd2").hide();
		$("#bigNestBox").hide();
		
		
	}
	
//broadcast panel
	function broadcast() {
	

	$("#castBox").click(function(){
	  $("#broadCloseVid").hide();
	 $("#count").show();
  $("#tagBox").show();
  $("#lightbox").fadeIn(200);
   $("#centerMe").fadeIn(200);  
	$("#alertMe").show();
	closeMarker()
	$("#nestAction").html("Add a Short Message to Broadcast");
	$("#save2").show();
	$("#sendBox").hide();
	
	//$("#castBox").fadeOut(400);
	$("#nestBox").fadeIn(200);
	$("#nestEnterIn").fadeIn(200);
	$("#broadAdd").fadeIn(200);
	 });
	 $("#broadClose").click(function(){
	 $("#mustLogin").fadeOut(200);
	 $("#broadAdd2").fadeOut(200);
	 $("#bigNestBox").fadeOut(200);
	 
   $("#lightbox").fadeOut(200);
	 $("#nestBox").fadeOut(200);
	 $("#castBox").fadeIn(200);
	 $("#broadAdd").fadeOut(200);
	 $("#sendBox").hide();
	 });
	 
// send Tweet	 
	 $("#broadTwit").mouseover(function(){
	 $("#broadType").html("Send Through Twitter");
	 });
	 $("#broadTwit").mouseout(function(){
	 $("#broadType").html("Choose a Broadcast Type");
	 });
	 $("#broadTwit").click(function(){
	 $("#count").hide();
	 $("#tagBox").hide();
	  $("#save2").show();
	 $("#sendBoxSMS").hide();
	 $("#sendBoxEmail").hide();
	 $("#sendBoxLink").hide();
	 $("#nestAction").html("Send This As A Tweet");
	 $("#broadTools").hide();
	 $("#nestEnterIn").hide();
	 $("#sendBox").show();
	 $("#sendBoxTweet").show();
	 $("#goArrowTwit ").show();
	 $("#sendEdit-on").show();
	 $("#sendEdit").hide();
	 
	 
	 });
// send Facebook
	 
	 $("#broadFace").mouseover(function(){
	 $("#broadType").html("Update Your Facebook Status");
	 });
	 $("#broadFace").mouseout(function(){
	 $("#broadType").html("Choose a Broadcast Type");
	 });
	 
// send Email	
	 $("#broadEmail").mouseover(function(){
	 $("#broadType").html("Send Via Email");
	 });
	 $("#broadEmail").mouseout(function(){
	 $("#broadType").html("Choose a Broadcast Type");
	 });
	 $("#broadEmail").click(function(){ 
	  $("#count").hide();
	 $("#tagBox").hide();
	 $("#broadTools").hide();
	  $("#save2").show();
	 $("#sendBoxSMS").hide();
	  $("#tweetStat").hide();
	 $("#sendBoxTweet").hide();
	 $("#sendBoxLink").hide();
	 $("#nestAction").html("Send To An Email Address");
	 $("#nestEnterIn").hide();
	 $("#sendBox").show();
	 $("#sendBoxName").show();
	 $("#sendBoxEmail").show();
	 $("#sendEdit-on").show();
	 $("#sendEdit").hide();
	 });
	 
// send SMS	 
	 $("#broadSms").mouseover(function(){
	 $("#broadType").html("Send It Through SMS");
	 });
	 $("#broadSms").mouseout(function(){
	 $("#broadType").html("Choose a Broadcast Type");
	 });
	 $("#broadSms").click(function(){
    $("#count").hide(); 
	 $("#tagBox").hide();
	  $("#tweetStat").hide();
	 $("#broadTools").hide();
	 $("#save2").show();
	 $("#sendBoxTweet").hide();
	 $("#sendBoxEmail").hide();
	 $("#sendBoxLink").hide();
	 
	 $("#nestAction").html("Send It Through SMS");
	 $("#nestEnterIn").hide();
	 $("#sendBox").show();
	 $("#sendBoxSMS").show();
	 $("#sendBoxSmsName").show();
	 $("#sendBoxPhone").show();
	 $("#cellDrop").show();
	 $("#sendEdit-on").show();
	 $("#sendEdit").hide();
	 });


// copy Direct Link
	 $("#broadLink").mouseover(function(){
	 $("#broadType").html("Direct Link");
	 });
	 $("#broadLink").mouseout(function(){ 

	 $("#broadType").html("Choose a Broadcast Type");
	 });
	 $("#broadLink").click(function(){
	  $("#count").hide();
	 	 $("#tagBox").hide();
	  $("#tweetStat").hide();
	 $("#broadTools").hide();
	 $("#save2").show();
	 $("#sendBoxLinkName").attr ('value', 'http://nestr.com?i=' +uid);
	 $("#sendBoxTweet").hide();
	 $("#sendBoxEmail").hide();
	 $("#sendBoxSMS").hide();
	 
	 $("#nestAction").html("Direct Link");
	 $("#nestEnterIn").hide();
	 $("#sendBox").show();
	 $("#sendBoxLink").show();
	 $("#sendEdit-on").show();
	 $("#sendEdit").hide();
	 });
	 
	 
// clear the send forms and bring back the post input	 
	 $("#sendEdit-on").click(function(){
	  $("#count").show();
	  $("#tagBox").show();
	  $("#tweetStat").hide();
	 	 $("#sendEdit-on").hide();
	 $("#sendEdit").show();
	 $("#broadTools").show();
	 $("#save2").show();

	    $("#sendBox").hide();
	 	$("#nestEnterIn").show();
		$("#nestAction").html("Add a Short Message to Broadcast");
	});
	

	
	}

function expandText() {	
	$("#textExpand").click(function(){

    $("#openTextBox").slideDown(500);
    $("#clickClose").show();
    $("#textExpand").hide();
    $("#addTextIcon").html("[-]");
});

	$("#clickClose").click(function(){

    $("#openTextBox").slideUp(500);
    $("#textExpand").show();
    $("#clickClose").hide();
    $("#addTextIcon").html("[+]");
});

}
// zip form actions

    function keyUpZip(){
                 
        $("#f-zipForm").keyup(function(event){
      
     if (event.keyCode == 13) {
     $("#castBox").fadeIn(200);  
		  $('#alertBot').hide();
        startZip();
		$("#map1").show();$("#map1b").hide();
		fadeOutIntro();
		
		loadMap2();
		$("#panel").hide();
		
		$("#bigNestBox").hide();
		moveMarker();

            }
        });
		$("#goArrow").click(function(){
		
     $("#castBox").fadeIn(200);
		$('#alertBot').hide();
		$("#broadAdd").hide();
		$("#panelIntro2").fadeOut(200);
			 startZip();
		fadeOutIntro();

		loadMap2();
		$("#panel").hide();
		$("#bigNestBox").hide();
		moveMarker();
	
	});
    }
    
 // city form actions

    function keyUpCity(){
                 
        $("#f-cityForm").keyup(function(event){
      
     if (event.keyCode == 13) { 
      cityHomeLink = 'yes';     
		  $('#alertBot').hide();
      $("#castBox").fadeIn(200);
		     startCity();
		     loadMap2();

    
		$("#map1").show();$("#map1b").hide();
		fadeOutIntro();
		loadMap2();
		$("#panel").hide();
		
		$("#bigNestBox").hide();
		moveMarker();

            }
        });
        
		$("#goArrowCity").click(function(){
		  
		     startCity();
		     loadMap2();
     $("#castBox").fadeIn(200);

		$('#alertBot').hide();
		$("#broadAdd").hide();
		$("#panelIntro2").fadeOut(200);
		fadeOutIntro();
		$("#panel").hide();
		$("#bigNestBox").hide();
		moveMarker();
	
	});
    }   

// mouse click clears the stuff
    function focusZip(){
    
        $("#f-cityForm").focus(function(){
          $("#f-cityForm").attr("value", "");
	

        });

    }

// start the ZIP lookup

    function startZip(){

        $("#nestBox").fadeOut(200);
        zip = $("#f-zipForm").val();


        $("#city").html("<div id='load'></div>").show();
        
        $.getJSON("i-getZip.php", {
            zip: zip
        }, function(j){

            city = j.city;
            state = j.state;
            notice = j.aa;
			      lat = j.lat;
			      lng = j.lng;

            if (notice == 'Enter a Valid Zip Code' | city == null) {

                $("#catBox").hide();
                $("#cityName").html("Oops, Try Again").fadeIn(200);

            }
            else {
                //make the nav turn on

                $("#catBox").hide();
                $("#cityName").html(city + ",  " + state).slideDown("slow");
                $("#t-chooseCat").fadeIn("slow").html(city + ",  " + state).slideDown("slow");
                $("#t-chooseCat").html("Nest In:").slideDown("slow");
                catSelect(zip);
				
				upNest(lat, lng, uid, zip, catid);

            }

        });
		


    } //end start zip

// start the CITY lookup

    function startCity(){

        $("#nestBox").fadeOut(200);
        myCity = $("#f-cityForm").val();


        $("#city").html("<div id='load'></div>").show();
        
        $.getJSON("i-getCity.php", {
            myCity: myCity
        }, function(j){

            city = j.city;
            state = j.state;
            notice = j.aa;
		      	lat = j.lat;
		      	lng = j.lng;
		      	zip2 = j.zip2;
		      	
                $("#catBox").hide();
                $("#cityName").html(city + ",  " + state).slideDown("slow");
                $("#t-chooseCat").fadeIn("slow").html(city + ",  " + state).slideDown("slow");
                $("#t-chooseCat").html("Nest In:").slideDown("slow");
                catSelect(zip2);
            upNest(lat, lng, uid, zip2, catid);
            
            
        });
		


    } //end start zip
    
    
// manage the nav buttons

    function catSelect(zip){
	
//marketplace
          $("#catBox").fadeIn("slow");
          $(".btn_market").click(function(){
        
          $("#alertMe").hide();
          $("#alertMe").fadeIn(800).html('Nesting In: Marketplace');
         //$("#castBox").fadeIn("slow");
          $("#panelIntro2").fadeOut("slow");
          $("#private").hide();
          $(".mainActive").each(function(){
                $(this).removeClass("mainActive");
            });
            
            
          $(".btn_market").addClass("mainActive");
		      $("#map1").show();
		      fadeOutIntro();
          fadeOutReg();
		      $("#catName").html("<strong>Marketplace</strong>");
		    
		   // $("#alertMe").html("<p>You Are Broadcasting in Marketplace</p>");
		
		 
           catid = "3";
           upCat(catid, zip);
            //updateCat();
        });
//opinion
        $(".btn_op").click(function(){
       
     $("#alertMe").hide();
    $("#alertMe").fadeIn(800).html('Nesting In: Opinion');
         $("#castBox").fadeIn("slow");
         $("#panelIntro2").fadeOut("slow");
         $("#private").hide();
        $(".mainActive").each(function(){
                $(this).removeClass("mainActive")
            });
        $(".btn_op").addClass("mainActive");
        $("#map1").show();
        fadeOutIntro();
        fadeOutReg();
		    $("#catName").html("<strong>Opinion</strong>");
		   // $("#alertMe").html("<p>You Are Broadcasting in Opinion</p>");
		
		      catid = "4";
			    upCat(catid, zip);
           
            //updateCat();
        });
		
//meet up
        $(".btn_meet").click(function(){
        $("#alertMe").hide();
       $("#alertMe").fadeIn(800).html('Nesting In: Meet Up');  
         $("#castBox").fadeIn("slow");
         $("#panelIntro2").fadeOut("slow");
         $("#private").hide();
        $(".mainActive").each(function(){
                $(this).removeClass("mainActive")
            });
        $(".btn_meet").addClass("mainActive");
        $("#map1").show();
        fadeOutIntro();
		    fadeOutReg();
		    $("#catName").html("<strong>Meet Up</strong>");
		   // $("#alertMe").html("<p>You Are Broadcasting in Meet Up</p>");
		
			     catid = "1";
			     upCat(catid, zip);
            
            //updateCat();
        });
		
//event
        $(".btn_ev").click(function(){
     $("#alertMe").hide();
     $("#alertMe").fadeIn(800).html('Nesting In: Events'); 
        
         $("#castBox").fadeIn("slow");
         $("#panelIntro2").fadeOut("slow");
         $("#private").hide();
        $(".mainActive").each(function(){
                $(this).removeClass("mainActive")
            });
         $(".btn_ev").addClass("mainActive");
         $("#alert").hide("slow");
         $("#map1").show();
         fadeOutIntro();
         fadeOutReg();
		 $("#catName").html("<strong>Event</strong>");
		// $("#alertMe").html("<p>You Are Broadcasting in Events</p>");
		 
			catid = "2";
			upCat(catid, zip);
            
            //updateCat();		 
        });
    }
	


 //load the start up map
 
     function loadMap1(lat, lng, cent){

            
            if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("mainMap"));
                var center = new GLatLng(lat, lng);
                map.setCenter(center, cent);
                var marker = new GMarker(center, {
                draggable: true
                });
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());
               // map.enableScrollWheelZoom();
                
                map.setMapType(G_NORMAL_MAP);
            }               
     
    }  


//load the regional map

function loadMap2(){

		//$("#castBox").fadeIn(200);
		broadcast();
		 
        $.getJSON("i-getLat.php", { 
            uid: uid
        }, function(j){
            var clickHandler;
            var map;
            var lat2;
            var lng2;
            var locations;
            var bounds;
            
            if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("mainMap"));
				var mapOptions  = {
			
				  googleBarOptions : {
				  style : "new",
				  showOnLoad : true,
				  onSearchCompleteCallback : function() { $("#mapOptions").show();},
				  linkTarget : G_GOOGLEBAR_LINK_TARGET_BLANK
				}   
 
};
                var center = new GLatLng(lat, lng);
                map.setCenter(center, 13);
                var marker = new GMarker(center, {
                    draggable: true
                });
                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());
               // map.enableScrollWheelZoom();
			        	map.enableGoogleBar(); 
				
                
               // map.openInfoWindow(map.getCenter(), document.createTextNode("Move me around"));
            }
            
            map.addOverlay(marker);
            
            clickHandler = GEvent.addListener(marker, "dragend", function(point){
                setNewMarker(point);
                
            });
             
            function processLocations(){
                var marker = new GMarker(new GLatLng(lat, lng));
                map.addOverlay(marker);
                GEvent.addListener(marker, 'click', function(){
                    marker.openInfoWindowHtml('Name: <b>' + post + '</b><br />');
                });
                
            }
            
          
            function setNewMarker(point){
            
                lat2 = point.lat();
                lng2 = point.lng();
				$("#nestBox").fadeOut(200);
				
				//if (cityHomeLink = 'no'){
        //$("#castBox").hide();
        //}
        //else if (cityHomeLink = 'yes'){
        //$("#castBox").fadeIn(200);
        //}
				
				$("#broadAdd").hide();
				$("#broadAdd2").hide();
				$("#bigNestBox").hide();
				  closeMarker();
                
                
                
//update lat and long in db
                
                $.post("i-upMap.php", {
                    lat2: lat2,
                    lng2: lng2,
                    uid: uid
                }, function(data){
                    //$("#alertMe").html('<p>Marker Updated</p> ').fadeIn(100);
                    
                });
                
            }
        }); // end loadMap2
    }

	
// create the nest for a new guest

	function createNest(){
	

	
	$.post("i-postNest.php", {
	
        zip: zip,
        ts: ts,
        uid: uid,
        lat: lat,
		    sid: sid,
		    catid: catid,
        lng: lng
		
        }, function(data){
           
  
        });		
	
	}
	
//update the nest for a new guest
	function upNest(lat, lng, uid, zip, catid){
	postCities(city, state);
	$.post("i-upNest.php", {

        zip: zip,
        ts: ts,
        uid: uid,
        lat: lat,
	    	catid: catid,
        lng: lng
		
        }, function(data){
            
  
        });	
        
  $.post("i-upNest-City.php", {
			
				city: city,
				state: state,
				zip: zip,
				uid: uid

			}, function(data){
				
			});	
	
	}

//update the category
	function upCat(catid, zip){
	
	$.post("i-upCat.php", {
	
        uid: uid,
		catid: catid,
		zip: zip
		
        }, function(data){
             
  
        });		
	
	}

	function countit(){
		//counter
		$("#nestEnterIn").charCounter(115, {
			container: "#count"
		});
		
	}
	
	function sendText(){
		//send the email
		$("a#goArrowEmail").click(function(){
			//$("#updateMeEmail").html("Sending....").show();
		  QuietSave();
			nestEnterIn = $("#nestEnterIn").val();
			Emailname = $("#sendEmailName").val();
			Nemail = $("#sendEmail").val();	
			
			emailMe = nestEnterIn + ' --> View The Map Here: http://nestr.com/?i=' + uid;
			nakedEmail = nestEnterIn;
		
			$.post("i-emailNow.php", {
				Emailname: Emailname,
				uid: uid,
				nakedEmail: nakedEmail,
				emailMe: emailMe,
				Nemail: Nemail
			   
			}, function(data){
			
				$("#updateMeEmail").html(data).fadeIn(100);
			});
			
		});
	
		//send the SMS
		
		$("a#goArrowSMS").click(function(){
         QuietSave();
			$("#updateMeSMS").html("Sending....").show();
			nestEnterIn = $("#nestEnterIn").val();
			SMSname = $("#sendBoxSmsName").val();
			phone = $("#sendBoxPhone").val();
			cellDrop = $("#cellDrop").val();
			smsMe = nestEnterIn + ' http://nestr.com/n.php?i=' + uid;
			nakedSMS = nestEnterIn;
			$.post("i-smsNow.php", {
				SMSname: SMSname,
				uid: uid,
				nakedSMS: nakedSMS,
				smsMe: smsMe,
				phone: phone,
				cellDrop: cellDrop
			}, function(data){
				$("#updateMeSMS").html(data).fadeIn(100);
			});
			
		});
		
		
		//send the Tweet
		
		$("a#goArrowTwit").click(function(){
		  QuietSave();
			nestEnterIn = $("#nestEnterIn").val();
			pTwit = $("#pTwit").val();
			uTwit = $("#uTwit").val();
			tweetMe = nestEnterIn + ' http://nestr.com?i=' + uid;
			nakedTweet = nestEnterIn;
			$.post("i-tweetNow.php", {
			
				pTwit: pTwit,
				uTwit: uTwit,
				tweetMe: tweetMe,
				nakedTweet: nakedTweet,
				uid: uid
			
			}, function(data){
				$("#tweetStat").html(data).fadeIn(100);
			});
			 QuietSave();
		}); 
		

		saveMe();

		
	}

  function saveMe(){
  
  	 $("#save2").mouseover(function(){
	 $("#broadType").html("Save Nest - Make Public or Private");
	 });
	 $("#save2").mouseout(function(){
	 $("#broadType").html("Choose a Broadcast Type");
	 });
		//save and update the nest AGAIN #2
		$("#save2").click(function(){ 
		 privateSave(zip);
		$("#nestBox").fadeOut(200);
		$("#bigNestBox").fadeOut(200);
		 $("#broadAdd").fadeOut(200);
		  $("#private").fadeIn(200);
		   $("#broadClose7").click(function(){

		    $("#broadAdd").show();
        $("#broadAdd7").fadeOut(200);
        $("#private").fadeOut(200);
        $("#nestBox").fadeIn(200);
        
    });

		});
		

		$("#cancel3").click(function(){
			$("#bigNestBox").slideUp(500);
			$("#broadAdd2").fadeOut(200);
			$("#broadAdd").fadeIn(200);
			
		});	
 }
// manage the alertbox


   function moveMarker(){
                
  $("#alertMe").fadeIn(50);
  //$("#alertMe").animate({height: "50px", borderBottom:'3px solid #CCC'}, 300);
  $("#alertMe").show().html("<div id='alertBotTxt'>You Can Move the Red Marker. Double Click To Zoom</div>");
  
} 

   function closeMarker(){
                
 $("#alertMe").hide();
   //$('#alertMe').animate({height: "0px", borderBottom:'0px'},300);
   $("#alertMe").fadeIn(500).html('Marker Updated');

} 
	
   function alertBot(category){ 
   $('#alertMe').hide();                                
   $("#alertBot").show().html(category);
   $("#alertBot").delay(2000,function(){
      $("#alertBot").show().html(category);
      $("#alertBot").fadeOut(770);
    	   });
    
}

//get the cities then add this to the city DIV, bro

function postCities(city, state){



}


function getTags(){


var cityHomeLink = 'no';
			$.getJSON("i-getTag2.php",
			function(data12){
				
        for (var i=0; i < data12.length; i++){
					var dataRow12 = data12[i]['tags']
					$("<li><a href='#Cities' id='"+dataRow12+"'>"+dataRow12+"</a></li>").appendTo('ul#TagList');
				                 
				}
				
					$("UL#TagList A").click(function(){
					
				   $("#browseIt").show();    
        
				   $('#searchLoader').show();  
				   $('#keyAlertBox').hide();
				   $("ul#CityNest").fadeOut(50);
				   $("ul#CityNest").html('Loading');
				   $("ul#CityNest").html('');
				        var myCityt = $(this).attr('id');
				        getCityNestsTags(myCityt);
                            
                  		});	
				
		
			});

} 

function getCities(){

var cityHomeLink = 'no';
			$.getJSON("i-getCities.php",
			function(data){
				
        for (var i=0; i < data.length; i++){
					var dataRow = data[i]['city2']+', '+data[i]['state2']
					var zipIDD = data[i]['zipID2'];
					var zipReal = data[i]['zipReal']; 
					$("<li><a href='#Cities' id='"+dataRow+"'>"+dataRow+"</a></li>").appendTo('ul#CityList');
					         
                          
				}
				
				   $("UL#CityList A").click(function(){
				   
				
				   $('#searchLoader').show();  
				   $('#keyAlertBox').hide();
				  $("ul#CityNest").fadeOut(50);
				   $("ul#CityNest").html('Loading');
				   $("ul#CityNest").html('');
				        var myCity = $(this).attr('id');
				        //alert(myCity);
				        getCityNests(myCity);

                  		});			
			});

} 
 
function getCityNests(nn){
        
        $.getJSON("i-getCityNests.php", {      
            nn: nn
        }, function(data1){

				  $('#searchLoader').hide(); 
        for (var i=0; i < 7; i++){
					var postCN = data1[i]['postCN'];
					var uidCN = data1[i]['uidCN'];
					var tsNoww = data1[i]['tsNow'];
					var cityCN = data1[i]['cityCN'];
          var stateCN = data1[i]['stateCN'];
          var zipCN = data1[i]['zipCN'];
           if ( postCN == 'Nothing Here' ){$('').appendTo('ul#CityNest') } else { 
        
                                                
                                                                                      
					$("ul#CityNest").fadeIn(400);
					$("<li id='cityMe'><div id='cityMeBox'><a  title='Short title' href='http://nestr.com/n.php?i="+uidCN+"'  id='"+uidCN+"'>"+postCN+"</a></div></li>").appendTo('ul#CityNest');
					$("<li id='cityMe2'><div id='cityMeBox2'>Posted: <abbr class='timeago' title='"+tsNoww+"'>July 17, 2008</abbr></div><div id='nestLocal'>"+cityCN+", "+stateCN+" ("+zipCN+")</div></li>").appendTo('ul#CityNest');

 $('abbr[class*=timeago]').timeago(); 
 
}              
				}
               				
			});

}
function getCityNestsTags(nnt){
            
        $.getJSON("i-getCityNestsTags.php", {      
            nnt: nnt
        }, function(data1t){

				  $('#searchLoader').hide(); 
        for (var i=0; i < 7; i++){
					var postCN = data1t[i]['postCN'];
					var uidCN = data1t[i]['uidCN'];
					var tsNoww = data1t[i]['tsNow'];
					var cityCN = data1t[i]['cityCN'];
          var stateCN = data1t[i]['stateCN'];
          var zipCN = data1t[i]['zipCN'];
           if ( postCN == 'Nothing Here' ){$('').appendTo('ul#CityNest') } else { 
        
                                                
                                                                                      
					$("ul#CityNest").fadeIn(400);
					$("<li id='cityMe'><div id='cityMeBox'><a  title='Short title' href='http://nestr.com/n.php?i="+uidCN+"'  id='"+uidCN+"'>"+postCN+"</a></div></li>").appendTo('ul#CityNest');
					$("<li id='cityMe2'><div id='cityMeBox2'>Posted: <abbr class='timeago' title='"+tsNoww+"'>July 17, 2008</abbr></div><div id='nestLocal'>"+cityCN+", "+stateCN+" ("+zipCN+")</div></li>").appendTo('ul#CityNest');

 $('abbr[class*=timeago]').timeago(); 
}              
				}
               				
			});

}

function getALLCityNests(nu){

    
        $.getJSON("i-getALLCityNests.php?jsoncallback=?", function(data2){

        for (var i=0; i < nu; i++){
					var postCN2 = data2[i]['postCN2'];
					var uidCN2 = data2[i]['uidCN2'];
          var tsNow2 = data2[i]['tsNow2'];
          var cityCN2 = data2[i]['cityCN2'];
          var stateCN2 = data2[i]['stateCN2'];  
          var zipCN2 = data2[i]['zipCN2'];
					if ( postCN2 == 'Nothing Here' ){$('').appendTo('ul#CityNest') } else {
				
          $('abbr[class*=timeago]').timeago(); 
                                                                                       
					$("ul#CityNest").fadeIn(400);
					$("<li id='cityMe'><div id='cityMeBox'><a href='http://nestr.com/n.php?i="+uidCN2+"' >"+postCN2+"</a></div></li>").appendTo('ul#CityNest');
				  $("<li id='cityMe2'><div id='cityMeBox2'>Posted: <abbr class='timeago' title='"+tsNow2+"'>July 17, 2008</abbr></div><div id='nestLocal'>"+cityCN2+", "+stateCN2+" ("+zipCN2+")</div></li>").appendTo('ul#CityNest');
 $('abbr[class*=timeago]').timeago(); 
           
 
}
}				
			
      				
			}); 

}

function privateSave(){


   $("#privSaveMe").click(function(){
      $("#private").fadeOut(200);
      $("#nestBox").show();
      $("#broadAdd").show();
      myCity = $("#f-cityForm").val();
      nestEnterIn = $("#nestEnterIn").val();
        if (nestEnterIn == false) {
        
         $("#saveStat2").show().html('Add a Message');
				   $("#saveStat2").delay(2000,function(){
      
      $("#saveStat2").hide();
      
      }); } else {
      privEmail = $("#privEmail INPUT").val();
			tagEnterIn = $("#tagEnterIn").val();
			moreText = $("#markItUp").val();
			privCKprivate = $("#privCKprivate input[name='option_layout']:checked").val();
		

			$.post("i-saveAll.php", {
			
				tagEnterIn: tagEnterIn,
				uid: uid,
				privCKprivate: privCKprivate,
				nestEnterIn: nestEnterIn,
				moreText: moreText,
				privEmail: privEmail,
				sid: sid,
				catid: catid
			
			}, function(data){
				//$("#saveStat2").html(data).fadeIn(100).fadeOut(3000);
				   $("#saveStat2").show().html(data);
				   $("#saveStat2").delay(2000,function(){
      
      $("#saveStat2").hide();
    	   });
				
			});      
  }
  });

}

function QuietSave(){


      myCity = $("#f-cityForm").val();
      nestEnterIn = $("#nestEnterIn").val();
        if (nestEnterIn == false) {
        $("#saveStat2").show().html('Add a Message');
				   $("#saveStat2").delay(2000,function(){
      
      $("#saveStat2").hide();
        
        });} else {
      privEmail = $("#privEmail INPUT").val();
			tagEnterIn = $("#tagEnterIn").val();
			moreText = $("#openTextBox TEXTAREA").val();
			privCKprivate = $("#privCKprivate input[name='option_layout']:checked").val();
		

			$.post("i-saveAll.php", {
			
				tagEnterIn: tagEnterIn,
				uid: uid,
				privCKprivate: privCKprivate,
				nestEnterIn: nestEnterIn,
				moreText: moreText,
				privEmail: privEmail,
				sid: sid,
				catid: catid
			
			}, function(data){
				//$("#saveStat2").html(data).fadeIn(100).fadeOut(3000);

				
			});      
  
}

}

function bigSave(){


   $("#save").click(function(){
      $("#private").fadeOut(200);
      
      $("#bigNestBox").hide();
      $("#nestBox").show();
      $("#broadAdd").show();
      nestEnterIn = $("#nestEnterIn").val();
      if (nestEnterIn == false) {
      $("#saveStat2").show().html('Add a Message');
				   $("#saveStat2").delay(2000,function(){
      
      $("#saveStat2").hide();
      
     }); } else {
      privEmail = $("#privEmail INPUT").val();
			tagEnterIn = $("#tagEnterIn").val();
			moreText = $("#openTextBox TEXTAREA").val();
			privCKprivate = $("#privCKprivate input[name='option_layout']:checked").val();
       
			
			$.post("i-saveAll.php", {
			
				tagEnterIn: tagEnterIn,
				uid: uid,
				privCKprivate: privCKprivate,
				nestEnterIn: nestEnterIn,
				moreText: moreText,
				privEmail: privEmail,
				sid: sid,
				catid: catid
			
			}, function(data){
				//$("#saveStat2").html(data).fadeIn(100).fadeOut(3000);
				   $("#saveStat2").show().html(data);
				   $("#saveStat2").delay(2000,function(){
      
      //$("#saveStat2").fadeOut(1000);
    	   });
				
			});      
  }
  });
  


}
function feedback(){

  $("#feedback").click(function(){
  $("#broadCloseVid").hide();
     $("#lightbox").fadeIn(200);
     $("#centerMe").fadeIn(200);
     $("#feedbackBox").fadeIn(200); 
    });
    
    
     $("#broadClose8").click(function(){
     $("#lightbox").fadeOut(200);
     $("#centerMe").fadeOut(200);
     $("#feedbackBox").fadeOut(200); 
    
    });
    
     $("#sendEmail2").click(function(){
                                           
     feedName = $("#feed1").val();
     feedComment = $("#feed2").val();
     $.post("feedback.php", {
                                           	
         feedName: feedName,
         feedComment: feedComment
                          	
           }, function(data){
           $("#emailStat").html(data).fadeIn(100).fadeOut(2000);
           });
           });
          
}
function videoMe(){

  $("#videoMe").click(function(){
     $("#broadCloseVid").show();
     $("#lightbox").fadeIn(200);
     $("#centerMe").fadeIn(200);
     $("#videoMeBox").show().load('videoMe.php'); 
     
    });
    
    
     $("#broadCloseVid").click(function(){
     $("#lightbox").fadeOut(200);
     $("#centerMe").fadeOut(200);
     $("#videoMeBox").fadeOut(200); 
    
    });
    
          
}

function keySearch(){

 $("#searchInput").keyup(function(event){
 


   if (event.keyCode == 13) { 

     $('#keyAlertBox').hide();
		  search();
		  
		  }

  });
}

function clickSearch(){

 $('#keyAlertBox').hide();

$("#goSearch").click(function(){

			search();

});			

}

function getAllNests(){

$("#showAllNests").click(function(){

$('ul#CityNest').html('');

 $('#keyAlertBox').hide();

getALLCityNests(7);
	
$('ul#CityNest').fadeIn(400);
 });  



}


function search(){

$('#searchLoader').show();  

$("ul#CityNest").html('');

 var keyword = $("#searchInput").val();
 
   $("ul#CityNest").fadeOut(50);
        $.getJSON("i-searchHome.php?jsoncallback=?", {   
           
            keyword: keyword
            
          }, function(data3){
         
         var keyAlert = data3['keyAlert'];
    
  $('#searchLoader').hide();      
           if (keyAlert ==  'noVal' ) {
                   $('#keyAlertBox').fadeIn(500);
                    $('#keyAlertBox').html('Please Enter a Search Request');
                   
                    }
                    
           if (keyAlert ==  'noRec' ) {
                   $('#keyAlertBox').fadeIn(500);
                    $('#keyAlertBox').html('No Results Found');
                   
                    }
                    	
        for (var i=0; i < 10; i++){
        			
					var postCN3 = data3[i]['postCN3'];
					var uidCN3 = data3[i]['uidCN3'];
					var tsNoww3 = data3[i]['tsNow3'];
					var cityCN3 = data3[i]['cityCN3'];
          			var stateCN3 = data3[i]['stateCN3'];
        		    var zipCN3 = data3[i]['zipCN3'];
           if ( postCN3 == 'Nothing Here' ){$('').appendTo('ul#CityNest') } else { 

                                                                                               
					$("ul#CityNest").show();
				
					$("<li id='cityMe'><div id='cityMeBox'><a href='http://nestr.com/n.php?i="+uidCN3+"' target=_blank id='"+uidCN3+"'>"+postCN3+"</a></div></li>").appendTo('ul#CityNest');
					$("<li id='cityMe2' title='fdsfsd'><div id='cityMeBox2'>Posted: <abbr class='timeago' title='"+tsNoww3+"'>July 17, 2008</abbr></div><div id='nestLocal'>"+cityCN3+", "+stateCN3+" ("+zipCN3+")</div></li>").appendTo('ul#CityNest');


 $('abbr[class*=timeago]').timeago(); 
 

}
				}
				        				
			});


} 

function topSearch(){

        $.getJSON("i-getTopSearch.php?jsoncallback=?", function(data7){

        for (var i=0; i < data7.length; i++){
        
					var kw = data7[i]['kw'];
                                                                                 
					$("<li id='tops'>"+kw+"</li>").appendTo('ul#searches');
				  
}				
 				
			});
	
} 


function minimize(){
       
      $("#minimize").toggle(
                function () {
              
                        $("#mainMapOverlay").animate({height: "304px"}, 1000)
                        $("#minimize").html('Close')
                },
                function () {
                 
                        $("#mainMapOverlay").animate({height: "40px" }, 1000)
                        $("#minimize").html('What is Nestr?')
                }
        );    

}

	
}); //end doc
