// $Id: google_cse.js,v 1.1.4.3 2008/07/01 21:31:14 mfb Exp $
$(function() {
  var googleCSEWatermark = function($id) {
    var f = document.getElementById($id);
    if (f && (f.query || f.q || f['edit-keys'])) {
      var q = f.query ? f.query : (f.q ? f.q : f['edit-keys']);
      var n = navigator;
      var l = location;
      if (n.platform == 'Win32') {
        q.style.cssText = 'border: 1px solid #7e9db9; padding: 2px;';
      }
      var b = function() {
        if (q.value == '') {
          q.style.background = '#FFFFFF url(http://www.google.com/coop/intl/' + Drupal.settings.googleCSE.language + '/images/google_custom_search_watermark.gif) left no-repeat';
        }
      };
      var f = function() {
        q.style.background = '#ffffff';
      };
      q.onfocus = f;
      q.onblur = b;
      if (!/[&?]query=[^&]/.test(l.search)) {
        b();
      }
    }
  };
  googleCSEWatermark('google-cse-searchbox-form');
  googleCSEWatermark('google-cse-results-searchbox-form');
  if (Drupal.settings.googleCSE.searchForm) {
    googleCSEWatermark('search-form');
  }
});
;
// Array to hold the player object ids
onepixelout_objects = new Array();

// Array to hold the playerIDs
onepixelout_players = new Array();

// Set a flag to show if id's have been collected
onepixelout_initialized = 0;

// Call back when a player is started - it uses the flashvar playerID of the player that is starting as its parameter
function ap_stopAll(playerID) {
  
  // If this is the first time we clicked a player then get the object and player ids
  if (!onepixelout_initialized) {
    onepixelout_getPlayers();
    onepixelout_initialized = 1;
  }
  
  // Iterate over the array of players
  for(var i = 0; i < onepixelout_players.length; i++) {
    
    try {
  
    // If this player id is not the playerID that is starting then close it
      if(onepixelout_players[i] != playerID) {
        document.getElementById(onepixelout_objects[i]).SetVariable('closePlayer', 1);
      }
      else {
        document.getElementById(onepixelout_objects[i]).SetVariable('closePlayer', 0);
      }
    } catch( errorObject ) {
     // Trap any errors
    }
  }
}


// Get object and playerIDs of onepixelout players
function onepixelout_getPlayers() {

  //Initialize a counter
  i = 0;
  
  // Iterate over all onepixelout players
  $('.onepixelout > [id^=swf]').each(function () {
    
    // Collect the div ids, turn them in to object ids, and store them
    onepixelout_objects[i] = $(this).attr('id');
    
    // Extract the flashvars string
    flashvars = $('#' + onepixelout_objects[i] + ' > param').filter('[name=flashvars]').attr('value');

    // Find out where playerID appears in the value
    index1 = flashvars.indexOf('playerID');
    
    // Find out where the first ampersand is in the value
    index2 = flashvars.indexOf('&');
    
    // The playerID variable is this substring so store it
    onepixelout_players[i++] = flashvars.substring(index1 + 9, index2);
  
  });
  
}
;

