/**
 * JavaScript scripts set for CMS
 *
 * @copyright Copyright (c) 2009
 * @package   ECTO Framework
 * $Id: public.js 65 2009-10-08 19:47:51Z $
 */

/**
 * Close message
 *
 * @param object obj
 */
function closeMessage(e)
{
    $(e.parentNode.parentNode).animate({
        height:0,
        opacity:0,
        paddingTop:0,
        marginTop:0,
        paddingBottom:0,
        marginBottom:0
    }, 1000);
    $(e.parentNode.parentNode).queue(function(){
        $(this).hide();
        $(this).dequeue();
    });
}

function getMessage(msg, type)
{
    switch(type)
    {
        case 'notice':
            return '<div class="notice">'+ msg +'</div>';
            break;
        case 'ok':
            return '<div class="ok"><div class="fr"><a href="#" onclick="closeMessage(this);return false;">'+ _('close') +'</a></div>'+ msg +'</div>';
            break;
        case 'info':
            return '<div class="info">'+ msg +'</div>';
            break;
        case 'error':
        default:
            return '<div class="error"><div class="fr"><a href="#" onclick="closeMessage(this);return false;">'+ _('close') +'</a></div>'+ msg +'</div>';
    }
}

var project = {
    toggleSearchType : function(e)
    {
        if(e.className == 'searchType')
        {
            e.className = 'searchTypeExtend';
            $('#extendedSearch').slideDown(500);
        }
        else
        {
            e.className = 'searchType';
            $('#extendedSearch').slideUp(500);
        }
    },

    spinerIndex : {},

    startSpiner : function(parent)
    {
        if(this.spinerIndex[parent] === undefined)
            this.spinerIndex[parent] = 0;

        var nextIndex = this.spinerIndex[parent] + 1;

        if(!$(parent +' .catalogItem:eq('+ nextIndex +')').length)
            nextIndex = 0;


        $(parent +' .catalogItem:eq('+ this.spinerIndex[parent] +')').fadeOut(600);
        $(parent +' .catalogItem:eq('+ nextIndex +')').fadeIn(600);

        this.spinerIndex[parent] = nextIndex;

        setTimeout(function(){project.startSpiner(parent);}, 10000);
    },

    changeType : function(e)
    {
        $('select[name="category"] option[value!=""]').remove();
        var html = '';

        if(e.value == '')
        {
            for(var type in categories)
            {
                for(var x in categories[type])
                    html += '<option value="'+ categories[type][x].id +'">'+ categories[type][x].name +'</option>';
            }
        }
        else
        {
            for(var x in categories[e.value])
                html += '<option value="'+ categories[e.value][x].id +'">'+ categories[e.value][x].name +'</option>';
        }
        $('select[name="category"]').append(html);
    }
};