$(document).ready(function(){

	
	JT_init();
	
	$('#social a').each(function () {
	    $('<div class="fader" />').css('opacity', 0).prependTo(this);
	  }).hover(function () {
	    $('img', this).stop().animate({
		marginLeft : 5
	    }, 250);
	    $('.fader', this).stop().animate({
	      opacity : 0.15
	    });
	  }, function () {
	    $('img', this).stop().animate({
	      marginLeft : 10
	    }, 250);
	    
	    $('.fader', this).stop().animate({
	      opacity : 0
	    });
	  }).find('img').css('marginLeft', 10);
	  
  	$('#about a').each(function () {
	    $('<div class="fader" />').css('opacity', 0).prependTo(this);
	  }).hover(function () {
	    $('img', this).stop().animate({
	      marginLeft : 5
	    }, 250);
	    $('.fader', this).stop().animate({
	      opacity : 0.15
	    });
	  }, function () {
	    $('img', this).stop().animate({
	      marginLeft : 10
	    }, 250);
	    
	    $('.fader', this).stop().animate({
	      opacity : 0
	    });
	  }).find('img').css('marginLeft', 10);

});
	
function validateSubmitFeedback(){

	if($("#feedback").val()==""){
		alert("Please, enter your feedback.");
		return false;
	}
	return true;
	
}

function follow(follower,following,following_id,type,elem){

	var i=content.document.createElement('iframe');
	i.setAttribute('name', 'sourcecow');
	i.setAttribute('id', 'sourcecow');
	i.setAttribute('src', $("#site").val()+'auto/iframe.php?follower='+follower+'&following='+following+'&type='+type);
	i.setAttribute('style', 'z-index: 2147483647; position: fixed;left:10px;top:10px;width:350px;height: 520px;border:none;');
	var iframe=content.document.body.appendChild(i);
	iframe.addEventListener("load", first_load, false); 

	if(type=="User")$.post("/ajax/follow.php", { id: following_id,type: type } );
	else $.post("/ajax/follow.php", { id: following_id,type: type,listname:following } );
	$(elem).parent().html("You are following them");

}

function source_close(){ 
    var f = content.document.getElementById('sourcecow');
    f.style.display = 'none'; 
    f.parentNode.removeChild(f);
}
function pre_source_close(){ 
	setTimeout(source_close, 2000);
}

function first_load(){ 
	var f = content.document.getElementById('sourcecow');
	f.removeEventListener("load",first_load,false);
	f.addEventListener("load", pre_source_close, false); 
}
function showJoinBox(){
	
	$("#joinBox").modal({
		overlay:80,
		overlayCss: {backgroundColor:"#E1EBD3"},
		containerCss:{
			backgroundColor:"#fff",
			borderColor:"#DDDDDD",
			height:300,
			padding:"12px",
			width:300
		},
		overlayClose:true
	});
	
}

function saveJoinInfo(){
	var autoFollow="Yes";
	if(!$('#autoFollow').is(':checked'))autoFollow="No";
	$.post("/ajax/preJoin.php", { joinMessage: $("#joinMessage").val(), autoFollow: autoFollow },
		function(data){
			window.location=$("#loginLink").val();
		}
	);

}
function saveWhy(id,following){

	if($("#why_"+id).val()!=""){
		$.post("/ajax/saveWhy.php", { why: $("#why_"+id).val(), how: $("#how_"+id).val(),what: $("#what_"+id).val(),following_id:id,following:following },
			function(data){
				$("#nudge_"+id).show();
			}
		);
	}else{
		alert("Please, fill the why part.");
	}
	
}

function nudge(id,following){

	$.post("/ajax/nudge.php", { following:following },
		function(data){
			$("#nudge_"+id).html("nudged");
		}
	);
}

function showFirstTimeBox(){
	
	$("#firstTimeBox").modal({
		overlay:80,
		overlayCss: {backgroundColor:"#E1EBD3"},
		containerCss:{
			backgroundColor:"#fff",
			borderColor:"#DDDDDD",
			height:300,
			padding:"12px",
			width:300
		},
		overlayClose:true
	});
	
}