YAHOO.namespace('example.anim');

// [TALIB]
// This function added to facilitate ease of finding display area when
// new content is added
function getContentAreaHeight( defaultHeight ) {
	var cah = document.getElementById('contentDisplayArea').offsetHeight ;
	if( cah < defaultHeight ) 
		cah = defaultHeight ;
	return cah ;
}


function checkContentArea() {
var expandHeight = document.getElementById('expand').offsetHeight ; ;
if( expandHeight > 0 ) {
// If the height is greater than 0, then we need to set the size
// of the content area to the new height and then call
// expandAnim to redraw the window
var windowHeight = getContentAreaHeight( 50 ) ;
expandAnim = new YAHOO.util.Anim('expand', { height: {to: windowHeight} }, 0.2 );
expandAnim.animate();
}
}

YAHOO.example.anim.init = function() {

 	var isOpen = false;
    // Get size of content area
    // var gh = document.getElementById('contentDisplayArea').offsetHeight;
    var gh = getContentAreaHeight( 50 ) ;
    // If main Content Display area is small, set height to default value
    // this will help to ensure any related links are displayed
    if (gh < 50){
        gh = 50;
    }
    var expandAnim = new YAHOO.util.Anim('expand', { height: {to: gh} }, 0.2 );
    //expand animation speed
    expandAnim.duration = 0.9;
	var collapseAnim = new YAHOO.util.Anim('expand', { height: {to: 0} }, 0.2 );
    //collapse animation speed
    collapseAnim.duration = 0.5;

	var doTransition = function(e) {

		// [TALIB]
		// By placing this here, we enable the height of the box to be changed
		// each time the user clicks on one of the Flash movie links		
		var instContentHeight = getContentAreaHeight( 50 ) ;
		expandAnim = new YAHOO.util.Anim('expand', { height: {to: instContentHeight} }, 0.2 );

        //the expand/collapse bar background image must change on expand/collapse
        //due to the design.
        //Set the variables here for the open/closed state AND the path to the image directory
        var openImage = 'expand_collapse_bar-open-28px.gif'; // Image shown when open state
        var closedImage = 'expand_collapse_bar-closed-28px.gif'; //image shown when closed state
        var imagePath = '/images/'; //path to image from HTML file

		if (isOpen) {
            // Check is related clocks are on page. If so, hide.
            if(document.getElementById('relatedBlocks')) {
            document.getElementById('relatedBlocks').style.display = 'none';
            }
			collapseAnim.animate();
			isOpen = false;
            document.getElementById('expandLink').innerHTML = 'Click here to see more information';
            document.getElementById('expandControl').style.backgroundImage = 'url('+imagePath+closedImage+')';
            document.getElementById('bottomBorder').style.display = 'none';
		} else {
            // Check is related clocks are on page. If so, show.
            if(document.getElementById('relatedBlocks')) {
            document.getElementById('relatedBlocks').style.display = 'block';
            }
			expandAnim.animate();
			isOpen = true;
            document.getElementById('expandLink').innerHTML = 'Click here to hide';
            document.getElementById('expandControl').style.backgroundImage = 'url('+imagePath+openImage+')';
            document.getElementById('bottomBorder').style.display = 'block';
		}

		return false;
	}
    //Create a privlidged function that can be called by the flash
    this.exposeContent=function(){
					doTransition('expandLink');
	   }

	YAHOO.util.Event.addListener('expandLink', 'click', doTransition);
}

YAHOO.util.Event.addListener(window, 'load', YAHOO.example.anim.init);

