AXFlashSlides = function(id, url, bgcolor)
{
	this.slides = null;
	if(url != null)
	{
		this.fo = new FlashObject("swf/axslideshow-3.swf", id, "100%", "100%", 6, "CCCCCC");
		this.fo.addVariable("url", url);
		this.fo.addParam("salign", "T");
		this.fo.addParam("wmode", "opaque");	
		if(bgcolor != null)
		{
			this.fo.addParam("bgcolor", bgcolor);
		}
		this.fo.write('slides');
		
		var slidesDiv = findObj('slides');
		if(slidesDiv != null)
		{
			slidesDiv.style.display = "block";
		}
		
		this.slides = findObj(id);
		//this.ratio = ratio ? ratio : 1.3333;
		if(this.slides.length != null && this.slides.length > 1)
		{
			this.slides = this.slides[0];
				
		}
	}
	this.htmlSlidePath = "";
	this.currentSlide = 0;
	this.lastId = -1;
}
AXFlashSlides.prototype.setSlide = function(id)
{
	//alert("Set slide "+id + " current " + this.currentSlide);
	//alert("slide path "+this.htmlSlidePath);
	if(id != null && id != this.lastId)
	{
		this.currentSlide = id-2;
		try
		{
			if(this.slides != null)
			{
				this.slides.SetVariable("_root.slides.tCurrentSlide", this.currentSlide.toString());
				this.slides.TCallLabel("_root.slides", "setCurrentSlide");
			}
			
			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);
				}
			}
			//alert(this.htmlSlides.src);
			this.htmlSlides.src = this.htmlSlidePath + (id+2) + ".html";
			
			if(id > 1 && mp2 != null)
			{
				mp2.Play();
			}
		}
		catch(e)
		{
			//alert(e);
		}
		this.lastId = id;
	}
};
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;
		}
		
		/*
		if(this.slideTimer != null)
		{
			if(this.slides.offsetWidth != w || this.slides.offsetHeight != h)
			{
				this.slideTimer = setTimeout("slides.setSize("+this.width+","+this.height+")", 200);
			}
			else
			{
				this.slideTimer = null;
			}
		}
		else
		{
			this.slideTimer = setTimeout("slides.setSize("+this.width+","+this.height+")", 200);
		}
		*/	
	}
};
AXFlashSlides.prototype.previous = function()
{
	if(this.currentSlide > 0)
	{
		this.setSlide(this.currentSlide-1);
	}
};
AXFlashSlides.prototype.next = function()
{
	this.setSlide(this.currentSlide+1);
};
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);
	}
}

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++;
            }
        }
    }
}
