﻿
var controles = 
{
    publico: {},
    generico : {}
};

controles.publico = 
{ 
    // Controls
    controls : [
                    'controles.publico.buscar', 
                    'controles.generico.email',
                    'controles.generico.pngFix',
                    'controles.generico.scroll',
                    'controles.publico.cmsmenu',
                    'controles.publico.contacto',
                    'controles.publico.listaDesplegable',
                    'controles.publico.login',
                    'controles.publico.galeria',
                    'controles.publico.hiddenBreadcrumbs',
                    'controles.publico.noticiasInicio',
                    'controles.publico.rotator'
               ],
    // Lang
    lang : null, 

    // Init
    init : function()
    {        
        // Load controls
        if(this.controls != null)
        {
            $.each(this.controls, function(key, control)  
            {
                $('head').append('<script type="text/javascript" src="' + $('#Root').val() + '_js/controles/' + control + '.js"></' + 'script>');
                libraryConstructor(control, window, arguments);
            });
        } 
    }
};

function randomFromTo(from, to)
{
    return Math.floor(Math.random() * (to - from + 1) + from);
}


$(document).ready
(   
    function()
    {
        // Init
        controles.publico.init();
        //Resize
        resizeContenidos();
        //Imagenes inicio
        //imagesInicio();
        //Sitemap
        $('a.linkSiteMapOpen').click
        (
            function () {
                $('div.mapaBox iframe').attr('src', $('#Root').val() + 'Sitemap.aspx');
                $('div.mapaBox').show();
                $('div.mapaOverlay').show();
            }
	    );
        $('a.linkSiteMapClose').click
        (
            function () {
                $('div.mapaBox iframe').attr('src', '');
                $('div.mapaBox').hide();
                $('div.mapaOverlay').hide();
            }
	    );
    }
);

function libraryConstructor(item, context /*, args */) 
{  
    var args = Array.prototype.slice.call(arguments).splice(2);  
    var namespaces = item.split(".");  
    var func = namespaces.pop();  
    for(var i = 0; i < namespaces.length; i++) 
    {    
        context = context[namespaces[i]];  
    }  
    return context[func].apply(this, args);
}

function resizeContenidos()
{
// 	var contenidoCorto = $('div.contenidoCorto');
//    var seccionesCorto = $('div.seccionesCorto');
//    if(contenidoCorto.length > 0 && seccionesCorto.length > 0)
//    {
//        if(seccionesCorto.height() < contenidoCorto.height())
//        {
//            seccionesCorto.height(contenidoCorto.height());
//        }
//    }
    var windowHeight = $(window).height();
    var topHeight = $('div.mainTop').height();
    var menuHeight = $('div.mainMenu').height();
    var midHeight = $('div.mainMid').height();
    var botHeight = $('div.mainBot').height();
    var restHeight = windowHeight - (topHeight + menuHeight + midHeight + botHeight);
    if(restHeight > 0) $('div.mainBot').height(botHeight + restHeight - 25);
    if($('div.submenu').length > 0)
    {
        $('div.submenu').height($('div.contenido').height());
    }
}

window.onresize = resizeContenidos;

//function imagesInicio()
//{
// 	if($('div.inicio').length > 0)
// 	{
//        $('div.inicio div.superior a:last').css('float', 'right');
//        $('div.inicio div.superior a:last').css('margin-right', '0px');
//    }
//}
