<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,5 @@
+* Fix issue where Opera gets confused by complex selectors in $$. [Paulo Pereira, Andrea Baron, jddalton] 
+
 * Fix for IE7 to access local files via Ajax.Request. Closes #8259. [hagen.seifert, jddalton]
 
 * Ensure CSS files have loaded before firing the dom:loaded event. [Diego Perini, jddalton]</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -22,6 +22,10 @@ var Selector = Class.create({
     if (!Prototype.BrowserFeatures.XPath) return false;
     
     var e = this.expression;
+    
+    // Opera's XPath engine breaks down when selectors are too complex
+    if (Prototype.Browser.Opera)
+      return false;    
 
     // Safari 3 chokes on :*-of-type and :empty
     if (Prototype.Browser.WebKit &amp;&amp; 
@@ -32,7 +36,7 @@ var Selector = Class.create({
     // the &quot;checked&quot; property from DOM nodes
     if ((/(\[[\w-]*?:|:checked)/).test(e))
       return false;
-
+      
     return true;
   },
   
@@ -461,9 +465,18 @@ Object.extend(Selector, {
     id: function(nodes, root, id, combinator) {
       var targetNode = $(id), h = Selector.handlers;
       if (!targetNode) {
-        // IE doesn't find elements by ID if they're not attached to the
-        // document.
-        if (Prototype.Browser.IE &amp;&amp; (root.sourceIndex &lt; 1 || root === document)) {
+        var needsToSearch = false;
+        // IE and Opera don't find elements by ID if they're not attached
+        // to the document.
+        if (Prototype.Browser.IE &amp;&amp; (root.sourceIndex &lt; 1 ||
+         root === document)) {
+          needsToSearch = true;        
+        } else if (Prototype.Browser.Opera &amp;&amp;
+         (root.compareDocumentPosition(document) &amp; 1) === 1) {
+          needsToSearch = true;   
+        }
+        
+        if (needsToSearch) {
           var nodes = root.getElementsByTagName('*');
           for (var i = 0, node; node = nodes[i]; i++) {
             if (node.id === id) {</diff>
      <filename>src/selector.js</filename>
    </modified>
    <modified>
      <diff>@@ -379,8 +379,8 @@ new Test.Unit.Runner({
     var wrapper = new Element(&quot;div&quot;);
     wrapper.update(&quot;&lt;table&gt;&lt;tr&gt;&lt;td id='myTD'&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;);
     new Selector('[id=myTD]').findElements(wrapper);
-    this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0]);
-    this.assertNotNullOrUndefined(wrapper.select('td')[0]);
-    this.assertNotNullOrUndefined(wrapper.select('#myTD')[0]);
+    this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0], &quot;[id=myTD]&quot;);
+    this.assertNotNullOrUndefined(wrapper.select('td')[0], &quot;td&quot;);
+    this.assertNotNullOrUndefined(wrapper.select('#myTD')[0], &quot;#myTD&quot;);
   }
 });
\ No newline at end of file</diff>
      <filename>test/unit/selector_test.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>69a4e3f5c1f0b1d1656e6ba6ce8f3c4f0dc29e66</id>
    </parent>
  </parents>
  <author>
    <name>Andrew Dupont</name>
    <email>prototype@andrewdupont.net</email>
  </author>
  <url>http://github.com/sstephenson/prototype/commit/6cdef71df792ae67ea1ecb4e69c64db5a3d03a0c</url>
  <id>6cdef71df792ae67ea1ecb4e69c64db5a3d03a0c</id>
  <committed-date>2008-06-24T11:29:37-07:00</committed-date>
  <authored-date>2008-06-24T11:29:37-07:00</authored-date>
  <message>Fix issue where Opera gets confused by complex selectors in $$. [#157 state:resolved]</message>
  <tree>168ebc912ee993ee1aa4d0605b9aa0654a6ae647</tree>
  <committer>
    <name>Andrew Dupont</name>
    <email>prototype@andrewdupont.net</email>
  </committer>
</commit>
