function initializeEmbedControls(){
	var origWidth = new Array();
	var origHeight = new Array();

  // adding elements
  $('object').each(function (i){
    var linkName = $(this).attr('rel').split(', ')[0];
    var linkUrl = $(this).attr('rel').split(', ')[1];
		origWidth[i] = $(this).width();
		origHeight[i] = $(this).height();
		$(this).before('<div class="object-background-container control-'+i+'"><div class="top left" style="height:'+(origHeight[i]+8)+'px"><div class="video-controls"><ul><li><a class="resize" href="#">Enlarge</a></li><li><a href="'+linkUrl+'" target="_blank">'+linkName+'</a></li></ul></div></div><div class="top right top-right" style="height:'+(origHeight[i]+8)+'px"></div><div class="bottom left"></div><div class="bottom right bottom-right"></div></div>').after('<div class="object-trigger" style="height:'+(origHeight[i])+'px"></div>');
		$(this).parents('.item').height(origHeight[i]);
  })

  var maximized = false;	
  
  $('.object-trigger').mouseenter(function(){
    if (!maximized) {
      minimizeControl($('.object-background-container').not(this)); 
      $(this).hide().siblings('.object-background-container').fadeIn('fast',function(){
        $(this).children('.left').animate({'width':280},'fast','swing');
      });
    }
  });
  
  $('.object-background-container').hover(function(){},function(){
    minimizeControl($(this));
  })
  
  
  $('.video-controls a.resize').click(function(e){
    e.preventDefault();
    var controlParent = $(this).parents('.object-background-container');
    var i = parseInt(controlParent.attr('class').split('control-')[1][0]);
    var newHeight = 425/190*origHeight[i];
    var newMarginTop = (newHeight - origHeight[i])*(-0.5);
    var thiss = $(this);

    if (!$(this).hasClass('big')) {
      controlParent.css('z-index',10).next().css('z-index',10);
      controlParent.children('.left').animate({'width':514,'marginLeft':-117},'fast','swing',function(){
        controlParent.children('.top').animate({'height':newHeight+8, 'marginTop':newMarginTop},'fast','swing',function(){
          controlParent.next().attr({'width':425,'height':newHeight}).css({'marginLeft':-117,'marginTop':newMarginTop+3}).children('embed').attr({'width':425,'height':newHeight});
          thiss.html('Close').addClass('big');
        });
      });
      maximized = true;
    } else {
      controlParent.css('z-index',0).next().css('z-index',0);
      controlParent.next().attr({'width':190,'height':origHeight[i]}).css({'marginLeft':0,'marginTop':3}).children('embed').attr({'width':190,'height':origHeight[i]}).css({'marginLeft':0,'marginTop':0});
      controlParent.children('.top').animate({'height':origHeight[i]+8,'marginTop':0},'fast','swing',function(){
        controlParent.children('.left').animate({'width':190,'marginLeft':0},'fast','swing',function(){
          thiss.html('Enlarge').removeClass('big');
        });
      });
      maximized = false;
    }
  })
  
  function minimizeControl(jObject){
    if (!maximized) {
      jObject.fadeOut('fast',function(){
        $(this).children('.left').css('width',190);
        $(this).siblings('.object-trigger').show();
      });
    }
  }
}