// this one by shawn hill - uses the TB fn and prototype
function select_to( select_obj, host ){
  if(select_obj.selectedIndex!=0) {
		  location.href='http://' + host + select_obj.options[select_obj.selectedIndex].value;
		}
		return false;
}
var rotatingImages = [];
var thisImage = 0;
var rotator;
// this one by shawn hill - uses the TB fn and prototype
function category_file( file_name, _div, width, height){
  var flv_movie='/movies/flv.swf', flash_version=8;
  var extension = file_name.split('.');
  switch (extension[extension.length - 1]){
    case 'swf':
      new FlashTag( flash_version, file_name, width, height ).insertHtml( _div );
      break;
    case 'flv':
      var tag = new FlashTag(flash_version, flv_movie, width, height);
      tag.addVariable( 'movie_path', file_name );
      tag.insertHtml( _div );
      break;
    default:
				  var ni = new Image();
						ni.src = file_name;
						rotatingImages[rotatingImages.length] = file_name;
				  if( rotatingImages.length == 1 ){
        $(_div).innerHTML='<img id="rotatorImage" src="'+file_name+'"/>'; //width="'+width+'" height="'+height+'" 
							 rotator = $('rotatorImage');
								setInterval('rotator.src = rotatingImages[( ++thisImage % rotatingImages.length )]', 3500)
						}
      break;
  }
}

// ---------------------------------------------------------------------------
// Usage
/*

# Example 1

if (FlashRedirect.hasVersion(8, 'noflash.html')) {
  var tag = new FlashTag(8, 'main.swf', '400', '300');
  tag.addProperty('bgcolor', '#ffffff');
  tag.addProperty('allowScriptAccess', 'sameDomain');
  tag.writeHtml();
}

# Example 2

if (Flash.hasVersion(8)) {
  var tag = new FlashTag(8, 'main.swf', '400', '300');
  tag.writeHtml();
} else {
  document.write('Flash 8 is not installed.');
}

# Example 3

new FlashTag(8,'main.swf','400','300').insertHtml('someDivId');

*/
// ---------------------------------------------------------------------------
// Flash Object

var Flash = new Object();

/**
 * @param versionRequired Number
 * @return Boolean
 */
Flash.hasVersion = function (versionRequired) {
  if (navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
    var description = navigator.plugins['Shockwave Flash'].description;
    var version = parseInt(description.charAt(description.indexOf('.') - 1));
    return version >= versionRequired;
  }
  if (navigator.appVersion.indexOf('Windows') != -1 && window.execScript) {
    this.hasVersionResult = null;
    execScript('on error resume next: Flash.hasVersionResult=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + versionRequired + '"))','VBScript');
    return this.hasVersionResult;
  }
  return false;
}

// ---------------------------------------------------------------------------
// FlashRedirect Object

var FlashRedirect = new Object();

/**
 * @param versionRequired Number
 * @param redirectLocation String
 * @return Boolean
 */
FlashRedirect.hasVersion = function (versionRequired, redirectLocation) {
  if (Flash.hasVersion(versionRequired)) {
    return true;
  } else {
    window.location.href = redirectLocation;
    return false;
  }
}

// ---------------------------------------------------------------------------
// FlashTag Class

/**
 * Constructor
 * @param version Number
 * @param movie String
 * @param width String
 * @param height String
 */
FlashTag = function (version, movie, width, height) {
  this.version = version;
  this.movie = movie;
  this.width = width;
  this.height = height;
  this.propers = new Array();
  this.varis = new Array();
}

/**
 * @param name String
 * @param value String
 * @return FlashTag
 */
FlashTag.prototype.addProperty = function (name, value) {
  this.propers[name] = value;
  return this;
}

/**
 * @param obj Object
 * @return FlashTag
 */
FlashTag.prototype.addProperties = function (obj) {
  for (var i in obj) {
    this.addProperty(i, obj[i]);
  }
  return this;
}

/**
 * @param name String
 * @param value String
 * @return FlashTag
 */
FlashTag.prototype.addVariable = function (name, value) {
  this.varis[name] = value;
  return this;
}

/**
 * @param obj Object
 * @return FlashTag
 */
FlashTag.prototype.addVariables = function (obj) {
  for (var i in obj) {
    this.addVariable(i, obj[i]);
  }
  return this;
}

/**
 * @return String
 */
FlashTag.prototype.getHtml = function(){
  var fvaris = '';
  //for (var i in this.varis) {
  //  fvaris += i + '=' + escape(this.varis[i]) + '&';
  //}
  this.addProperty ('FlashVars', fvaris);
  var tag = '<object';
  tag += ' width="' + this.width + '"';
  tag += ' height="' + this.height + '"';
  tag += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
  tag += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.version + ',0,0,0">';
  tag += '<param name="movie" value="' + this.movie + '?' + fvaris + '" />';
  for (var i in this.propers) {
    tag += '<param name="' + i + '" value="' + this.propers[i] + '" />';
  }
  tag += '<embed src="' + this.movie + '?' + fvaris + '"';
  tag += ' type="application/x-shockwave-flash"';
  tag += ' pluginspage="http://www.macromedia.com/go/getflashplayer"';
  tag += ' width="' + this.width + '"';
  tag += ' height="' + this.height + '"';
  for (var i in this.propers) {
    tag += ' ' + i + '="' + this.propers[i] + '"';
  }
  tag += '><\/embed>';
  tag += '<\/object>';
  return tag;
}

/**
 * @return Void
 */
FlashTag.prototype.writeHtml = function(){
  document.write(this.getHtml());
}

/**
 * @param element Object
 * @return Void
 */
FlashTag.prototype.insertHtml = function (element) {
  //if ( ! element) element = document.body;
  //else if (typeof(element) == 'string') element = document.getElementById(element);
  var _divvy = document.createElement('div');
  _divvy.innerHTML = this.getHtml();
  //element.appendChild(div);
		$(element).appendChild(_divvy)
}

// ---------------------------------------------------------------------------
