var slideObject

AXFlashSlides = function()
{
	this.id = "fslides";
	this.divId = "slides";
	this.bgcolor = "F6F6F6";
	this.url = null;
	this.slides = null;
	this.htmlSlidePath = "";
	this.currentSlide = -1;
	this.lastId = -1;
	this.slideChange = null;
}
AXFlashSlides.prototype.flashCommand = function(type,o,value)
{
    try
    {
        if(type == "get")
        {
            return this.slides.GetVariable(o);
        }
        else if(type == "set")
        {
            this.slides.SetVariable(o, value);
        }
    }
    catch(ex)
    {
    }
}
AXFlashSlides.prototype.getFlashMovieObject = function(id)
{
    if (window.document[id]) 
    {
        return window.document[id];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1)
    {
        if (document.embeds && document.embeds[id])
        {
            return document.embeds[id]; 
        } 
    }
    else
    {
        return document.getElementById(id);
    }
}
AXFlashSlides.prototype.next = function()
{
	this.setSlide(this.currentSlide+1);
}
AXFlashSlides.prototype.previous = function()
{
	if(this.currentSlide > 0)
	{
		this.setSlide(this.currentSlide-1);
	}
}
AXFlashSlides.prototype.search = function(s)
{
    this.flashCommand("set", "_root.slideshow", "search("+(s)+")");
}
AXFlashSlides.prototype.getCurrentSlide = function()
{
    var newSlide = parseInt(this.flashCommand("get", "_root.currentSlideIndex"));
    if(this.currentSlide != -1 && newSlide != this.currentSlide && this.slideChange != null)
    {
         //alert('slide set: '+newSlide+' current: '+this.currentSlide);
         this.slideChange(newSlide+1);
    }
}
AXFlashSlides.prototype.setSlide = function(id)
{
    if(id != null && id-1 != this.currentSlide)
	{   
		try
		{
			if(this.slides != null)
			{
			    this.currentSlide = id-1;
			    //alert('set slide: '+this.currentSlide);
				this.flashCommand("set", "_root.slideshow", "setSlide("+this.currentSlide+")");
			}
			
			if(this.htmlSlidePath == "")
			{
				if(this.htmlSlides == null)
				{
					this.htmlSlides = document.getElementById('htmlslides');
				}
				if(this.htmlSlides != null && this.htmlSlides.src != null)
				{
					this.htmlSlidePath = this.htmlSlides.src.substring(0, this.htmlSlides.src.lastIndexOf(".")-1);
				}
			}
			this.htmlSlides.src = this.htmlSlidePath + (id+1) + ".html";
			
			if(id > 1 && mp2 != null && id != this.currentSlide+1)
			{
				mp2.Play();
			}
		}
		catch(e)
		{
			//alert(e);
		}
	}
};
AXFlashSlides.prototype.setSize = function(w, h)
{
	if(this.slides != null)
	{
		if(w.indexOf("%") < 0)
		{
			if(w/h>this.ratio)
			{
				this.height = Math.round(h);
				this.width = Math.round(h*this.ratio);
			}
			else
			{
				this.height = Math.round(w/this.ratio);
				this.width = Math.round(w);
			}
			this.slides.style.width = this.width+"px";
			this.slides.style.height = this.height+"px";
		}
		else
		{
			this.slides.style.width = w;
			this.slides.style.height = h;
		}	
	}
}
AXFlashSlides.prototype.setUrl = function(url)
{
    //alert("setUrl");
    if(url != null)
    {
        if(url.indexOf("?") > -1)
        {
            //extract slideId
            var id = -1;
            var s = url.split("?");
            var newUrl = "data/"+s[0];
            
            for(var i=1; i<s.length; i++)
            {
                if(s[i].indexOf("slideId") > -1)
                {
                    id = parseInt(s[i].substring(s[i].indexOf("=")+1));
                }
            }
            
            if(newUrl != this.url)
            {
                //load new slide show
                this.currentSlide = id-1;
                this.lastId = -1;
                this.url = newUrl;
                this.write();
            }
            else if(id > -1)
            {
              	this.setSlide(id);
            }
        }
        else
        {
            if(url != this.url)
            {
                this.currentSlide = -1;
                this.lastId = -1;
                this.url = url;
                this.write();
            }
        }
    }
}
AXFlashSlides.prototype.write = function(div)
{
    //debugger
    this.divId = div?div:"slides";
    if(this.url != null && this.divId != null)
	{
		this.fo = new FlashObject("swf/slidestrip-1.swf?i="+new Date().getTime(), this.id, "100%", "100%", 8, this.bgcolor);
		this.fo.addVariable("url", this.url);
		
		if(this.fo.installedVersion > 7)
	    {
	        this.fo.addParam("allowScriptAccess", "always");
	    }
	    else
	    {
	        this.fo.addParam("allowScriptAccess", "sameDomain");	
	    }
	
		if(this.currentSlide > -1)
		{
		    this.fo.addVariable("currentSlide", this.currentSlide);
		}
		//this.fo.addParam("salign", "TL");
		//this.fo.addParam("scaleMode", "noScale");
		//this.fo.addParam("wmode", "opaque"); //problem in FF to select images
		if(this.bgcolor != null)
		{
			this.fo.addParam("bgcolor", this.bgcolor);
		}
		this.fo.write(this.divId);
		
		var slidesDiv = document.getElementById(this.divId);
		if(slidesDiv != null)
		{
			slidesDiv.style.display = "block";
		}
		
		this.slides = this.getFlashMovieObject(this.id);
		this.currentSlideInterval = setInterval('slides.getCurrentSlide()', 1000);
	}
}

