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

(function($) {

Galleria.addTheme({
    name: 'classic',
    author: 'Galleria',
    css: 'galleria.classic.css',
    defaults: {
        transition: 'fade',
        thumbCrop:  'height',
        
		// set this to false if you want to show the caption all the time:
        _toggleInfo: true,
		
				        // is the auto start set? this is the control for the button state.
		_playbut: true
		
		
		
    },
    init: function(options) {

		
        // add some elements
        this.addElement('info-link','info-close','gal-control');
        this.append({
            'info' : ['info-link','info-close'],
			'container' : ['gal-control']
        });
        
        // cache some stuff
        var info = this.$('info-link,info-close,info-text'),
            touch = Galleria.TOUCH,
            click = touch ? 'touchstart' : 'click';
        
		var galid = this
		
        // 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('image-nav-left'), { left:-50 });
            this.addIdleState( this.get('image-nav-right'), { right:-50 });
            this.addIdleState( this.get('counter'), { opacity:0 });
			this.addIdleState( this.get('info'), { opacity:0 });
			this.addIdleState( this.get('gal-control'), { opacity:0 });
        }
        
        // toggle info
        if ( options._toggleInfo === true ) {
            info.bind( click, function() {					   
                info.toggle();
				galid.$('gal-control').toggle();
            });
        } else {
			info.show();
			this.$('info-link, info-close').hide();
		}



this.bind('pause', function() {
                this.$('gal-control').addClass('playbut-paused');
            });
this.bind('play', function() {
                this.$('gal-control').removeClass('playbut-paused');
            });

         
		
        // bind some stuff
        this.bind('thumbnail', function(e) {
            
            if (! touch ) {
                // fade thumbnails
                $(e.thumbTarget).css('opacity', 0.6).parent().hover(function() {
                    $(this).not('.active').children().stop().fadeTo(100, 1);
                }, function() {
                    $(this).not('.active').children().stop().fadeTo(400, 0.6);
                });
                
                if ( e.index === options.show ) {
                    $(e.thumbTarget).css('opacity',1);
                }
            }
        });
        
        this.bind('loadstart', function(e) {
            if (!e.cached) {
                this.$('loader').show().fadeTo(200, 0.4);
            }
            
            this.$('info').toggle( this.hasInfo() );
            
            $(e.thumbTarget).css('opacity',1).parent().siblings().children().css('opacity', 0.6);
        });
		
		var gallery = Galleria.get(0); // gallery is now the first galleria instance
		var playingshow = true;
		
		
 this.$('gal-control').click(function() {
									  if(playingshow === true){
						gallery.pause();
						playingshow = false;
									  } else {
						gallery.play();
						playingshow = true;
						}
    });
				 
        this.bind('loadfinish', function(e) {
            this.$('loader').fadeOut(200);
        });
    }
});

   
  

  
  
}(jQuery));

