var bdv4Gallery = Class.create({
    DefaultOptions : {
        containerEl : 'gallerycontainer',
        photoEl : "leadphoto",
        swfEl : 'gallerySWF',
        id : 'bdv4GallerySWF'
    },
    
    initialize : function(xmlpath,options) {
        this.options = Object.extend(
			Object.extend({},this.DefaultOptions), options || {}
		);
		
		this.xmlpath = xmlpath
		
		this.photoEl = $( this.options.photoEl )
		this.containerEl = $( this.options.containerEl )
		
		var d = Element.getDimensions( this.photoEl )
		
		window.bdv4Gallery_InitFunction = function () {			
			var cback = this.objref.getCallback('slideChange')
			window[cback] = function(event,idx) {
			    this._handleSlideChange(idx)
			}.bind(this)
		}.bind(this)
		
		// do we have a start slide?
		start = 0
		var match = null
		if (match = /^\#p(\d+)$/.exec(window.location.hash)) {
		    start = match[1]
		}
				
		this.swfEl = new Element('div',{style:"",id:this.options.swfEl})
		this.photoEl.insert({
		    before: this.swfEl
		})
	
	    this.swfEl.absolutize()	
	    this.swfEl.clonePosition(this.photoEl)
	    
	    var top = this.swfEl.getStyle('top')
	    var left = this.swfEl.getStyle('left')
		
		swfobject.embedSWF(
			"/swf/bdv4Gallery.swf",
			this.options.swfEl,
			d.width,
			d.height + 10,
			"9",
			"/swf/expressInstall.swf",
			{ xmlpath : this.xmlpath, JSInitFunc : "bdv4Gallery_InitFunction", start : start },
			{ allowfullscreen : true },{style:"position:absolute;top:"+top+";left:"+left},function (e) {
			    this.objref = e.ref
			}.bind(this)
		);				
	},
	
    _handleSlideChange : function(idx) {
        //alert("changed slide to " + idx)
        //window.location.hash = "#p"+idx
        pageTracker._trackPageview(window.location.pathname + '/photos/' + idx)  
    }
	
})

1;