var tp = 1;

var $j = jQuery.noConflict();

$j(document).ready(function() {
               $j('#more_tweets').click(function() {
                    $j.ajax({
   	                 	type: "GET",
						dataType: "html",
	                    url: "/wp-content/themes/fede/twitterposts.php",
	                    data: "tp="+(++tp),
						error: function(msg,a,b,c,d) {
							alert("error:"+msg);
							alert(a + "\n" + b + "\n" + c + "\n" + d + "\n")
						},
	                    success: function(msg){
	                    	$j('#twitter_data').append(msg);
	                    }
                    });
               });
           });


function subscribe() {
	$j.ajax({
     	type: "GET",
		dataType: "html",
        url: "/newsletter.php",
        data: "email="+$j('#email').val(),
		error: function(msg,a,b,c,d) {
			alert("error:"+msg);
			alert(a + "\n" + b + "\n" + c + "\n" + d + "\n")
		},
        success: function(msg){
        	$j('#newsletterForm').html(msg);
        }
    });	
}
function unsubscribe() {
	$j.ajax({
     	type: "GET",
		dataType: "html",
        url: "/newsletter.php",
        data: "email="+$j('#email').val()+"&accion=unsubscribe",
		error: function(msg,a,b,c,d) {
			alert("error:"+msg);
			alert(a + "\n" + b + "\n" + c + "\n" + d + "\n")
		},
        success: function(msg){
        	$j('#newsletterForm').html(msg);
        }
    });	
}

function changeIdioma(lang) {
	document.location = changeWindowLanguaje(document.location.href, lang);
}

function changeWindowLanguaje(url, idioma) {
	str = url;
	
	re = /\?lang=..\&/g; 
	str = str.replace(re,"?");

	re = /(\?l|\&l)ang=../g;
	str = str.replace(re, "");

	if (str.indexOf('?')>0) 
		str = str + "&lang=" + idioma;
	else
		str = str + "?lang=" + idioma;
	return str;
}

function moreTweets() {
	tp++;
	jQuery.ajax({
	   type: "POST",
	   url: "twitterposts.php",
	   data: "tp="+tp,
	   success: function(msg){
		alert("!");
	    jQuery("#redesSociales").append(html);
	   }
	 });
}
