$(document).ready(function(){


//------------------------------------//
// Primary Navigation
//------------------------------------//
    //Initialize Primary Nav
    $('ul.nav').superfish();
    
    //fix the top nav
    $('.vertical ul li').eq(1).addClass("topBorder");
	//take the margin off of the last list-item
	//$("ul.navist li:last-child").addClass("last");
	
//------------------------------------//


//------------------------------------//
// Set up the Slider on the Home Page 
//------------------------------------//

	$('DIV.drawers').accordion({
		header: 'H3.d-handle',		
		selectedClass: 'open',
		event: 'mouseover',
		animated: 'easeslide',
		fillSpace: false		
  	});
	
//------------------------------------//


 //take the margin off of the last list-item on each row
$("ol.olHotTopics li:nth-child(3n)").addClass("last");



//------------------------------------//
// Set up the Random Images on the Home Page 
//------------------------------------//
    
    $.ajax({
    type: "GET",
    //url: "/BCHA2/XML/HomePageImages.xml", //Localhost
    url: "/XML/HomePageImages.xml", 
    dataType: "xml",
    success: function(xml) {

            //get elements      
            var images = $("image", xml)
                            
            //create a random number within the range of our image count
            var now=new Date();
            var num=((now.getSeconds()) % images.length);
                                            
            //grab all the data we need.
            var imageUrl = images.eq(num).attr('url')
            var imageTitle = images.eq(num).attr('title')
            var imageID = images.eq(num).attr('id')
            
            //set up the photo
            $(".randomPhoto").attr({
                src: imageUrl,
                alt: imageTitle                    
            }).fadeIn("normal")                           
        }
    });




//------------------------------------//
// Special Actions for IE6 only
//------------------------------------//
    if (!(window.XMLHttpRequest)) {
    
        //fix the background image on the sub page
        $("#innerContentWrap.subPage").css({
        'background-image' : 'url(/images/bgSubPageInnerContent.gif)', //----------------------------for dev&prod
        //'background-image' : 'url(/bcha2/images/bgSubPageInnerContent.gif)',
        'background-repeat' : 'repeat-y'
        });
    }
//------------------------------------//

//------------------------------------//
// Photo Gallery
//------------------------------------//
    if ($('#PhotoGallery').size() != 0) {
        var gallery = $('#PhotoGallery').galleriffic('#navigation', {
            delay:                2000,
            numThumbs:            5,
            enableBottomPager:    true,
            enableTopPager:       false,
            imageContainerSel:    '#slideshow',
            controlsContainerSel: '#controls',
            nextPageLinkText:     '&raquo;',
            prevPageLinkText:     '&laquo;',
            playLinkText:         '',
            prevLinkText:         '&laquo; Previous',
            nextLinkText:         'Next &raquo;',
            preloadAhead:         5
        });
    	
        gallery.onFadeOut = function() {
            $('#details').fadeOut('fast');
        };
    	
        gallery.onFadeIn = function() {
            $("ul.thumbs li:nth-child(5n)").addClass("lastthumb");
            $('#details').fadeIn('fast');
    		
        };
		
    }

//------------------------------------//
// Icons for various Links
//------------------------------------//
    var iconPath = "/images/icons/"; //----------------------------for dev&prod
	//var iconPath = "/bcha2/images/icons/";
	$("#twoColRight a[@href*=mailto]").append('<img class="linkIcon" src="' + iconPath + 'iconEmail.gif" alt="Send Email" width="16" />');
	$("a.pdf").append('<img class="linkIcon" src="' + iconPath + 'iconPDF.gif" alt="PDF Download" height="16" width="16" />');
	//$("a[@href$=.zip]").append('<img class="linkIcon" src="' + iconPath 'iconZip.gif" alt="ZIP File Download" height="16" width="16" />');
	//$("a[@href$=.doc]").append('<img class="linkIcon" src="' + iconPath 'iconDOC.gif" alt="Word Document Download" height="16" width="16" />');
	//$("a[@href$=.ppt]").append('<img class="linkIcon" src="' + iconPath 'iconPPT.gif" alt="PowerPoint Download" height="16" width="16" />');
	//$("a[@href$=.xls]").append('<img class="linkIcon" src="' + iconPath 'iconXLS.gif" alt="Excel Download" height="16" width="16" />');
	
//------------------------------------//


//------------------------------------//
// Tabs Initialization
//------------------------------------//
    $('#tabBox-1 > ul').tabs();
    $('#tabBox-2 > ul').tabs();
    $('#tabBox-3 > ul').tabs();
    //$('#tabBox-4 > ul').tabs();
    //$('#tabBox-5 > ul').tabs();
//------------------------------------//
    
//------------------------------------//
// Show/Hide Functionality
//------------------------------------//
    // Hide all div's with the class "shBox"
	$('.shBox').hide();
	
	//$("a.showHide").click(function(){ 
	//    var target = $($(this).attr('href')) 
	//    $("div.shBox:visible").not(target).slideUp(); 
	//    target.slideToggle(); 
	//}); 
	
	// Create show/hide functionality
	// Desc: Basically, this attaches a toggle onClick event to each
	// 'a' tag that has the class 'showHide'
	// The 'a' tag's HREF attribute value is the ID of the
	// element to be shown/hidden.
	// "shTitle" givs us a nice "expand/collapse" arrow right before the 'a' tag
	$('a.showHide').toggle(
	    function(){
		    var e = $(this)
		    if (e.hasClass("shTitle")){
		        e.addClass("shTitleOpen")
		    }
           // Fade in the selected element
			$(e.attr('href')).fadeIn("slow")
		},
		function(){
		    var e = $(this)
		    if (e.hasClass("shTitle")){
		        e.removeClass("shTitleOpen")
		    }
			// Fade out the element
			$(e.attr('href')).fadeOut("fast")
		}
    );
	
//------------------------------------//

});




