
/**
 * JavaScript scripts set for CMS
 *
 * @copyright Copyright (c) 2009, ecto.lt
 * @author    Benas Valančius <benas@ecto.lt>
 * @package   Framework
 *
 * $Id: public.js 77 2009-10-13 10:21:55Z noen $
 */

/**
 * 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 = {
    toggleYear : function(e)
    {
        if($(e).parent().find('ul').is(':visible'))
        {
            $(e).find('span').text('+');
            $(e).parent().find('ul').slideUp(500);
        }
        else
        {
            $(e).find('span').text('-');
            $(e).parent().find('ul').slideDown(500);
        }
    },

    crossProBanner : function(selector, img, index)
    {
        $('#activeImage').val(index);
        var time = 15;

        $(selector).crossSlide({
            fade: 0.01
        }, [
            {
                src:  img,
                from: 'bottom left',
                to:   'top right',
                time: time
            },
            {
                src:  img,
                from: 'top right',
                to:   'bottom right',
                time: time
            },
            {
                src:  img,
                from: 'bottom right',
                to:   'top left',
                time: time
            },
            {
                src:  img,
                from: 'top left',
                to:   'bottom left',
                time: time
            }
        ]);
    },

    slideBanner : function(selector, images)
    {
        var slideShow = [{
            from : 'bottom left',
            to   : 'top right'
        },
        {
            from : 'top right',
            to   : 'bottom right'
        },
        {
            from : 'bottom right',
            to   : 'top left'
        },
        {
            from : 'top left',
            to   : 'bottom left'
        },
        {
            from : 'bottom left',
            to   : 'top right'
        },
        {
            from : 'top right',
            to   : 'bottom right'
        },
        {
            from : 'bottom right',
            to   : 'top left'
        },
        {
            from : 'top left',
            to   : 'bottom left'
        },
        {
            from : 'bottom left',
            to   : 'top right'
        },
        {
            from : 'top right',
            to   : 'bottom right'
        },
        {
            from : 'bottom right',
            to   : 'top left'
        },
        {
            from : 'top left',
            to   : 'bottom left'
        },
        {
            from : 'bottom left',
            to   : 'top right'
        },
        {
            from : 'top right',
            to   : 'bottom right'
        },
        {
            from : 'bottom right',
            to   : 'top left'
        },
        {
            from : 'top left',
            to   : 'bottom left'
        }];

        var actions = [];
        var z = 0;
        var time = 15;

        for(var i = 0; i < 4; i++)
        {
            for(var x in images)
            {
                actions[actions.length] = {
                    src  : images[x],
                    from : slideShow[z].from,
                    to   : slideShow[z].to,
                    time : time
                };
                z++;
            }
        }

        $(selector).crossSlide({
            fade: 1
        }, actions);
    },

    enlarge : function()
    {
        var index = $('#activeImage').val();

        $('.proBanner span a:eq('+ index +')').click();
    }
};