AXFlashSlides = function()
{
	this.id = "fslides";
	this.divId = "slides";
	this.bgcolor = "FFFFFF";
	this.slideshowPlayer = "swf/ax-slideshow-6.swf";
	this.asObject = "slideshow";
	this.url = null;
	this.slides = null;
	this.htmlSlidePath = "";
	this.currentSlide = 0;
	this.lastId = -1;
	this.slideTimer;
	this.isLoaded = false;
    this.ii = 0;	
}
AXFlashSlides.prototype.checkState = function()
{
    var slideCount = this.getSlideCount();
    var slideCountLoaded = this.getSlideCountLoaded();
   
    //alert("slideCount: "+slideCount+" slideCountLoaded: "+slideCountLoaded);
    if(slideCountLoaded > 1 && slideCountLoaded > this.currentSlide)
    {
        if(!this.isLoaded && typeof(this.slidesLoaded) == "function")
        {
            //alert("slidesloaded, slideCountLoaded: "+slideCountLoaded+" currentSlide: "+this.currentSlide);
            this.isLoaded = true;
            this.slidesLoaded();
        }
    }
}
AXFlashSlides.prototype.flashCommand = function(type,o,value)
{
    try
    {
        if(this.slides != null && this.ii > 10)
        {	
		    if(type == "get")
	        {
    		        return this.slides.GetVariable(o);
	        }
	        else if(type == "set" && typeof(this.slides.readyState) != undefined)
	        {
    		        this.slides.SetVariable(o, value);
	        }
        }
        
        if(this.ii < 11)
        {
            this.ii++;
        }
    }
    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.getSlideCount = function()
{
    var x = parseInt(this.flashCommand("get", "_root.slideCount"));
    return (x>-1)?x:0;
}
AXFlashSlides.prototype.getSlideCountLoaded = function()
{
    var x = parseInt(this.flashCommand("get", "_root.slideCountLoaded"));
    return (x>-1)?x:0;
}
AXFlashSlides.prototype.getSlide = function()
{
    return parseInt(this.flashCommand("get", "_root.slideIndex"));
}
AXFlashSlides.prototype.setSlide = function(id)
{
	id = (id != null && id > -1)?id:0;
	try
	{
	    this.currentSlide = id-1;
		if(this.slides != null)
		{
			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);
			}
		}
		
		if(this.htmlSlides != null)
		{
		    this.htmlSlides.src = this.htmlSlidePath + (this.currentSlide+1) + ".html";
		}
		
		if(id > 1 && mp2 != null && id != this.currentSlide+1)
		{
			mp2.Play();
		}
	}
	catch(e)
	{
		//alert(e);
	}
};
AXFlashSlides.prototype.setUrl = function(url)
{
    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)
{
    this.divId = div?div:"slides";
    if(this.url != null && this.divId != null)
	{
		this.isLoaded = false;
		if(typeof(this.slidesLoading) == "function")
		{
		    this.slidesLoading();
		}
		this.fo = new FlashObject(this.slideshowPlayer, this.id, "100%", "100%", 6, "CCCCCC");
		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("slideIndex", this.currentSlide);
		}
		this.fo.addParam("salign", "T");
		this.fo.addParam("wmode", "opaque");	
		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.slides = $(this.id);
		
		//start slideTimer
		if(this.slideTimer == undefined)
		{
		    this.slideTimer = new PeriodicalExecuter(this.checkState.bindAsEventListener(this), 1);
		    this.slideTimer.start();
		}
	}
}

/**********************************************************************************
*
* 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);
	}
}

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++;
            }
        }
    }
}