// Self Publicity JS
tweetmeme_style = 'compact';
tweetmeme_source = 'selfpublicity';
tweetmeme_service = 'bit.ly';

$(document).ready(function(){
	 $("#login-page input#email-field").focus();  
	
	/* user profile */
	 $("#report-link").click(function(){
		$(".report-box").modal({
			overlayClose:true
		});
		return false;
	 });
	 
	 $(".recommend-link").click(function(){
		$(".recomment-box").modal({
			overlayClose:true,
			containerCss:{
				height:220,
				width:460
			}
		});
	 });
	  
	 $(".show-recommendations").click(function(){
		$(".recommendation-box").modal({
			overlayClose:true,
			containerCss:{
				height:300,
				width:580
			}
		});
	 });
	 
	  $(".my-recommendations-link").click(function(){
		$.modal('<iframe src="' + baseurl+ '/recommendations' + '" height="280" width="570" style="border:0">',{
			overlayClose:true,
			containerCss:{
				height:300,
				width:580
			}
		});
	 });
	  
	 $("#ask-recommend-request").click(function(){
		$(".recommend-request-box").modal({
			overlayClose:true,
			containerCss:{
				height:120,
				width:400
			}
		});
	 });
	 
	  $("#ask-request-popup").click(function(){
		$("#ask-recommend-popup").modal({
			overlayClose:true,
			containerCss:{
				height:120,
				width:400
			}
		});
	 });
	 
	  $("#add-to-contacts-button").click(function(){
		$(".add-to-contact-box").modal({
			overlayClose:true,
			containerCss:{
				height:140,
				width:400
			}
		});
	 });
 
	  
	 $(".open-publish-box").click(function(){
	 		$("#publish-popup").modal({
				overlayClose:true,
				containerCss:{
					height:100,
					width:400
				}
			});
			
			return false;
	 });
	 
	 $(".open-login-popup").click(function(){
			$("#login-popup").modal({
				overlayClose:true,
				containerCss:{
					height:250,
					width:680
				}
			});
			return false;
	 });
	 
	 $("#cemail-button").click(function(){
		
		var cemail = $("#cemail").val();
		
		jQuery.ajax({
		   type: "POST",
		   url: baseurl+"/ajax/cemailbutton/",
		   dataType: "html", 
		   data: "email="+cemail,
		   success: function(text){}
		});
		
		
     	$("#login-popup").modal({
			overlayClose:true,
			containerCss:{
				height:250,
				width:680
			}
		});
		return false;
	 });
	 
	 /* edit profile */
	 $('#editprofile-form .text').bt({
		  trigger: ['focus', 'blur'],
		  positions: ['right'],
		  fill: 'rgba(0, 0, 0, 1)',
		  strokeWidth: 1,
		  strokeStyle: '#',
		  cssStyles: {color: '#FFF'}
	 });
	 
	 /*gallery */
	 $("a.lightbox").lightBox({
		imageLoading: baseurl+'/images/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: baseurl+'/images/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: baseurl+'/images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: baseurl+'/images/lightbox/lightbox-btn-next.gif',									
	 });
	 
	 $("a#show-import-services").click(function(){
		$("#import-services").slideToggle();
	 });
	 
	 var original_keywords_value = "e.g. designer, plumber";
	 var original_name_value = "e.g. John Doe";
	 
	 $("#keywords-field").focus(function(){
		 var current_keywords_value = $(this).val();
		 var current_name_value = $("#name-field").val();
		 if(current_keywords_value==original_keywords_value) {
		 	$(this).val("");
		 }
		 
		 if(current_name_value==original_name_value){
		 	$("#name-field").val("");
		 }
	 });
	 
	  $("#keywords-field").blur(function(){
		 var current_keywords_value = $(this).val();
		 var current_name_value = $("#name-field").val();
		 if(current_keywords_value=="") {
		 	$(this).val(original_keywords_value);
		 }
		
		 if(current_name_value==""){
			if(current_keywords_value=="") {
		 		$("#name-field").val(original_name_value);
			}
		 }
	 });
	  
	  $("#keywords-field").focus(function(){
		 var current_keywords_value = $(this).val();
		 var current_name_value = $("#name-field").val();
		 if(current_keywords_value==original_keywords_value) {
		 	$(this).val("");
		 }
		 
		 if(current_name_value==original_name_value){
		 	$("#name-field").val("");
		 }
	 });
	 
	  $("#name-field").focus(function(){
		 var current_name_value = $(this).val();
		 var current_keywords_value = $("#keywords-field").val();
		 if(current_keywords_value==original_keywords_value) {
		 	$("#keywords-field").val("");
		 }
		
		 if(current_name_value==original_name_value){
		 	$(this).val("");
		 }
	 });
	  
	  $("#name-field").blur(function(){
		 var current_name_value = $(this).val();
		 var current_keywords_value = $("#keywords-field").val();
		 if(current_keywords_value=="") {
			 if(current_name_value=="") {
		 		$("#keywords-field").val(original_keywords_value);
			 }
		 }
		
		 if(current_name_value==""){
			 if(current_keywords_value==original_keywords_value) {
		 		$(this).val(original_name_value);
			 } else {
				if(current_keywords_value=="") {
					$(this).val(original_name_value);
				} else {
			 		$(this).val("");
				}
			 }
		 }
	 });
});

