if ($.browser.msie)
{
    if ($.browser.version > 6)
    {
	$(document).ready(init);
    }
}
else
    $(document).ready(init);

function init()
{
	$('div.vota span.star').hover(function () {marca_estrellas(this);},function () {restaura_estrellas(this)});
	round($('.blockblue'));
	round($('.blockgreen'));
	round($('.blockred'));
	round($('.blockyellow'));
	round($('#blockhome > div'));
	$('div.blockyellow table tr:first-child').css('background','none');
	$('div.blockyellow table tr:first-child').css('border','none');
	$('div.blockyellow div.contenido table tr:odd').addClass('par');

	$('div.blockgreen div.conoceme div.left div.datos').prepend('<div style="position: absolute;width: 215px; height: 16px; top: -16px; left: 0; background: url(/images/fondo-datos-top.png) no-repeat top left"></div>');
	$('div.blockgreen div.conoceme div.left div.datos').prepend('<div style="position: absolute;width: 215px; height: 16px; bottom: -16px; left: 0; background: url(/images/fondo-datos-bottom.png) no-repeat top left"></div>');
	$('.block_first').append('<img style="position: absolute;bottom:0;left:0" src="/images/blockf-bg-bottom.png" />');

	$('#submenu.home').prepend('<div style="position: absolute; top: 0; left: 0; width: 17px; height: 66px; background: url(/images/fondo-submenu-home-left.png) no-repeat top left; z-index: 11"></div>');
    $('#submenu.home').prepend('<div style="position: absolute; top: 0; right: 0; width: 17px; height: 66px; background: url(/images/fondo-submenu-home-right.png) no-repeat top left; z-index: 11"></div>');
    $('#submenu.home ul li:not(.active)').prepend('<div style="position: absolute; top: 0; left: 0; width: 11px; height: 57px; background: url(/images/fondo-submenu-home-boton-left.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.home ul li:not(.active)').prepend('<div style="position: absolute; top: 0; right: 0; width: 11px; height: 57px; background: url(/images/fondo-submenu-home-boton-right.png) no-repeat bottom left; z-index: 11"></div>');

    $('#submenu.comp').prepend('<div style="position: absolute; top: 0; left: -1px; width: 17px; height: 80px; background: url(/images/fondo-submenu-comp-left.png) no-repeat top left; z-index: 11"></div>');
    $('#submenu.comp').prepend('<div style="position: absolute; top: 0; right: 0; width: 17px; height: 80px; background: url(/images/fondo-submenu-comp-right.png) no-repeat top left; z-index: 11"></div>');
    $('#submenu.comp ul li:not(.active)').prepend('<div style="position: absolute; top: 0; left: 0; width: 11px; height: 57px; background: url(/images/fondo-submenu-comp-boton-left.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.comp ul li:not(.active)').prepend('<div style="position: absolute; top: 0; right: 0; width: 11px; height: 57px; background: url(/images/fondo-submenu-comp-boton-right.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.comp ul li.active').prepend('<div style="position: absolute; top: 0; left: 0; width: 11px; height: 57px; background: url(/images/fondo-submenu-comp-boton-active-left.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.comp ul li.active').prepend('<div style="position: absolute; top: 0; right: 0; width: 11px; height: 57px; background: url(/images/fondo-submenu-comp-boton-active-right.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.comp').append('<div class="bottom" style="position: absolute; bottom: 0; left: 1px; width: 718px; height: 30px; background: #323D40"></div>');
    $('#submenu.comp .bottom').append('<div style="position: absolute; bottom: 0; left: 10px; width: 698px; height: 30px; background: #323D40 url(/images/submenu-comp-bottom.png) repeat-x top left;"></div>');

    $('#submenu.blue').prepend('<div style="position: absolute; top: 0; left: 0; width: 17px; height: 66px; background: url(/images/fondo-menu-blue-left.gif) no-repeat top left; z-index: 11"></div>');
    $('#submenu.blue').prepend('<div style="position: absolute; top: 0; right: 0; width: 17px; height: 66px; background: url(/images/fondo-menu-blue-right.gif) no-repeat top left; z-index: 11"></div>');
    $('#submenu.blue ul li:not(.active)').prepend('<div style="position: absolute; top: 0; left: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-blue-left.gif) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.blue ul li:not(.active)').prepend('<div style="position: absolute; top: 0; right: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-blue-right.gif) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.blue ul li.active').prepend('<div style="position: absolute; top: 0; left: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-blue-left-active.gif) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.blue ul li.active').prepend('<div style="position: absolute; top: 0; right: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-blue-right-active.gif) no-repeat bottom left; z-index: 11"></div>');

	$('.blockblue > div.titulo').prepend('<div style="position: absolute; top: 0; left: 0; width: 16px; height: 93px; background: url(/images/titulo-blue-left.png) no-repeat top left; z-index: 11"></div>');
	$('.blockblue > div.titulo').prepend('<div style="position: absolute; top: 0; right: 0; width: 16px; height: 93px; background: url(/images/titulo-blue-right.png) no-repeat top left; z-index: 11"></div>');
    $('.blockred > div.titulo').prepend('<div style="position: absolute; top: 0; left: 0; width: 16px; height: 93px; background: url(/images/titulo-red-left.png) no-repeat top left; z-index: 11"></div>');
    $('.blockred > div.titulo').prepend('<div style="position: absolute; top: 0; right: 0; width: 16px; height: 93px; background: url(/images/titulo-red-right.png) no-repeat top left; z-index: 11"></div>');

    $('#submenu.yellow ul li:not(.active)').prepend('<div style="position: absolute; bottom: 1px; left: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-yellow-left.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.yellow ul li:not(.active)').prepend('<div style="position: absolute; bottom: 1px; right: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-yellow-right.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.yellow ul li.active').prepend('<div style="position: absolute; bottom: 1px; left: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-yellow-active-left.png) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.yellow ul li.active').prepend('<div style="position: absolute; bottom: 1px; right: 0; width: 11px; height: 57px; background: url(/images/fondo-boton-yellow-active-right.png) no-repeat bottom left; z-index: 11"></div>');

    $('#submenu.green ul li:not(.active)').prepend('<div style="position: absolute; bottom: 3px; left: 0; width: 9px; height: 47px; background: url(/images/fondo-boton-green-left.gif) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.green ul li:not(.active)').prepend('<div style="position: absolute; bottom: 3px; right: 0; width: 9px; height: 47px; background: url(/images/fondo-boton-green-right.gif) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.green ul li.active').prepend('<div style="position: absolute; bottom: 3px; left: 0; width: 9px; height: 47px; background: url(/images/fondo-boton-green-active-left.gif) no-repeat bottom left; z-index: 11"></div>');
    $('#submenu.green ul li.active').prepend('<div style="position: absolute; bottom: 3px; right: 0; width: 9px; height: 47px; background: url(/images/fondo-boton-green-active-right.gif) no-repeat bottom left; z-index: 11"></div>');

	$('.block_first').append('<img style="position: absolute;bottom:0;left:0" src="/images/blockf-bg-bottom.png" />');

	$('div.bloque-comenta2').append('<div style="position: absolute; width: 680px; height: 30px; left: 0; bottom: 0; background: url(/images/bloque-comenta-bottom.png) no-repeat top left"></div>');

    // ESTRELLAS
    $('.stars').each(function () {
        var point = $(this).attr("puntuacion");
        var ent = 0;
        for (var i = 1; i <= point; i++)
        {
            $(this).append('<img src="/images/star-marked.gif" />');
            ent = i;
        }
        if (ent != point)
        {
            $(this).append('<img src="/images/star-half.gif" />');
            for (var i = ent + 1; i < 5; i++)
                $(this).append('<img src="/images/star.gif" />');
        }
        else
            for (var i = ent; i < 5; i++)
                $(this).append('<img src="/images/star.gif" />');
    });
    $('div.vota span.star').each(function () {
        var point = parseFloat($(this).parent().attr("puntuacion"));
		if (point >= $(this).attr('valor'))
		{
			$(this).css('background','url("/images/star-marked.gif")');
		}
		if (point < $(this).attr('valor') && point > $(this).prev('span.star').attr('valor'))
		{
			$(this).css('background','url("/images/star-half.gif")');
		}
    });

	playoffs();
	ajustarVideo();
	fixImagen();

	var ntickers = $('#blockhome div.comp_escolares div.bajo span.titulo').size();
    if (ntickers > 1) {
        setInterval("showTicker()",5000);
    }
}

