//var baseurl = "http://localhost/newElie.im/";
var baseurl = "http://elie.im/";


var myworkemail=  '254,767,411,882,1019,308,170,446,866,996,969,886,958,46,494,28,354,217,5,935:155,659,498,791,955,343,217,400,785,912,936,792,984,65,412,120,332,188,97,978';
var mypersomail= '460,199,177,58,319,1,991,728,60,173,414:443,162,211,122,346,109,950,701,18,196,499';
//var mymobile = '338,79,89,481,704,736,448,903,88,692,480,145,71,311,384,543,169:377,126,121,457,758,725,496,942,120,643,467,168,106,258,438,551,145';
var mymobile = '50,832,10,148,36,909,146,865,565,640,512,323,945,220,483,668,751:25,881,42,188,19,952,165,840,533,691,565,375,924,239,464,687,731';
var myfaxwork = '586,625,301,292,490,207,578,285,461,222,143,686,384,20,50,692,923:609,576,269,268,476,250,626,308,493,233,189,667,429,32,4,643,938';
var myskype = '687,708,189,40,198,829,292,83,368,471:714,678,200,90,181,839,336,54,281,441';
var mygtalk = '750,805,551,501,408,179,963,929,14,862,287,121,500,361,430,707,89,350,429,429:651,839,594,391,491,201,951,964,103,816,351,30,409,264,455,687,119,317,450,448';



function decrypt(str) {
var r = str.split(':');
var crypted = r[0].split(',');
var key     = r[1].split(',');
var clear     = "";
for (i = 0; i < crypted.length; i++)
{
clear += String.fromCharCode(crypted[i] ^ key[i]);
}
return clear;
}

function displayDecrypt(str, id) {
var clear = decrypt(str);
document.getElementById(id).innerHTML = clear;
}

//function displayDecrypt(str, id, todo, idtodo) {
//    var clear = decrypt(str);
//    document.getElementById(id).innerHTML = clear;
//    if(todo == 'mailto'){
//        document.getElementById(idtodo).href = "mailto:"+ clear;
//    }else if(todo == 'tel'){
//        document.getElementById(idtodo).href = "tel:"+ clear;
//    }
//}

function updateShareCounter(id){
$.ajax({
type: "GET",
url: baseurl + "ajax/updateCount.php?id=" + id,
success: function(response){
var test = response.split(",", 2);
var id = "bulle"+test[0];
var count = test[1];
if(count >= 0){
if(count == 0 || count == 1){
$("#"+id).html(count + '<br/>share');
}else {
$("#"+id).html(count + '<br/>shares');
}

} else {
$("#"+id).html('er');
}
}
});
}

function getCount(id){
$.ajax({
type: "GET",
url: baseurl + "ajax/getCount.php?id=" + id,
success: function(response){
var test = response.split(",", 2);
var id = "bulle"+test[0];
var count = test[1];
if(count >= 0){
if(count == 0 || count == 1){
$("#"+id).html(count + '<br/>share');
}else {
$("#"+id).html(count + '<br/>shares');
}

} else {
$("#"+id).html('er');
}
}
});
}

