//
// Tooltip functionality
//
$ektron.fn.hoverbox = function(options) {
    if (options == undefined) {
		options = '';	
	}
	var settings = $ektron.extend({
        id: 'tooltip' + options,
        top: 0,
        left: 15
    });

    var handle;

    function tooltip(event) {
        if ( ! handle) {
            // Create an empty div to hold the tooltip
            if (options == '2') {
			handle = $ektron('<div style="position:absolute" id="tooltip2"></div>').appendTo(document.body).hide();				
			} else if (options == 'small'){
			handle = $ektron('<div style="position:absolute" id="tooltipSmall"></div>').appendTo(document.body).hide();		
			} else if (options == 'auto'){
			handle = $ektron('<div style="position:absolute" id="tooltipAuto"></div>').appendTo(document.body).hide();				
			} else {
			handle = $ektron('<div style="position:absolute" id="'+settings.id+'"></div>').appendTo(document.body).hide();
			}
        }

        if (event) {
            // Make the tooltip follow a cursor
            handle.css({
                top: (event.pageY - settings.top) + "px",
                left: (event.pageX + settings.left) + "px"
            });
        }

        return handle;
    }

    this.each(function() {
        $ektron(this).hover(
            function(e) {
                $ektron(this).children().attr("alt","").attr("title", ""); //remove alt tags if any images used for tooltip
				if (this.title) {
                    // Remove default browser tooltips
                    this.t = this.title;
                    this.title = '';
                    this.alt = '';
                    tooltip(e).html(this.t).fadeIn('fast');
                }
            },
            function() {
                if (this.t) {
                    this.title = this.t;
                    tooltip().hide();
                }
            }
        );

        $ektron(this).mousemove(tooltip);
    });
};

//
// on page ready
//
$ektron().ready(function() { 
//
// Alternate table rows
//
$ektron("table.generalAlternateRows tr:nth-child(odd)").addClass("rowOdd");

//
// Break out of iFrames
if (top.location!= self.location) {top.location = self.location.href}
//

//
// Expandable/Collapsible areas
//
	// Mark as collapsed button
	function markExpandable() {
		$ektron(this).removeClass("buttonExpand");
		$ektron(this).removeClass("buttonClose");
		$ektron(this).addClass("buttonClose");
		// Footer fix for IE6
		$ektron("#footer").css({position: "absolute", top: ($ektron("#container").height() - 120)});
	}

	// Mark as expandable button
	function markCollapsed() {
		$ektron(this).removeClass("buttonClose");
		$ektron(this).addClass("buttonExpand");
		// Footer fix for IE6
		$ektron("#footer").css({position: "absolute", top: ($ektron("#container").height() - 120)});
	}
	
	// The setup
	$ektron(".collapsible.closed").children().not(".toggleCollapsible").hide();
	$ektron(".collapsible.opened").children().show();

	$ektron(".collapsible.closed > .toggleCollapsible").each(function() {
		markCollapsed.call($ektron(this));
	});
	
	$ektron(".collapsible.opened > .toggleCollapsible").each(function() {
		markExpandable.call($ektron(this));
	});

	// on Click handler
	$ektron(".collapsible > .toggleCollapsible").click(function() {
		$ektron(this).parent().children().not(".toggleCollapsible").toggle();
			if ($ektron(this).parent().children().not(".toggleCollapsible").is(":hidden")) {
				markCollapsed.call($ektron(this));
			} else {
				markExpandable.call($ektron(this));
			}
 	});
	
//
// SCORECARD IMAGE REPLACEMENT
//
//$ektron(".scorecard td:contains(Jane)").wrap("<span class='test'></span>");
//$ektron(".scorecard").find("td:contains(Jane)").wrap("<span class='test'></span>");
$ektron(".scorecard").find("td:contains([increasing])").addClass("trendImageHolder").html('<img src="/img/ico_trend_increasing.png" class="trendImage tooltipSmall" width="22" height="22" alt="increasing" title="Increasing - this trend is worsening" />');
$ektron(".scorecard").find("td:contains([decreasing])").addClass("trendImageHolder").html('<img src="/img/ico_trend_decreasing.png" class="trendImage tooltipSmall" width="22" height="22" alt="decreasing" title="Decreasing - this trend is good" />');
$ektron(".scorecard").find("td:contains([no change])").addClass("trendImageHolder").html('<img src="/img/ico_trend_nochange.png" class="trendImage tooltipSmall" width="22" height="22" alt="Little or no change" title="Little or no change" />');
$ektron(".scorecard").find("td:contains([requires monitoring])").addClass("trendImageHolder").html('<img src="/img/ico_trend_monitoring.png" class="trendImage tooltipSmall" width="22" height="22" alt="Little or no change - requires monitoring" title="Little or no change - the trend requires monitoring" />');
$ektron(".scorecard").find("td:contains([not available])").addClass("trendImageHolder").html('<img src="/img/ico_transparent.gif" class="trendImage tooltipSmall" width="22" height="22" alt="Not available" title="Trend information not available" />');

$ektron(".scorecard").find("td:contains([within target])").addClass("trendImageHolder").html('<img src="/img/ico_trend_green.png" class="trendImage tooltipSmall" width="22" height="22" alt="increasing" title="Within target" />');
$ektron(".scorecard").find("td:contains([outside target])").addClass("trendImageHolder").html('<img src="/img/ico_trend_red.png" class="trendImage tooltipSmall" width="22" height="22" alt="increasing" title="Outside target" />');
$ektron(".scorecard").find("td:contains([requires monitoring])").addClass("trendImageHolder").html('<img src="/img/ico_trend_yellow.png" class="trendImage tooltipSmall" width="22" height="22" alt="increasing" title="Requires monitoring" />');

//
// TOOLTIPS
//
$ektron(".tooltip").hoverbox();
$ektron(".tooltip a").hoverbox();
$ektron(".tooltip2").hoverbox("2");
$ektron(".tooltipSmall").hoverbox("small");
$ektron(".tooltipAuto").hoverbox("auto");
$ektron("acronym").hoverbox();

//
// ENLARGE BUTTON
//

$ektron("a.showBtnEnlarge").each(function() {
	$ektron(this).css("height", function() {
		return $ektron(this).children("img").height() + "px";
		});
	
		$ektron(this).css("width", function() {
		return $ektron(this).children("img").width() + "px";
		});

	$ektron(this).prepend('<div class="btnEnlarge"></div>');
	});



});

//
// CMS BREADCRUMB OVERRIDES FOR FRENCH ACCENTS
//

$ektron("#menubreadcrumbs a[title*=Salle des medias]").html("Salle des m&eacute;dias");
$ektron("#menubreadcrumbs a[title*=Soins de sante dans votre communaute]").html("Soins de sant&eacute; dans votre communaut&eacute;"); 
$ektron("#menubreadcrumbs a[title*=Cybersante]").html("Cybersant&eacute;"); 