function round(elem)
{
    elem.append('<div style="position:absolute; top:0; left:0; width:9px; height:11px; background:url(/images/corner-tl.png) no-repeat top left;"></div>');
    elem.append('<div style="position:absolute; top:0; right:0; width:9px; height:11px; background:url(/images/corner-tr.png) no-repeat top left;"></div>');
    elem.append('<div style="position:absolute; bottom:0; left:0; width:9px; height:11px; background:url(/images/corner-bl.png) no-repeat top left;"></div>');
    elem.append('<div style="position:absolute; bottom:0; right:0; width:9px; height:11px; background:url(/images/corner-br.png) no-repeat top left;"></div>');
}

function marca_estrellas(star)
{
	$(star).css('background','url("/images/star-marked.gif")');
	$(star).prevAll('span.star').css('background','url("/images/star-marked.gif")');
	$(star).nextAll('span.star').css('background','url("/images/star.gif")');
}

function restaura_estrellas(star)
{
    $('div.vota span.star').each(function () {
        var point = parseFloat($(this).parent().attr("puntuacion"));
		if (point >= $(this).attr('valor'))
		{
			$(this).css('background','url("/images/star-marked.gif")');
		}
		else if (point < $(this).attr('valor') && point > $(this).prev('span.star').attr('valor'))
		{
			$(this).css('background','url("/images/star-half.gif")');
		}
		else
		{
			$(this).css('background','url("/images/star.gif")');
		}
    });
}

