jQuery(document).ready(function($) {

	$.ajax({
		type: "GET",
		url: "http://bustrofedon.net/wp-content/themes/bustrofedon-2/js/palabras.xml",
		dataType: "xml",
		success: parseXml
	});

function parseXml(xml) {
	$('.silaba').hover(
		function () {	
			$(this).everyTime(120,function(i) {
				var silaba = $(this).attr('id');
				var c = $(xml).find(silaba).children().length;
				var r = Math.ceil(Math.random() * c);
				var palabraNueva = $(xml).find(silaba).children(':nth-child('+r+')');
				var antes = $(palabraNueva).find("pre").text();
				var desp = $(palabraNueva).find("post").text();
				var color = $.Color([Math.random(),0.6,1.0], 'HSV').toCSS();
				$(this).children('.pre').replaceWith('<div class="pre">&nbsp;<a style="color:' + color + '" href="http://bustrofedon.net/">' + antes + '</a></div>');
				$(this).children('.post').replaceWith('<div class="post"><a style="color:' + color + '" href="http://bustrofedon.net/">' + desp + '</a></div>');
			});
		},
		function () {
			$(this).stopTime();
		}
	);
}

$('.widget .info ul').addClass('invisible').addClass('absolute');

$('.widget').hover(
	function () {
		$(this).children('.info').children().toggleClass('invisible');
	});


$(function(){
    // the height of the content, discluding the header/footer
    var content_height = $(window).height()*.8;
    // the beginning page number to show in the footer
    var page = 1;
    function buildNewsletter(){
        if($('#newsletterContent').contents().length > 0){
            // when we need to add a new page, use a jq object for a template
            // or use a long HTML string, whatever your preference
            $page = $("#page_template").clone().addClass("page");
            

            $('#cuento').append($page);
            page++;

            // here is the columnizer magic
            $('#newsletterContent').columnize({
                columns: 2,
                target: ".page:last",
                overflow: {
                    height: content_height,
                    id: "#newsletterContent",
                    doneFunc: function(){
                        buildNewsletter();
                    }
                }
            });
        }
    }
    buildNewsletter();
    $('#despues').appendTo('#cuento');
});

$('.page:last').addClass('sinborde');

$('.page:first').addClass('sinmargen');

/*
$('.page:first').children('.first').children('p:first').dropJ({
	keepCase:false,
	factor:2,
	clear:false
});
*/

var highestCol = Math.max($('#sidebar').height(),$('#texto').height());
$('.cols').height(highestCol);

});