﻿
var fcg = 
{
    // Controls
    controls : [
                    'fcg.areaClubes',
                    'fcg.buscador',
                    'fcg.buscadorInterno',
                    'fcg.calendarioEventos',
                    'fcg.club18',
                    'fcg.dropClubes', 
                    'fcg.destacados',
//                    //'fcg.dropIdioma',
                    'fcg.galeria',
                    'fcg.galeriaPrensa',
                    'fcg.gridResultados',
                    'fcg.gridResultadosGrandPrix',
                    'fcg.gridResultadosCircuito',
                    'fcg.handicap',
                    'fcg.listadoDropDown',
                    'fcg.mapaClubes', 
                    'fcg.menu',  
                    'fcg.panelNavegable',
                    'fcg.pngFix', 
                    'fcg.reloj', 
                    'fcg.rotator',
                    'fcg.solapas'
                ],      
    
    // Lang
    lang : null,
    
    // Url
    url : null,
    
    // Init
    init : function()
    {
        // Load controls
        $.each(this.controls, function(key, control)  
        {
            $('head').append('<script type="text/javascript" src="' +url + '_js/fcg/' + control + '.js"></' + 'script>');
            controlConstructor(control, window, arguments);
        });
    }
};

$(document).ready
(
    function() {
        // Init
        fcg.init();

        // Clima
        $('iframe#climaFrame').attr('src', url + 'clima.aspx');

        $('table').removeAttr('rules');

        // Resize
        resizeContenido();
        resizeBody();
        if ($('h1.homeTit').length > 0) 
        {
            resizeHome();
        }
    }
);

function controlConstructor(control, context /*, args */) 
{  
    var args = Array.prototype.slice.call(arguments).splice(2);  
    var namespaces = control.split(".");  
    var func = namespaces.pop();  
    for(var i = 0; i < namespaces.length; i++) 
    {    
        context = context[namespaces[i]];  
    }  
    return context[func].apply(this, args);
}

function resizeContenido()
{
	var contenidoLeft = $('div.contenidoLeft').height();
    var contenidoRight = $('div.contenidoRight').height(); //600;
    if(contenidoLeft < contenidoRight) $('div.contenidoLeft').height(contenidoRight);
    else $('div.contenidoRight').height(contenidoLeft);
}

function resizeBody()
{
	var alturaWin = $(window).height();
	var alturaDoc = $('div.publicidad').height() + $('div.banner').height() + $('div.menu').height() + $('div.contenidoLeft').height() + $('div.pie').height() + $('div.affinity').height() + 11;
	if(alturaDoc < alturaWin)
    {
        var contenido = alturaWin - ($('div.publicidad').height() + $('div.banner').height() + $('div.menu').height() + $('div.pie').height() + $('div.affinity').height() + 11);
        $('div.contenidoLeft').height(contenido);
        $('div.contenidoRight').height(contenido);
    }
}

function resizeHome()
{
	var alturaTit = $('h1.homeTit').height();
	var alturaCajaSuperior = 0;
	if ($('div.calendario').length > 0) alturaCajaSuperior = $('div.calendario').height();
	else alturaCajaSuperior = $('div.destacado').height();
	var alturaTorneos = $('div.torneos').height();
	var alturaNoticias = $('div.noticias').height();

	if ((alturaTit * 2) + alturaCajaSuperior + alturaTorneos + 16 >= alturaTit + alturaNoticias)
	{
	    $('div.noticias').height(alturaTit + alturaCajaSuperior + alturaTorneos + 17);
	}
	else
	{
	    $('div.torneos').height(alturaNoticias - (alturaTit + alturaCajaSuperior + 17));
	}
}

window.onresize = resizeBody;