//twitter
(function($) {

$.fn.tweet = function(o){
var s = {
username: ["seaofclouds"],              // [string]   required, unless you want to display our tweets. :) it can be an array, just do ["username1","username2","etc"]
avatar_size: null,                      // [integer]  height and width of avatar if displayed (48px max)
count: 4,                               // [integer]  how many tweets to display?
intro_text: null,                       // [string]   do you want text BEFORE your your tweets?
outro_text: null,                       // [string]   do you want text AFTER your tweets?
join_text:  null,                       // [string]   optional text in between date and tweet, try setting to "auto"
auto_join_text_default: "i said,",      // [string]   auto text for non verb: "i said" bullocks
auto_join_text_ed: "i",                 // [string]   auto text for past tense: "i" surfed
auto_join_text_ing: "i am",             // [string]   auto tense for present tense: "i was" surfing
auto_join_text_reply: "i replied to",   // [string]   auto tense for replies: "i replied to" @someone "with"
auto_join_text_url: "i was looking at", // [string]   auto tense for urls: "i was looking at" http:...
loading_text: null,                     // [string]   optional loading text, displayed while tweets load
query: null                             // [string]   optional search query
};

$.fn.extend({
linkUrl: function() {
var returning = [];
var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
this.each(function() {
returning.push(this.replace(regexp,"<a href=\"$1\">$1</a>"))
});
return $(returning);
},
linkUser: function() {
var returning = [];
var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
this.each(function() {
returning.push(this.replace(regexp,"<a href=\"http://twitter.com/$1\">@$1</a>"))
});
return $(returning);
},
linkHash: function() {
var returning = [];
var regexp = / [\#]+([A-Za-z0-9-_]+)/gi;
this.each(function() {
returning.push(this.replace(regexp, ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all&from='+s.username.join("%2BOR%2B")+'">#$1</a>'))
});
return $(returning);
},
capAwesome: function() {
var returning = [];
this.each(function() {
returning.push(this.replace(/(a|A)wesome/gi, 'AWESOME'))
});
return $(returning);
},
capEpic: function() {
var returning = [];
this.each(function() {
returning.push(this.replace(/(e|E)pic/gi, 'EPIC'))
});
return $(returning);
},
makeHeart: function() {
var returning = [];
this.each(function() {
returning.push(this.replace(/[&lt;]+[3]/gi, "<tt class='heart'>&#x2665;</tt>"))
});
return $(returning);
}
});

function relative_time(time_value) {
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
if(delta < 60) {
return 'less than a minute ago';
} else if(delta < 120) {
return 'about a minute ago';
} else if(delta < (45*60)) {
return (parseInt(delta / 60)).toString() + ' minutes ago';
} else if(delta < (90*60)) {
return 'about an hour ago';
} else if(delta < (24*60*60)) {
return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
} else if(delta < (48*60*60)) {
return '1 day ago';
} else {
return (parseInt(delta / 86400)).toString() + ' days ago';
}
}

if(o) $.extend(s, o);
return this.each(function(){
var list = $('<ul class="tweet_list">').appendTo(this);
var intro = '<p class="tweet_intro">'+s.intro_text+'</p>'
var outro = '<p class="tweet_outro">'+s.outro_text+'</p>'
var loading = $('<p class="loading">'+s.loading_text+'</p>');
if(typeof(s.username) == "string"){
s.username = [s.username];
}
//var query = '';
//if(s.query) {
//query += 'q='+s.query;
//}
//query += '&q=from:'+s.username.join('%20OR%20from:');

var url = 'http://api.twitter.com/1/statuses/user_timeline/elie.json?count=' + s.count + '&callback=?';

//var url = 'http://search.twitter.com/search.json?&'+query+'&rpp='+s.count+'&callback=?';
if (s.loading_text) $(this).append(loading);

$.getJSON(url, function(data){

if (s.loading_text) loading.remove();
if (s.intro_text) list.before(intro);

$.each(data, function(i,item){

// auto join text based on verb tense and content
if (s.join_text == "auto") {
if (item.text.match(/^(@([A-Za-z0-9-_]+)) .*/i)) {
var join_text = s.auto_join_text_reply;
} else if (item.text.match(/(^\w+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+) .*/i)) {
var join_text = s.auto_join_text_url;
} else if (item.text.match(/^((\w+ed)|just) .*/im)) {
var join_text = s.auto_join_text_ed;
} else if (item.text.match(/^(\w*ing) .*/i)) {
var join_text = s.auto_join_text_ing;
} else {
var join_text = s.auto_join_text_default;
}
} else {
var join_text = s.join_text;
};

var join_template = '<span class="tweet_join"> '+join_text+' </span>';
var join = ((s.join_text) ? join_template : ' ')
//var avatar_template = '<a class="tweet_avatar" href="http://twitter.com/'+ item.from_user+'"><img src="img/Social.me/16-16/twitter.png" height="'+s.avatar_size+'" width="'+s.avatar_size+'" alt="'+item.from_user+'\'s avatar" border="0"/></a>';
var avatar_template = '<img src="' + baseurl + 'img/Social.me/24-24/twitter.png" alt="twitter" class=""/>';

var avatar = (s.avatar_size ? avatar_template : '')

var date = '<a href="http://twitter.com/'+ item.user.screen_name +'/statuses/'+item.id+'" title="view tweet on twitter" target="_NEW">'+relative_time(item.created_at)+'</a>';

var text = '<span class="tweet_text">' +$([item.text]).linkUrl().linkUser().linkHash().makeHeart().capAwesome().capEpic()[0]+ '</span>';

// until we create a template option, arrange the items below to alter a tweet's display.
list.append('<li class="social" style="margin-bottom: 20px;">' + avatar + date + join + text + '</li><br/>');


});
if (s.outro_text) list.after(outro);
});

});
};
})(jQuery);
//fin de twitter
