function getFlashMovieObject(movieName) {
  if (window.document[movieName]) {
      return window.document[movieName];
  } else {
    return document.getElementById(movieName);
  }
}    


var Aq_Gallery2 = Class.create( {
	
	setHandles : function() {
			
        //Adding viewer to page
        $('a[id^=galleryButtonA-]').click(function()
        	{
        		alert('test');
        		//$('div#galleryPhoto').css('display', 'block');
        	});
        
        /**
         * Hover thumbnail.
         */
        $('li[id^=galleryButton-]').hover( function()
        		{
            	var reg = new RegExp('-(.*)', 'gi');
            	var id = reg.exec($(this).attr('id'));
            	id = id[1];
		          $('#imageThumbCanvas-' + id).fadeIn('fast');
					  }, function() 
					  	{
            		var reg = new RegExp('-(.*)', 'gi');
            		var id = reg.exec($(this).attr('id'));
            		id = id[1];
			           $('#imageThumbCanvas-' + id).fadeOut('slow');
        			}
        	);
     }
	
});



/* old class not used */

var Aq_Gallery = Class.create( {
    isFullscreen : false,
    savedOffset : 0,
    /**
     * Setting handles on gallery buttons / links
     */
    setHandles : function() {
        //Adding viewer to page
        var params = {
            wmode:'opaque',
            allowScriptAccess:'*'
        }
    
        //swfobject.embedSWF(Const.SITE_URL+'public/swf/ImageViewer.swf', "galleryPhotoClose2", "100%", "100%", "9", null, null, params); 
        var _this = this;
        $('a[id^=galleryButton-]').click(function() {
            $('div#galleryPhoto').css('display', 'block')
        })
        
        /**
         * Hover thumbnail.
         */
        $('li[id^=galleryButton-]').hover(function() {
            var reg = new RegExp('-(.*)', 'gi');
            var id = reg.exec($(this).attr('id'));
            id = id[1];

            $('#imageThumbCanvas-' + id).fadeIn('fast');

        }, function() {
            var reg = new RegExp('-(.*)', 'gi');
            var id = reg.exec($(this).attr('id'));
            id = id[1];

            $('#imageThumbCanvas-' + id).fadeOut('slow');
        });

        /**
         * Loading a full screen image
         */
        $('li[id^=galleryButton-]').click(function() {
        	
            // Setting gallery bar to the bottom of the screen
            if (!_this.isFullscreen) {

                var bodyHeight = parseInt($('body').height());
                
                var scroll = $(window).scrollTop();
                var offsetRelative = document.getElementById('gallery').offsetTop - scroll ;
                
                if($.browser.msie)
                {
                    var interval = bodyHeight - 49;
                    _this.savedOffset = document.getElementById('gallery').offsetTop;
                    $('#gallery').css('top', document.getElementById('gallery').offsetTop);
                    $('div#gallery').animate( {
                        top : ''+ interval+'px'
                    });
                }
                else
                {
                    var interval = bodyHeight - offsetRelative - 49;
                    _this.savedOffset = interval;
                    $('div#gallery').animate( {
                        top : '+=' + interval 
                    });
                }
                
                $('div#gallery').css('position', 'absolute');
                
                //$('div#gallery').css('top', 0);
                
            }

            _this.isFullscreen = true;
            
            // Fetching image fullscreen URL
            var reg = new RegExp('-(.*)', 'g');
            var id = reg.exec($(this).attr('id'));
            id = id[1];
            
            $('#galleryphotos').css('top', $(document).scrollTop() + 'px');
            //$('#galleryphotos').css('top', '60px');
            
            /*
            if($.browser.msie)
            {
                $('html').css('overflow', 'hidden');
            } else {
                $('body').css('overflow', 'hidden');
            }
            */
						
            $('#galleryphotos').fadeIn(
                'slow',
                function() {
                    $('galleryPhotoClose2').ready(function(){
                        var width = $('body').width();
                        var height = $('body').height();
                        
                        $('div.infos').fadeOut('fast', function(){
                            $('div.infos b').html($('input[name=title-'+id+']').val());
                            $('div.infos p').html($('input[name=subtitle-'+id+']').val());
                            $('div.infos').fadeIn('fast');
                        })
                        
                        var fullUrl = Const.SITE_URL
                        + 'media/render/image-thumb/id/' + id + '/width/'
                        + width + '/height/' + height + '/crop/inner';
                        
                        //console.log(fullUrl);
                        var im = new Image(width, height);
                        
                        //$('img#galleryPhoto').attr('src',fullUrl);
                        
                        $(im).load(function() {
                            $('img#galleryPhoto').fadeOut('fast', function() {
                                $('img#galleryPhoto').attr('src', fullUrl);
                                $('img#galleryPhoto').fadeIn('fast');
                            })
                        });
    
                        $(im).attr('src', fullUrl);
                         
                        /*
                        $('#galleryPhotoClose2').ready(function(){
                            var img = getFlashMovieObject("galleryPhotoClose2");
                        	
                            img.loadImage(fullUrl, true);
                        })*/
                    });
                });
            
                return false;
        });

        /**
         * Click action on the "close" button
         */
        $('a[id^=galleryPhotoClose]').click(function() {
            $('#galleryphotos').fadeOut(
                'fast',
                function(){
                    if($.browser.msie)
                    {
                        $('html').css('overflow', '');
                    }
                    else
                    {
                        $('body').css('overflow', '');
                    }
                    
                    if($.browser.msie)
                    {
                        $('div#gallery').animate( {
                            top : (Math.abs(_this.savedOffset)) + 'px'
                        });
                    }
                    else
                    {
                        $('div#gallery').animate( {
                            top : '-='+(Math.abs(_this.savedOffset))
                        });
                    }
                    
                    
                    
                    _this.isFullscreen = false;
                }
            );
            return false;
        });
    }
});
