var bookmarkedSection;
var querySection;   
var initialSection;

//function loadSection(section) {   
//    //alert(section);	
//		if(section == 0) var url = "index.php?controller=Block1"; 
//		else var url = "index.php?controller=Block1&sec="+section; 
//  
//	    function successHandler(obj) {   
//        // Use the response...   
//    	    /*YAHOO.util.Dom.get("block1").innerHTML = obj.responseText; */  
//		
//	    }   
//  
//    	function failureHandler(obj) {   
//        	 // Fallback...   
//	         location.href = "?sec=" + section;   
//    	}   
//   
//	     YAHOO.util.Connect.asyncRequest("GET", url,   
//    		 {   
//             success:successHandler,   
//             failure:failureHandler   
//	         }   
//    	);	
//}   

function loadSection2(section) {   
    //alert(section);
	if(section == 0) var url = "index.php?controller=Block2"; 
	//else var url = "block2.php?sec="+section; 
	else{
		numCheckboxes = 0;
		var url = "index.php?controller=Block2&sec="+section; 
	}
  
    function successHandler(obj) {   
        // Use the response...   
        YAHOO.util.Dom.get("block2").innerHTML = obj.responseText;   
		
    }   
  
    function failureHandler(obj) {   
         // Fallback...   
         location.href = "?sec=" + section;   
     }   
   
     YAHOO.util.Connect.asyncRequest("GET", url,   
         {   
             success:successHandler,   
             failure:failureHandler   
         }   
    );   
}   

function initializeNavigationBar() {
    // Process links
    var anchors, i, len, anchor, href, section, currentSection;
    anchors = YAHOO.util.Dom.get("categoriesSection").getElementsByTagName("a");
    for (i = 0, len = anchors.length; i < len; i++) {
        anchor = anchors[i];
        YAHOO.util.Event.addListener(anchor, "click", function (evt) {
            href = this.getAttribute("href");
            section = YAHOO.util.History.getQueryStringParameter("sec", href) || "0";
            // If the Browser History Manager was not successfuly initialized,
            // the following call to YAHOO.util.History.navigate will throw an
            // exception. We need to catch it and update the UI. The only
            // problem is that this new state will not be added to the browser
            // history.
            //
            // Another solution is to make sure this is an A-grade browser.
            // In that case, under normal circumstances, no exception should
            // be thrown here.
            try {
                YAHOO.util.History.navigate("navbar", section);
            } catch (e) {
               /* loadSection(section);*/
				loadSection2(section);
            }
            YAHOO.util.Event.preventDefault(evt);
        });
    }

    // This is the tricky part... The window's onload handler is called when the
    // user comes back to your page using the back button. In this case, the
    // actual section that needs to be loaded corresponds to the last section
    // visited before leaving the page, and not the initial section. This can
    // be retrieved using getCurrentState:
    currentSection = YAHOO.util.History.getCurrentState("navbar");
   /* loadSection(currentSection);*/
	loadSection2(currentSection);
}

bookmarkedSection = YAHOO.util.History.getBookmarkedState("navbar");   
querySection = YAHOO.util.History.getQueryStringParameter("sec");   
initialSection = bookmarkedSection || querySection || "0";   

YAHOO.util.History.register("navbar", initialSection, function (state) {   
     // Load the appropriate section:   
     /*loadSection(state);  */
	 loadSection2(state);   
 });  

YAHOO.util.History.onReady(function () {
    initializeNavigationBar();
});

// Initialize the browser history management library.
try {
    YAHOO.util.History.initialize("yui-history-field", "yui-history-iframe");
} catch (e) {
    // The only exception that gets thrown here is when the browser is
    // not supported (Opera, or not A-grade) Degrade gracefully.
    // Note that we have two options here to degrade gracefully:
    //   1) Call initializeNavigationBar. The page will use Ajax/DHTML,
    //      but the back/forward buttons will not work.
    //   2) Initialize our module. The page will not use Ajax/DHTML,
    //      but the back/forward buttons will work. This is what we
    //      chose to do here:
    /*loadSection(initialSection);*/
	loadSection2(initialSection);
}