/* Rename embed tags for setSWFDimensions function - for AdSys ads*/
function resize(objID, width, height, open) {
  if(open) {
    var embeds = document.getElementsByTagName("embed");
    for(var i = 0; i < embeds.length; i++) {
      if(embeds[i].name == objID) {
        embeds[i].id = objID + "-embed";
      }
    }
  }
  setSWFDimensions(objID, width, height);
}

/* Resize Flash objects */
function setSWFDimensions(objID, width, height) {
  if(objID && width && height) {
    setElementDimensions(objID, width, height);
    var fEmb = document.getElementById(objID + '-embed');
			
    if(fEmb != null) { 
      fEmb.width = width;
      fEmb.height = height;
      if(fEmb.style) { 
        fEmb.style.width = width + 'px';
        fEmb.style.height = height + 'px';
      }
    }
  }
}

/* Resize HTML Elements */
function setElementDimensions(objID, width, height) {
  if (objID && width && height) {
    var fObj = document.getElementById(objID);
    
    if (fObj && fObj.style) {
      fObj.setAttribute('width', width);
      fObj.setAttribute('height', height);
      fObj.style.width = width + 'px';
      fObj.style.height = height + 'px';
    }	
  }	
}

function expandElementDimensions(objID, width, height) {
  if (objID && width && height) {
    var fObj = document.getElementById(objID);
    
    if (fObj && fObj.style) {
      fObj.setAttribute('width', width);
      fObj.setAttribute('height', height);
      fObj.style.width = width;
      fObj.style.height = height;
    }	
  }	
}

function setElementPosition(objID, top, left) {
	if (objID && top && left) {
    var fObj = document.getElementById(objID);
    
    if (fObj && fObj.style) {
      fObj.setAttribute('top', top);
      fObj.setAttribute('left', left);
      fObj.style.top = top + 'px';
      fObj.style.left = left + 'px';
    }	
  }
}


/* for peel ads */
function peel(pid, oid, width, height) {
  var frames = document.getElementsByTagName("iframe");
  for(var i = 0; i < frames.length; i++) {
    if(frames[i].style.visibility == "hidden") {
      frames[i].style.visibility = "visible";
    } else {
      frames[i].style.visibility = "hidden";
    }
  }
  setElementDimensions(pid, width, height);
  setSWFDimensions(oid, width, height);
}

/* Object Control */
function ObjectControl(div_id)
{

	this.object_attributes 	= new Object();
	this.object_params	= new Object();
	this.embed_attributes	= new Object();

	this.div_id = div_id;

	//Methods
	this.set_object_attribute = ObjectControl_set_object_attribute;
	this.set_object_param = ObjectControl_set_object_param;
	this.set_embed_attribute = ObjectControl_set_embed_attribute;
	this.write_object = ObjectControl_write_object;
}

function ObjectControl_set_object_attribute(attribute_name, attribute_value)
{
	this.object_attributes[attribute_name] = attribute_value;
}

function ObjectControl_set_object_param(param_name, param_value)
{
	this.object_params[param_name] = param_value;
}

function ObjectControl_set_embed_attribute(attribute_name, attribute_value)
{
	this.embed_attributes[attribute_name] = attribute_value;
}

function ObjectControl_write_object()
{
	var object_tag =   '<object';
	
	for (attribute in this.object_attributes)
	{
		object_tag += ' ' + attribute + '="' + this.object_attributes[attribute] + '"';
	}

	object_tag += '>\n';

	for (param in this.object_params)
	{
		object_tag += '<param name="' + param + '" value="' + this.object_params[param] + '" />\n';
	}
    	
	var with_embed = false;
	var embed_attributes  = '';
	for (attribute in this.embed_attributes)
	{
		with_embed = true;
		embed_attributes += ' ' + attribute + '="' + this.embed_attributes[attribute] + '"';
	}

	
	if (with_embed)
		object_tag += '<embed' + embed_attributes + ' />\n';

	object_tag += '</object>\n';

	if (this.div_id)
	{
		var d = document.getElementById(this.div_id);
  		d.innerHTML = object_tag;
	}
	else
		document.write(object_tag);

	return object_tag;
}