function playoffs()
{
	if (!$('div.scroll-playoffs').is('div')) return;
	var cols = $('div.scroll-playoffs .columna').size();
    $('div.scroll-playoffs > div.playoffs').width((cols*138)+'px');
    $('div.scroll-playoffs > div.playoffs-cuartos').width((cols*170)+'px');
	var i = 0;
	var n = 0;

    if ($('div.scroll-playoffs > div').is('.playoffs')) {
        var fondos = {
            "0":"url(/images/comp_esc/partido-blue.png)",
            "1":"url(/images/comp_esc/partido-green.png)",
            "2":"url(/images/comp_esc/partido-orange.png)"
        };
        var partido_final = "url(/images/comp_esc/partido-final.png)";
        var partido_ganador = "url(/images/comp_esc/partido-ganador.png)";
    }
    if ($('div.scroll-playoffs > div').is('.playoffs-cuartos')) {
        var fondos = {
            "0":"url(/images/comp_esc/partido-blue-w.png)",
            "1":"url(/images/comp_esc/partido-green-w.png)",
            "2":"url(/images/comp_esc/partido-orange-w.png)"
        };
        var partido_final = "url(/images/comp_esc/partido-final-w.png)";
        var partido_ganador = "url(/images/comp_esc/partido-ganador-w.png)";
    }
	var color = {
		"0":"#0182AB",
		"1":"#82A00A",
		"2":"#CB8622"
	};

	var ncol = 0;
	$('div.scroll-playoffs div.columna').each(function () {
		$(this).find('.partido').each(function () {
			var margin = i*71;
			$(this).css('margin-top',margin+'px');
			$(this).css('background-image',fondos[ncol]);
			$(this).find('a.info').css('color',color[ncol]);
			$(this).find('span.v').each(function() {
				$(this).prev('span.g').css('right','25px');
				$(this).prev('span.g').css('border-left','#2E393C solid 2px');
			});
		});
		$(this).find('p.titulo').css('color',color[ncol]);
		n++;
		i = Math.pow(2,n) - 1;
		var color_borde = color[ncol];
		if (ncol == 2) ncol = 0;
		else ncol++;

		var mtop = $(this).find('.partido:first').css('margin-top');
		mtop = mtop.replace('px','');
		var tamano_borde = parseInt(mtop);
		tamano_borde += 71;
		mtop = mtop / 2;
		$(this).find('.partido:first').css('margin-top','0px');
		$(this).find('.partido:first').css('padding-top',(50+mtop)+'px');

		$(this).find('.partido:even').each(function () {
			$(this).find('p.e1').append('<div style="position: absolute; top: 21px; right: -7px; width: 3px; height:'+tamano_borde+'px; background-color: '+color_borde+';"></div>');
		});
	});

	var final = $('div.scroll-playoffs div.columna:last').attr('final');
	if ( final == 'campeon')
	{
		var mfinal = $('div.scroll-playoffs div.columna:last').prev('.columna').find('.partido:first').css('padding-top');
		$('div.scroll-playoffs div.columna:last').prev('.columna').find('.partido:first').css('background-image',partido_final);
		$('div.scroll-playoffs div.columna:last').prev('.columna').find('.partido a.info').css('color','#9541AB');
		$('div.scroll-playoffs div.columna:last').prev('.columna').find('p.titulo').css('color','#9541AB');
		mfinal = mfinal.replace('px','');
		$('div.scroll-playoffs div.columna:last .partido:first').css('margin-top',(mfinal-38)+'px').css('padding-top','0');;
		$('div.scroll-playoffs div.columna:last .partido:first').css('background-image',partido_ganador);
		$('div.scroll-playoffs div.columna:last .partido:first .e1').css('padding-top','52px');

		$('div.scroll-playoffs div.columna:last').prev('.columna').find('p.e1 div').remove();
		$('div.scroll-playoffs div.columna:last').find('p.e1 div').remove();
		$('div.scroll-playoffs div.columna:last a.info').css('color','#cf4323');
	}
	else if (final == 'final')
	{
		$('div.scroll-playoffs div.columna:last').find('.partido:first').css('background-image',partido_final);
		$('div.scroll-playoffs div.columna:last').find('.partido a.info').css('color','#9541AB');
		$('div.scroll-playoffs div.columna:last').find('p.titulo').css('color','#9541AB');
		$('div.scroll-playoffs div.columna:last').find('p.e1 div').remove();
	}
}