/**********************************************************************************
*
* HTML slide show
*
*
***********************************************************************************/
AXSlideShow = function(classname)
{
	this.classname = classname ? classname : "slideshow";
	this.setParentBackgroundColor = true;
	this.currentSlide = 0;
	
	//get slides
	this.slideshows = GetElementsWithClassName('div',this.classname);
	if(this.slideshows != null && this.slideshows.length > 0)
	{
		this.slides = this.slideshows[0].childNodes;
		var t = new Array();
		if(this.slides != null && this.slides.length > 0)
		{
			for(var i=0; i<this.slides.length; i++)
			{
				if(this.slides[i].nodeType == 1)
				{
					t.push(this.slides[i]);
					this.showHideSlide(i, false);
				}
			}
			
			this.slides = t;
		}
	}
	this.setSlide(0);
}
AXSlideShow.prototype.setSlide = function(id)
{
	if(this.slides != null && id > -1 && id < this.slides.length)
	{
		this.showHideSlide(this.currentSlide, false);
		this.showHideSlide(id, true);
		this.currentSlide = id;
		//jscss('swap', this.slides[id], this.slides[id].className, this.slides[id].className);
		if(this.setParentBackgroundColor)
		{
			var o = this.slides[this.currentSlide];
			var color = getStyle(o, "background-color");
			if(color != null)
				this.slideshows[0].style.backgroundColor = color;
		}
	}
}
AXSlideShow.prototype.showHideSlide = function(id, show)
{
	if(this.slides != null)
	{
		if(show)
		{
			this.slides[id].style.display = 'block';
		}
		else{
			this.slides[id].style.display = 'none';
		}
	}
}
AXSlideShow.prototype.previous = function()
{
	if(this.slides != null && this.currentSlide > 0)
	{
		this.setSlide(this.currentSlide-1);
	}
}
AXSlideShow.prototype.next = function()
{
	if(this.slides != null && this.slides.length - 1 > this.currentSlide)
	{
		this.setSlide(this.currentSlide+1);
	}
}

if(!axm) var axm = {};

if(!axm.controls) axm.controls = {};


axm.controls.toggleButton = function()
{
	this.id = "fslides";
	this.divId = "slides";
}

function slideLabel() {
	var slideColl = GetElementsWithClassName('div','slide');
	var list = document.getElementById('jumplist');
	smax = slideColl.length;
	for (n = 0; n < smax; n++) {
		var obj = slideColl[n];

		var did = 'slide' + n.toString();
		obj.setAttribute('id',did);
		if(isOp) continue;

		var otext = '';
 		var menu = obj.firstChild;
		if (!menu) continue; // to cope with empty slides
		while (menu && menu.nodeType == 3) {
			menu = menu.nextSibling;
		}
	 	if (!menu) continue; // to cope with slides with only text nodes

		var menunodes = menu.childNodes;
		for (o = 0; o < menunodes.length; o++) {
			otext += nodeValue(menunodes[o]);
		}
		list.options[list.length] = new Option(n+' : ' +otext,n);
	}
}
/*
function getStyle(el,styleProp)
{
	var x = el;
	if(typeof(el) == "string")
		x = document.getElementById(el);
	if (document.defaultView != null && document.defaultView.getComputedStyle != null)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x != null && x.currentStyle != null)
		var y = eval('x.currentStyle.' + styleProp);
	return y;
}
*/
function getStyle(el, style) {
   if(!document.getElementById) return;
   
     var value = el.style[toCamelCase(style)];
   
    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);
       
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];
     
     return value;
}

/** toCamelCase(input)
 * Converts string input to a camel cased version of itself.
 * For example:
 * toCamelCase("z-index"); // returns zIndex
 * toCamelCase("border-bottom-style"); // returns borderBottomStyle.
 */
function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? 
    	oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}

function isClass(object, className) {
	return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
}

function GetElementsWithClassName(elementName,className) {
	var allElements = document.getElementsByTagName(elementName);
	var elemColl = new Array();
	for (i = 0; i< allElements.length; i++) {
		if (isClass(allElements[i], className)) {
			elemColl[elemColl.length] = allElements[i];
		}
	}
	return elemColl;
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

Array.prototype.removeItems = function(itemsToRemove) {

    if (!/Array/.test(itemsToRemove.constructor)) {
        itemsToRemove = [ itemsToRemove ];
    }

    var j;
    for (var i = 0; i < itemsToRemove.length; i++) {
        j = 0;
        while (j < this.length) {
            if (this[j] == itemsToRemove[i]) {
                this.splice(j, 1);
            } else {
                j++;
            }
        }
    }
}