var execAfterLoading = new Array;

var getDate = function(){
    var meses = new Array('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
    var dias = new Array('Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sábado');
    var fecha = new Date();
    var showDay = dias[fecha.getDay()];
    var showDayNumber = fecha.getDate();
    var showMonth = meses[fecha.getMonth()];
    var showYear = fecha.getFullYear();
    var showHours = (fecha.getHours() < 10 ? ('0' + fecha.getHours().toString()) : fecha.getHours());
    var showMinutes = (fecha.getMinutes() < 10 ? ('0' + fecha.getMinutes().toString()) : fecha.getMinutes());
    var showSeconds = (fecha.getSeconds() < 10 ? ('0' + fecha.getSeconds().toString()) : fecha.getSeconds());
    $('#fecha').html(showDay + ' ' + showDayNumber + ' de ' + showMonth + ' de ' + showYear + ' | ' + showHours + ':' + showMinutes + ':' + showSeconds);
    setTimeout(function(){
        getDate();
    }, 1000);
}

var fixTheIEShit = function(){
    var max = 0;

    var col1 = $(".spc_menu_left");
    var col2 = $(".spc_main_right");
    var col3 = $(".spc_ads_right");

    var col1h = $(col1).height();
    var col2h = $(col2).height();
    var col3h = $(col3).height();

    if (col1h > max) {
        max = col1h;
    }
    if (col2h > max) {
        max = col2h;
    }
    if (col3h > max) {
        max = col3h;
    }

    col1.css("height", max);
    col3.css("height", max);
    col2.css("height", max);

}

execAfterLoading.push(getDate);
execAfterLoading.push(fixTheIEShit);
execAfterLoading.push(random_escort);
$(function() {
	if($('.spc_section').length > 1) {
		$('.spc_main_right .spc_section').each(function() {
			if ($(this).not('.wallpapers').not('.spc_backstage').is(':first-child')) {
				$(this).addClass('minita');
			} else if($(this).is('.spc_backstage')) {
				$(this).addClass('normal2');
			} else if($(this).is('.wallpapers')) {
				$(this).addClass('normal2');
			} else if ($(this).not(':first-child').is('.videos')) {
				$(this).addClass('minita2');
			} else {
				$(this).addClass('normal');
			}
		});
	} else {
		$('.spc_section').addClass('normal2');
		$('.banner').hide();
	}
	var my_height = Math.ceil($('.minita .spc_section_item').length / 5)* $('.minita .spc_section_item').height();
	var new_height = $('.minita :first-child').height()+my_height+$('.spc_section.normal').find('.titlebox').height();
	$('.minita').height(new_height.toString()+'px');
});

function placeVoteSPC(pub){
    $.ajax({
        type: "GET",
        url: "/primavera/content/vote_escort.php",
        data: 'id=' + pub,
        success: function(respuesta){
            if (respuesta != 0) {
                document.getElementById('vote_btn').src = '/navidad/templates/Default/images/publicacion/gracias.jpg';
                if (respuesta == '1') {
                    var votes = parseInt(document.getElementById('voteDisplay').innerHTML, 10) + 1;
                    document.getElementById('voteDisplay').innerHTML = votes;
                }
            }
        }
    });
}

function random_escort(){
    $('.spc_prim_random_escort').click(function(){
        $.ajax({
            type: 'POST',
            url: "/navidad/content/random_escort.php",
            data: 'id=' + $(this).attr('rel'),
            success: function(respuesta){
                if (respuesta.length > 10) {
                    document.location.href = respuesta;
                }
            }
        });
    });
}

function swapGemidosGroup(o, action){

    var image = o.src.split("/");
    var img_name = image[(image.length - 1)];

    var url = "";
    for (var c = 0; c < (image.length - 1); c++) {
        url += image[c] + "/";
    }

    var img_partes = img_name.split(".");

    if (action == 'ovr') {
        var new_img = img_partes[0].substr(0, (img_partes[0].length - 3)) + "." + img_partes[1];
    }
    else {
        var new_img = img_partes[0] + "_ds" + "." + img_partes[1];
    }

    var new_url = url + new_img;
    o.src = new_url;
}

function doThePNGcrapAgain(){
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);

    if ((version >= 5.5) && (document.body.filters)) {
        for (var i = 0; i < document.images.length; i++) {
            var img = document.images[i];
            var imgName = img.src.toUpperCase();
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
                if (img.align == "left") {
                    imgStyle = "float:left;" + imgStyle;
                }
                if (img.align == "right") {
                    imgStyle = "float:right;" + imgStyle;
                }
                if (img.parentElement.href) {
                    imgStyle = "cursor:pointer;" + imgStyle;
                }
                var strNewHTML = "<span " + imgID + imgClass + imgTitle +
                " style=\"" +
                "width:" +
                img.width +
                "px; height:" +
                img.height +
                "px;" +
                imgStyle +
                ";" +
                "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" +
                "(src=\'" +
                img.src +
                "\', sizingMethod='scale');\"></span>";
                img.outerHTML = strNewHTML;
                i = i - 1;
            }
        }
    }
}

