/**
 * @preserve Galleria Classic Theme 2011-08-01
 * http://galleria.aino.se
 *
 * Copyright (c) 2011, Aino
 * Licensed under the MIT license.
 */

/*global jQuery, Galleria */

Galleria.requires(1.25, 'This version of Classic theme requires Galleria 1.2.5 or later');

(function($) {


Galleria.addTheme({
    name: 'Galerie_olotropp',
    author: 'charleslouisallizard',
    css: 'galerie_olotropp.css',
    defaults: {
        transition: 'fade',
        thumbCrop:  'height',

        // set this to false if you want to show the caption all the time:
        _toggleInfo: true
    },
    init: function(options) {

        // add some elements
        this.addElement('info-link','info-close');
		this.append({
            'info' : ['info-link','info-close']
		
        });

        // cache some stuff
        var info = this.$('info-link,info-close,info-text'),
            touch = Galleria.TOUCH,
            click = touch ? 'touchstart' : 'click';

        // show loader & counter with opacity
        this.$('loader,counter').show().css('opacity', 0.4);

        // some stuff for non-touch browsers
        if (! touch ) {

			this.addIdleState( this.get('counter'), { opacity:0 });			
        }

        // toggle info
        if ( options._toggleInfo === true ) {
            info.bind( click, function() {
                info.toggle();
            });
        } else {
            info.show();
            this.$('info-link, info-close').hide();
        }

        // bind some stuff
        this.bind('thumbnail', function(e) {

       
                // fade thumbnails
                $(e.thumbTarget).css('opacity', 0).parent().hover(function() {
                    $(this).not('.active').css('background-position','bottom');
                }, function() {
                    $(this).not('.active').css('background-position', 'top');
                }
				);
				
				$(e.thumbTarget).parent().click((function() {
                    $(this).css('background-position', 'bottom').siblings().css('background-position', 'top');
                })
				);
           		
				
				if ( e.index === this.getIndex() ) {
						$(e.thumbTarget).parent().css('background-position', 'bottom');
					}
				else {
					$(e.thumbTarget).siblings().parent().css('background-position', 'top');
				}
		
        });
		
		
				$('.galleria-image-nav-right').click(function()
				{
				  $(this).css('background-position', 'bottom').siblings().css('background-position', 'top');
				});
				
				$('.galleria-image-nav-left').click(function()
				{
				  $(this).css('background-position', 'bottom').siblings().css('background-position', 'top');
				});
				
				$('.galleria-image-nav-left').hover(function()
				{
				  $(this).css('background-position', 'bottom').siblings().css('background-position', 'top');
				  
				});
				
				$('.galleria-image-nav-right').hover(function()
				{
				  $(this).css('background-position', 'bottom').siblings().css('background-position', 'top');
				  
				});
				
				$('.galleria-image-nav').mouseleave(function()
				{
				  $(this).children().css('background-position', 'top');
				  
				});



        this.bind('loadstart', function(e) {
            if (!e.cached) {
                this.$('loader').show().fadeTo(200, 0.4);
            }

           			
			$(e.thumbTarget).parentsUntil('.galleria-thumbnails-list').children().css('background-position', 'top');


       
        });

        this.bind('loadfinish', function(e) {
            this.$('loader').fadeOut(200);
				$(e.thumbTarget).parent().css('background-position', 'bottom');

				
        });
    }
});



}(jQuery));

