/* ------------------------------------------------------
	DOCUMENT READY */
$(document).ready(function() {
    /* ------------------------------------------- *
     * What's New, Current News, Events Tabbed UI  *
     * ------------------------------------------- */
    // #newsAndEvents ul.tabs
    // #newsAndEvents ul.tabs li a
    // #newsAndEvents ul.tabs li a.active
    // #newsAndEvents .tab-panel
    // #newsAndEvents .tab-panel-active

    // Look for hash to set active, otherwise 1st tab is active w/ content...
    $('#newsAndEvents ul.tabs li a').each(function(i) {
        if (window.location.hash !== '') {
            if (window.location.hash == $(this).attr('href')) {
                $(this).addClass('active');
                $($(this).attr('href')).addClass('tab-panel-active');
            }
        } 
        else {
            if (i == 0) {
                $(this).addClass('active');
                $($(this).attr('href')).addClass('tab-panel-active');
            }
        }
        
        if ($(this).hasClass('uses-background')) $(this).html('<span class="hide">' + $(this).html() + '</' + 'span>');
    });
    
    // Assign click event.. 
    $('#newsAndEvents ul.tabs li a').click(function(e) {
        // Set all to inactive...
        $('#newsAndEvents ul.tabs li a').removeClass('active');
        $('#newsAndEvents .tab-panel').removeClass('tab-panel-active');
        
        // Set selection active...
        $(this).addClass('active');
        $($(this).attr('href')).addClass('tab-panel-active');
        $(this).blur();
        
        return(false);
    });

});

/* ------------------------------------------------------
	SERVICES MAP MAIN FLASH 
	
	1. Detects #mainFlash block load
	2. Detects if the user is on the home page - if so, loads the corresponding Flash in it's place.
	
	*/

$("#servicesMapFlash").ready(function () {

    var myDir = getURLDirectory();

    if (myDir.indexOf("services") > -1) {



        //	    var ignoredParams = { src: 1, bgcolor: 1 };
        //	    var params = String('src="/lib/swf/services/services_map.swf" quality="high" bgcolor="#ffffff" ').split(" ");
        //	    var swf = new SWFObject("/lib/swf/services/services_map.swf", "map", "564", "650", "9.0.0.0", "#ffffff");
        //	    swf.addParam("align", "middle");
        //	    for (var i = 0; i < params.length; i++) {
        //	        var paramName = params[i].split("=")[0];
        //	        var paramValue = params[i].split("\"")[1];

        //	        if (ignoredParams[paramName] != 1 && paramName != "") {
        //	            swf.addParam(paramName, paramValue);
        //	        }
        //	    }
        //	    swf.write("map");

        var flashvars = { xmlPath: "/services/diakon.xml" };
        var params = {}; //wmode: "transparent" };
        var attributes = {};
        swfobject.embedSWF("/lib/swf/services/services_map.swf", "servicesMapFlash", "644", "730", "9.0.0", "", flashvars, params, attributes);


    };
});


/* ------------------------------------------------------
	HOME PAGE MAIN FLASH 
	
	1. Detects #mainFlash block load
	2. Detects if the user is on the home page - if so, loads the corresponding Flash in it's place.
	
	*/
	
$("#mainFlash").ready(function() {
	
	var myDir = getURLDirectory();
	
	if (myDir.indexOf("diakon.org") > -1) {
		var flashvars = {
			// Do Nothing
			xmlPath: "/lib/swf/home/xml/banners.xml",
			imgPath: "/lib/swf/home/images/"
		};
		var params = {
		  wmode: "transparent"
		};
		var attributes = {
		  id: "ExternalInterface",
		  name: "ExternalInterface"
		};
		
		swfobject.embedSWF("/lib/swf/home/homeFlash.swf", "mainFlash", "761", "297", "9.0.0", "", flashvars, params, attributes);
	};
});

/* ------------------------------------------------------
	HOME PAGE IMAGE FADER */
	
$(".slideshowWrapper").ready(function() {
    $(".slideshow").wrap("<a href=\"http://" + location.hostname + "/adoption/waitingchildren.asp?p=9.jpg\"></a>");
    $(".slideshow").cycle({
		// choose your transition type, ex: fade, scrollUp, shuffle, etc...
		fx: 'fade',
		timeout: 3200
	});
});


/* ------------------------------------------------------
	MENUS */
	
$("#primaryTopnav").ready(function() {
	if (window.attachEvent) {
		window.attachEvent("onload", tsMenus);	
	}
});


/* ------------------------------------------------------
	ACCORDION PANELS READY */
	
$("#accordionPanels").ready(function() {
	jQueryAccordion();
});


/* ------------------------------------------------------
	TABBED PANELS READY */
/*
var servicesDir = getURLDirectory();
if (servicesDir.indexOf("services") > -1) {
	$("#servicesTabs").ready(function() {
		var qs = String(getURLQueryString());
		var target = (qs.split("="))[1];
		jQueryTabbedPanels(target);
	});
}
*/