function ajustarVideo()
{
	$('div.conoceme div.video object').attr('width','215');
	$('div.conoceme div.video object').attr('height','165');
	$('div.conoceme div.video embed').attr('width','215');
	$('div.conoceme div.video embed').attr('height','165');

	$('div.blockblue div.imagen object').attr('width','270');
	$('div.blockblue div.imagen object').attr('height','230');

	$('div.blockblue div.imagen embed').attr('width','270');
	$('div.blockblue div.imagen embed').attr('height','230');

    $('div.blockblue div.pelis div.imagen object').attr('width','180');
    $('div.blockblue div.pelis div.imagen object').attr('height','170');

    $('div.blockblue div.pelis div.imagen embed').attr('width','180');
    $('div.blockblue div.pelis div.imagen embed').attr('height','170');
}

function fixImagen()
{
	$('div.blockgreen div.conoceme div.left div.imagen').height($('div.blockgreen div.conoceme div.left div.imagen img').height());
}

function showTicker()
{
    var last = $('#blockhome div.comp_escolares div.bajo span:visible:last');
    if (last.next().is("span")) var haymas = true;
    else var haymas = false;
    $('#blockhome div.comp_escolares div.bajo span:visible:first').fadeOut("normal");
    $('#blockhome div.comp_escolares div.bajo span:visible:first').next().fadeOut("normal", function () {
        if (haymas) {
            last.next().fadeIn();
            last.next().next().fadeIn();
        }
        else {
            var first = $('#blockhome div.comp_escolares div.bajo span:first');
            first.fadeIn();
            first.next().fadeIn();
        }
    });
}