/*
 *
 * Copyright (c) 2008 George Bonnes (george@olm1.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Version 1.0.1
 *
 * $LastChangedDate$
 * $Rev$
 *
 */

function activate_main_nav_menu_item() {
	current_url = new String(window.location);
    current_url_filename = new String;
    current_url_filename = current_url.slice(current_url.lastIndexOf('/') + 1);
    //alert('current_url_filename ' + current_url_filename);
    current_url_filename_base = new String;
    if (current_url_filename.indexOf('-') != -1) {
    	//alert('has - in filename');
    	current_url_filename_base = current_url_filename.slice(0, current_url_filename.indexOf('-'));
    } else {
    	current_url_filename_base = current_url_filename.replace('.html', '');
    }
    //alert('base: ' + current_url_filename_base);
    $('#nav_main a').each(function() {
    	//alert($(this).attr('href'));
    	link_href = $(this).attr('href');
    	link_filename = link_href.slice(link_href.indexOf('/') + 1);
    	link_filename = link_filename.replace('.html', '');
    	//alert('link_filename ' + link_filename);
    	if (link_filename == current_url_filename_base) {
    		$(this).addClass('active');
    	}
    }); 	
}

function activate_subnav_menu_item() {
	current_url = new String(window.location);
	current_url_filename = new String;
    current_url_filename = current_url.slice(current_url.lastIndexOf('/') + 1);
    current_url_filename_base = new String;
    current_url_filename_base = current_url_filename.replace('.html', '');
    //alert('base: ' + current_url_filename_base);
    $('#subnav a').each(function() {
    	link_href = $(this).attr('href');
    	link_filename = link_href.slice(link_href.indexOf('/') + 1);
    	link_filename = link_filename.replace('.html', '');
    	//alert('link_filename ' + link_filename);
    	if (link_filename == current_url_filename_base) {
    		$(this).addClass('active');
    	}
    });
}


$(document).ready(function() {
    // initialize our loading div to listen for $.ajax broadcasts
    $("#loading").bind("ajaxSend", function(){
        $("#loading").centerElement()
                     .vCenterElement()
                     .jqmShow();
     }).bind("ajaxComplete", function(){
         if (ajax_error == 0) {
            $("#loading").jqmHide();
         }
     });            
     
     $("#loading").jqm({overlay: 30, trigger: false});
     
     $('.hide_on_load').css('display', 'none');
     $('.show_on_load').css('display', 'block');
     
     // main navigation rollovers
     $("#nav_main a").hover(function () {
             $(this).css('background-image', 'url(/img/Image/layout_elements/nav1.jpg)')
                     .css('color', '#FFF'); 
         }, 
         function () { 
         	$(this).css('background-image', 'url(/img/Image/layout_elements/nav2.jpg)')
             .css('color', '#000'); 
         });

    // activate main menu tab based on the current page url
     activate_main_nav_menu_item();
     
     activate_subnav_menu_item();
    
     
    return false;
    
});  // end $(document).ready()