function contactActions(email)
{
	$("#popup-"+email).modal({
		overlayClose:true,
		containerCss:{
			height:220,
			width:440
		}
	});	
}

function recommendedBox(id)
{
	$("#recommended-"+id).modal({
		overlayClose:true,
		containerCss:{
			height:300,
			width:580
		}
	});	
	return false;
}

function removeContact(email, counter)
{
	jQuery.ajax({
		   type: "POST",
		   url: baseurl+"/ajax/removecontact/",
		   dataType: "html", 
		   data: "email="+email,
		   success: function(text){
				$("#contact-"+counter).remove();
				$("#stats-contact").html(text);
				$.modal.close();
		   }
	});
	return false;
}

function recommendContact(counter)
{
	$("#form-recommend-"+counter).toggle("slow");
	return false;
}

function recommendContactPopup(counter)
{
	$("#popup-"+counter).modal({
		overlayClose:true,
		containerCss:{
			height:250,
			width:380
		}
	});	
	return false;
}

function deleteRecommendations(id)
{
	jQuery.ajax({
	   type: "POST",
	   url: baseurl+"/ajax/deleterecommendation/",
	   dataType: "html", 
	   data: "id="+id,
	   success: function(text){
		  $("#user-"+id).hide("slow");
		  $("#stats-recommend").html(text);
	   }
	});
	return false;
}

function deleteRecommended(id)
{
	jQuery.ajax({
	   type: "POST",
	   url: baseurl+"/ajax/deleterecommended/",
	   dataType: "html", 
	   data: "id="+id,
	   success: function(text){
		  $("#user-"+id).hide("slow");
		  $("#stats-recommended").html(text);
	   }
	});
	return false;
}


function approveRecommendations(uid, type)
{
	jQuery.ajax({
	   type: "POST",
	   url: baseurl+"/ajax/approverecommendation/",
	   dataType: "html", 
	   data: "uid="+uid+"&approve="+type,
	   success: function(text){
		  $("#user-"+uid).hide("slow");
		  $("#stats-new-comments").html(text);
	   }
	});
	return false;
}

function askRecommendationRequest(counter, email, uid, ma)
{
	jQuery.ajax({
	   type: "POST",
	   url: baseurl+"/ajax/askrecommendationrequest/",
	   dataType: "html", 
	   data: "email="+email+"&uid="+uid+"&ma="+ma,
	   success: function(text){
		  $("#ask-request-"+counter).html('<div style="padding-left:10px;">Request sent</div>').removeClass("active-button");
		  $.modal.close();
	   }
	});
	return false;
}

function askUserForRecommendation(uid)
{
	jQuery.ajax({
	   type: "POST",
	   url: baseurl+"/ajax/askforrecommendation/",
	   dataType: "html", 
	   data: "uid="+uid,
	   success: function(text){
		  $("#ask-recommend-request").html("Request sent").removeClass("action-button").addClass("disabled-button");
		  $.modal.close();
	   }
	});
	return false;
}

function addUserToContact(uid)
{
	jQuery.ajax({
	   type: "POST",
	   url: baseurl+"/ajax/addcontact/",
	   dataType: "html", 
	   data: "uid="+uid,
	   success: function(text){
		  $("#add-to-contacts-button").html("In your contacts").removeClass("action-button").addClass("disabled-button");
		  $("#stats-contact").html(text);
		  $.modal.close();
	   }
	});
	return false;	
}


function addComment(uid)
{
	$("#comment-"+uid).modal({
		overlayClose:true,
		containerCss:{
			height:280,
			width:500
		}
	});
	return false;
}

function deleteComment(uid)
{
	$("#delete-"+uid).modal({
		overlayClose:true
		
	});
	return false;
}

function displayManualEmail()
{
   $("#import-services").hide();
   $("#manual-email").show();
   $("#import-email-options").html('<a href="#" id="display-webmail" onclick="displayBulkEmail(); return false;">Add from webmail address book</a>');
}

function displayBulkEmail()
{
   $("#manual-email").hide();
   $("#import-services").show();
   $("#import-email-options").html('<a href="#" id="display-webmail" onclick="displayManualEmail(); return false;">Add individual email</a>');
}




