    
    Event.observe(window, "load", function(){

        var teensFunDownloads = new PanelSet("ul.dots_downloads a", "div.rotator_downloads",true, true);
        var teensBooksFeatured = new PanelSet("ul.dots_featured a", "div.rotator_featured",true, true);
        var teensBooksSeries = new PanelSet("ul.dots_series a", "div.rotator_series",true, true);
        var teensHomeVideos = new PanelSet("ul.dots_videos a", "div.rotator_videos",true, true);
        var teensHomeNews = new PanelSet("ul.dots_news a", "div.rotator_news",true, true);        
        var teensHomeReading = new PanelSet("ul.dots_reading a", "div.rotator_reading",true, true);            
        var switchNested = new PanelSet("a.expand", "div.expander",false, false);
        var switchOne = new PanelSet("ul.tabs a", "div.rotator",false, false);
        var switchTwo = new PanelSet("ul.next_book_links a", "div.rotator_feature",false, false);
        var switchThree = new PanelSet("ul.next_book_links2 a", "div.rotator_feature2",false, false);        
        var kidsHome = new PanelSet("ul.next_book_links a", "div.rotator_books",false, false);
        var kidsHome = new PanelSet("ul.inline_tabs a", "div.rotator_kids_books",false, false);
        var utilityPanels = new PanelSet("div#utility_nav ul#rotators li a", "div.rotator_forms",false, false);
    });
    
    
    var PanelSet = Class.create();
        PanelSet.prototype = {
            initialize: function(links, items, randomize, automate) {
                this.links = $$(links);
                this.items = $$(items);
                if (this.items.length == 0 || this.links.length == 0) { // return false if links and items do not exist 
                    return;
                }
                for (var i=0; i < this.links.length; i++) {     // if link gets clicked
                    Event.observe(this.links[i], "click", this._linkClick.bindAsEventListener(this));
                }
                if (automate) {     // show different item every 3 seconds
                    this.interval = setInterval(function() {
                        this.showRandom();
                    }.bind(this), 3000);
                }
                if (randomize) {    // show random item
                    this.showRandom ();
                } else {    // show first item in array only
                    this.setItem(this.links[0]);
                }
            },
            _linkClick: function(e) {
                clearInterval(this.interval);   // clear timer once link is clicked
                var e = e || window.event;  // ie check
                Event.stop(e);  // stop event
                var link = Event.findElement(e, 'a'); 
                this.setItem(link); // show item             
            },
            
            hideAll: function() {
                for (var i=0; i < this.items.length; i++) { // hide all items
                    this.items[i].style.position = "absolute";
                    this.items[i].style.top = "-50001px";
                }    
            },
            
            showRandom: function() {
                var showItem = this.links[Math.floor(Math.random()*this.links.length)];  // find random item
                this.setItem(showItem);     // show random item                                            
            },
            
            classOff: function() {
                for (var i=0; i < this.links.length; i++) {
                    this.links[i].parentNode.className = " off";    // change link parent item to off
                }   
            },
            
            setItem: function(oLnk) {
                this.classOff();    // turn all links off
                oLnk.parentNode.className = "on";   // change this specific link parent to "on"
                var relAttr = oLnk.getAttribute("rel"); // get link rel attribute
                this.hideAll();     // hide all items                    
                for (var i=0; i < this.items.length; i++) {
                    if (this.items[i].hasClassName(relAttr)) {  // if item class name is equal to link rel then show item
                        this.items[i].style.position = "static";
                        break;
                    } 
                }              
            }
            
        }
        
  
    
function navHover() {
	if(!document.getElementById("main_nav")) {
        return false;
    }
	var	navRoot = document.getElementById("main_nav");
	for (i=0; i<navRoot.childNodes.length; i++) {
	    node = navRoot.childNodes[i];
	    if (node.nodeName=="LI") {
		    node.onmouseover=function() {
			    this.className =" over";
		    }
		    node.onmouseout=function() {
			    this.className =" out";
		    }
	    }
    }
}
	
Event.observe(window, "load", navHover);
Event.observe(window, 'load', safariShadowFix, false);
Event.observe(window, 'load', _popEventTracker, false);
            		
function safariShadowFix() {
    if (navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
        if(!document.getElementById("bottom_shadow")) {
            return false;
        }
        if(!document.getElementById("content")) {
            return false;
        }
        
        /* For safari we are moving shadow to different node, due to issues with accordion slider and 
        expanding content pushing shadow out of content area */
        
        /* Get default location from shadow and remove it */    
        var content = document.getElementById("content");
        var shadowNested = document.getElementById("bottom_shadow"); 
        var throwawayNode = content.removeChild(shadowNested);
        
        
        /* Move shadow to footer, so content length does not effect positioning */
        var footerLocale =  document.getElementById("footer"); 
        var newLocation = footerLocale.appendChild(shadowNested);
        shadowNested.style.bottom = "52px";     /* we have to re-position for the new node placement */
        shadowNested.style.right = "260px";
     
    }
 }
 
 function _popEventTracker(p_media, p_object, p_action, p_label, p_value, p_target) {
            var p_source = document.location.pathname+document.location.search+document.location.hash;
                var p_media = p_media;
                var p_object = p_object;
                var p_action = p_action;
                var p_label = p_label;
                var p_value = p_value;
                var p_target = p_target;
                var reportString =
            encodeURI('/object='+p_object+'/action='+p_action+'/label='+p_label+'/value='+p_value+'/target='+p_target+'/source='+p_source);
                
            //test call to urhcinTracker
            urchinTracker(reportString);
            //console.log(reportString);
  }
  
  function switchAbrigedField(elem) 
  {
    var abridgedNode = document.getElementById("uxAbridged");
    var unAbridgedNode = document.getElementById("uxUnAbridged");
    
    if(elem == "uxAbridged" && abridgedNode.checked == true)
    {
        abridgedNode.checked = true;
        unAbridgedNode.checked = false;
    }
    else if (elem == "uxUnAbridged" && unAbridgedNode.checked == true)
    {
        abridgedNode.checked = false;
        unAbridgedNode.checked = true;

    }
   
  }
  
  function SplitOpenBookAjaxResponse(response)
  { 
     var root = document.createElement("div");	
     root.innerHTML = response;

     var allChilds = root.childNodes;        
     // Loop through all the child nodes and check for both Widget and Readexcerpt container	
     for(var i = 0; i < allChilds.length; i++) {            
       if (allChilds[i].id && allChilds[i].id == "ConShareWidget") 
       {
        var share = document.getElementById('share_widget');
        share.innerHTML = allChilds[i].innerHTML;
         alert(allChilds[i].innerHTML);
       }
       
       if (allChilds[i].id && allChilds[i].id == "ConReadExcerpt") 
       {
        var share = document.getElementById('read_excerpt');
        share.innerHTML = allChilds[i].innerHTML;
         alert(allChilds[i].innerHTML);
       }
     }
 }