/**************************************************************

	Script	: Image Menu
	Version	: 2.2
	Authors	: Samuel Birch
	Desc	: 
	Licence	: Open Source MIT Licence

**************************************************************/

	
var ImageMenu = new Class({
	
	getOptions: function(){
		return {
			onOpen: false,
			onClose: Class.empty,
			openWidth: 200,
			transition: Fx.Transitions.quadOut,
			duration: 400,
			open: null,
			border: 0
		};
	},

	initialize: function(elements, options){
		this.setOptions(this.getOptions(), options);
		
		this.elements = $$(elements);
		
		this.widths = {};
		this.widths.closed = this.elements[0].getStyle('width').toInt();
		this.widths.openSelected = this.options.openWidth;
		this.widths.openOthers = Math.round(((this.widths.closed*this.elements.length) - (this.widths.openSelected+this.options.border)) / (this.elements.length-1))
		
		
		this.fx = new Fx.Elements(this.elements, {wait: false, duration: this.options.duration, transition: this.options.transition});
		
		this.elements.each(function(el,i){
			el.addEvent('mouseenter', function(e){
				new Event(e).stop();
				this.reset(i);
				
			}.bind(this));
			
			el.addEvent('mouseleave', function(e){
				new Event(e).stop();
				this.reset(this.options.open);
				
			}.bind(this));
			
			var obj = this;
			/*
			el.addEvent('click', function(e){

				if(obj.options.onOpen){
					new Event(e).stop();
					
					if(obj.options.open == i){
						obj.options.open = null;
						obj.options.onClose(this.href, i);
					}else{
						obj.options.open = i;
						obj.options.onOpen(this.href, i);
					}
				}
				
			})*/
			
		}.bind(this));
		
		if(this.options.open){
			if($type(this.options.open) == 'number'){
				this.reset(this.options.open);
			}else{
				this.elements.each(function(el,i){
					if(el.id == this.options.open){
						this.reset(i);
					}
				},this);
			}
		}
		
	},
	
	reset: function(num){
		if($type(num) == 'number'){
			var width = this.widths.openOthers;
			if(num+1 == this.elements.length){
				width += this.options.border;
			}
		}else{
			var width = this.widths.closed;
		}
		
		var obj = {};
		this.elements.each(function(el,i){
			var w = width;
			if(i == this.elements.length-1){
				w = width+5
			}
			obj[i] = {'width': w};
		}.bind(this));
		
		if($type(num) == 'number'){
			obj[num] = {'width': this.widths.openSelected};
		}
				
		this.fx.start(obj);
	}
	
});

ImageMenu.implement(new Options);
ImageMenu.implement(new Events);

function flashContent(id,file,width,height){
    var flashinstalled = 0;
    var windows = ControlVersion();
    var flash = '<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\' width=\'' + width +'\' height=\'' + height +'\'><param name=\'wmode\' value=\'transparent\' /><param name=\'movie\' value=\'' + file +'\' /><param name=\'quality\' value=\'high\' /><param name=\'loop\' value=\'false\' /><embed src=\'' + file +'\' quality=\'high\' loop=\'false\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' width=\'' + width +'\' height=\'' + height +'\'></embed></object>';
    
    if(navigator.plugins && navigator.plugins.length){
        x = navigator.plugins['Shockwave Flash'];
        if(x){
            flashinstalled = 2;
        }else{
            flashinstalled = 1;
            if(navigator.plugins['Shockwave Flash 2.0']){
                flashinstalled = 2;
            }
        }
    }else if(navigator.mimeTypes && navigator.mimeTypes.length){
        x = navigator.mimeTypes['application/x-shockwave-flash'];
        if(x && x.enabledPlugin){
            flashinstalled = 2;
        }else{
            flashinstalled = 1;
        }
    } else {
        if(windows != '-1') {
            flashinstalled = 2;    
        } else {
            flashinstalled = 1;
        }
    }

    if(flashinstalled == 2){
        document.getElementById(id).innerHTML = flash;
    }
}

// This function find the broswer/flash type for IE.
function ControlVersion(){
    var version;
    var axo;
    var e;
    try {
        axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.7');
        version = axo.GetVariable('$version');
    } catch (e) {
    }

    if (!version){
        try {

            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
            version = 'WIN 6,0,21,0';    
            axo.AllowScriptAccess = 'always';
            version = axo.GetVariable('$version');

        } catch (e) {
        }
    }
    if (!version){
        try {
            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.3');
            version = axo.GetVariable('$version');
        } catch (e) {
        }
    }

    if (!version) {
        try {
            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.3');
            version = 'WIN 3,0,18,0';
        } catch (e) {
        }
    }
    if (!version) {
        try {
            axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
            version = 'WIN 2,0,0,11';
        } catch (e) {
            version = -1;
        }
    }
    return version;
}

	function pli() {
  		var d=document;
		if(d.images){ 
			if(!d.MM_p) 
				d.MM_p=new Array();
				
			var i,j=d.MM_p.length,a=pli.arguments; 
			
			for(i=0; i<a.length; i++)
				if(a[i].indexOf("#")!=0){ 
					d.MM_p[j]=new Image; 
					d.MM_p[j++].src=a[i];
				}
			}
	}
	
/*************************************************************/