
// start ImgDetailUpdater
var ImgDetailUpdater = Class.create ({
    initialize: function(pic,links,items,options)
    {
		this.pic = pic;
		this.links = links;
		this.items = items;
			this.length = this.items.size();
		this.options = Object.extend(
		{
			initialIndex: 0,
			equalHeight: false, // boolean only, does not currently accept user inputed value
			activeClassName: 'active'
		}, options || {});
		if (this.options.initialIndex >= this.length)
		{
			this.options.initialIndex = 0;
		}
		this.currentIndex = this.options.initialIndex;

        this.maxHeight = this.options.equalHeight;
        if (this.options.equalHeight)
        {
			this.checkMaxHeight();
			this.setMaxHeight();
        }

		var boundClickHandler = this.__Click.bindAsEventListener(this);
        this.links.invoke('observe', 'click', boundClickHandler);

		//set initial display
		this.UpdateDetails(this.currentIndex);
    },
    checkMaxHeight: function()
    {
        this.maxHeight = 0;
        for (var i=0; i<this.length; i++)
        {
            if (this.items[i].getHeight() > this.maxHeight)
            {
                this.maxHeight = this.items[i].getHeight();
            }
        }
    },
    setMaxHeight: function()
    {
        this.items.invoke('setStyle', {height: this.maxHeight});
        this.items[0].up(0).setStyle({height: this.maxHeight+'px'});
    },
    __Click: function(e)
    {
        //e.stop();
        var el = Event.findElement(e, 'A');
        for (var i=0; i<this.length; i++)
        {
	        if (this.links[i] == el)
	        {
		        this.UpdateDetails(i);
		        break;
	        }
        }
    },
    UpdateDetails: function(i)
    {
		//update detail img
		this.pic.src = this.links[i].rel;
		this.pic.alt = this.links[i].title;
		//highlight link
        var activeClassName = this.options.activeClassName;
        this.links.each(function(el, index) {
			el.up().removeClassName(activeClassName);
		}); // un-highlight all links parents
		this.links[i].up().addClassName(activeClassName); // highlight specific link parent
		//hide / show details
        this.items.invoke('hide');
        this.items[i].appear({ duration: 0.3 });
        //this.items[i].show();
    }
});
// end ImgDetailUpdater


// start VidDetailUpdater
var VidDetailUpdater = Class.create ({
    initialize: function(pic,links,items,options)
    {
		this.pic = pic;
		this.links = links;
		this.items = items;
			this.length = this.items.size();
		this.options = Object.extend(
		{
			initialIndex: 0,
			equalHeight: false, // boolean only, does not currently accept user inputed value
			activeClassName: 'active'
		}, options || {});
		if (this.options.initialIndex >= this.length)
		{
			this.options.initialIndex = 0;
		}
		this.currentIndex = this.options.initialIndex;

        this.maxHeight = this.options.equalHeight;
        if (this.options.equalHeight)
        {
			this.checkMaxHeight();
			this.setMaxHeight();
        }

		var boundClickHandler = this.__Click.bindAsEventListener(this);
        this.links.invoke('observe', 'click', boundClickHandler);

		//set initial display
		this.UpdateDetails(this.currentIndex);
    },
    checkMaxHeight: function()
    {
        this.maxHeight = 0;
        for (var i=0; i<this.length; i++)
        {
            if (this.items[i].getHeight() > this.maxHeight)
            {
                this.maxHeight = this.items[i].getHeight();
            }
        }
    },
    setMaxHeight: function()
    {
        this.items.invoke('setStyle', {height: this.maxHeight});
        this.items[0].up(0).setStyle({height: this.maxHeight+'px'});
    },
    __Click: function(e)
    {
        //e.stop();
        var el = Event.findElement(e, 'A');
        for (var i=0; i<this.length; i++)
        {
	        if (this.links[i] == el)
	        {
		        this.UpdateDetails(i);
		        break;
	        }
        }
    },
    UpdateDetails: function(i)
    {
		//init
		var Img = this.links[i].rel.split(';')[0];
		var Vid = this.links[i].rel.split(';')[1];
		var Alt = this.links[i].title;
		var activeClassName = this.options.activeClassName;
		//update Silverlight player
		loadVideo.defer(Vid,Img);
		//update detail img
		//this.pic.src = Img;
		//this.pic.alt = Alt;
		//highlight link
        this.links.each(function(el, index) {
			el.up().removeClassName(activeClassName);
		}); // un-highlight all links parents
		this.links[i].up().addClassName(activeClassName); // highlight specific link parent
		//hide / show details
        this.items.invoke('hide');
        this.items[i].appear({ duration: 0.3 }); //this.items[i].show();
    }
});
// end VidDetailUpdater
