/*
Page-specific JavaScript -- CSS and HTML Design Patterns
    Dependent on chdp_common.js, chdp_popup.js, cssQuery.js, yahoo.js, event.js
    Version: 0.11

    Copyright (c) 2006, Michael Bowers. All rights reserved.
    Code licensed under the BSD License: http://cssdesignpatterns.com/license.txt

    yahoo.js, event.js, version: 0.11.4,
    Copyright (c) 2006, Yahoo! Inc. All rights reserved.
    Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt

        cssQuery, version 2.0.2 (2005-08-19)
        Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
        License: http://creativecommons.org/licenses/LGPL/2.1/
*/

function initPage() {

  /* MENU */
  assignEvent( 'click',     '*.menu',
                applyToDescendants, '*.dropdown', toggleClass, "hidden" );

  assignEvent( 'mouseover', '*.menu',
                applyToDescendants, '*.dropdown', removeClass, "hidden" );

  assignEvent( 'mouseout',  '*.menu',
                applyToDescendants, '*.dropdown', addClass,    "hidden" );



  assignEvent( 'mouseover', '*.menu li, *.menu h3',
                applyToThis, null, addClass,    "hover" );

  assignEvent( 'mouseout',  '*.menu li, *.menu h3',
                applyToThis, null, removeClass, "hover" );



  assignEvent( 'mouseover', '*.menu li.flyout-trigger',
                applyToDescendants, '> *.submenu', removeClass, "hidden" );

  assignEvent( 'mouseout',  '*.menu li.flyout-trigger',
                applyToDescendants, '> *.submenu', addClass,    "hidden" );

  /* ROLLUP */

/*
  assignEvent( 'click', '*.rollup-trigger',
                applyToChildrenOfAncestorWithClass, 'rollup',
                toggleClass, 'hidden'  );

  assignEvent( 'click', '*.rollup-trigger', applyToThis, null,
                toggleClass, 'rolledup'  );
*/

  /* TABS */

  assignEvent( 'click',     'ul.tabs li',
                applyToChildrenOfAncestorWithClass, 'tabs',
                removeClass, 'selected' );

  assignEvent( 'click',     'ul.tabs li',
                applyToThis, null, addClass, 'selected' );

  assignEvent( 'mouseover', 'ul.tabs li *.tab-label',
                applyToThis, null, addClass,    'hover' );

  assignEvent( 'mouseout',  'ul.tabs li *.tab-label',
                applyToThis, null, removeClass, 'hover' );


}

addEvent(window,'unload',purgeAllEvents);
addEvent(window,'load',initPage);



//ie mac fix for drop downs
         function menuFix1() {
         var sfEls = document.getElementById("topmenu").getElementsByTagName("li");
         for (var i=0; i<sfEls.length; i++) {
         sfEls[i].onmouseover=function() {
         this.className+=(this.className.length>0? " ": "") + "sfhover";
         }
         sfEls[i].onmouseout=function() {
         this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
         }
         }
         }



function menuFix() {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0; i<sfEls.length; i++) {
                sfEls[i].onmouseover=function() {
                this.className+=(this.className.length>0? " ": "") + "sfhover";
                }

                sfEls[i].onMouseDown=function() {
                this.className+=(this.className.length>0? " ": "") + "sfhover";
                }

                sfEls[i].onMouseUp=function() {
                this.className+=(this.className.length>0? " ": "") + "sfhover";
                }

                sfEls[i].onmouseout=function() {
                this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
                }
        }
}

                function getWindowHeight() {
                        var windowHeight = 0;
                        if (typeof(window.innerHeight) == 'number') {
                                windowHeight = window.innerHeight;
                        }
                        else {
                                if (document.documentElement && document.documentElement.clientHeight) {
                                        windowHeight = document.documentElement.clientHeight;
                                }
                                else {
                                        if (document.body && document.body.clientHeight) {
                                                windowHeight = document.body.clientHeight;
                                        }
                                }
                        }
                        return windowHeight;
                }

                function getStoryHeight() {
                        var storyHeight = 0;
                        if(document.getElementById('stories')){
                        storyHeight = document.getElementById('stories').offsetHeight;
                        }
                        else {
                                storyHeight = 0;
                                }
                        return storyHeight;
                }

                function getLeftHeight() {
                        var leftHeight = 0;
                        if(document.getElementById('nav')){
                        leftHeight = document.getElementById('nav').offsetHeight;
                        }
                         else {
                                leftHeight = 0;
                                }
                        return leftHeight;
                }

                function getRightHeight() {
                        var rightHeight = 0;
                         if(document.getElementById('extras')){
                        rightHeight = document.getElementById('extras').offsetHeight;
                         }
                         else {
                                rightHeight = 0;
                                }
                        return rightHeight;
                }

                function getDeckHeight() {
                        var deckHeight = 0;
                         if(document.getElementById('story2')){
                        deckHeight = document.getElementById('story2').offsetHeight;
                         }
                         else {
                                deckHeight = 0;
                                }
                        return deckHeight;
                }

                function getOtherHeight() {
                        var otherHeight = 0;
                         if(document.getElementById('otherNews')){
                       otherHeight = document.getElementById('otherNews').offsetHeight;
                         }
                         else {
                                otherHeight = 0;
                                }
                        return otherHeight;
                }

                function section1Height() {
                        var section1Height = 0;
                         if(document.getElementById('section1')){
                       section1Height = document.getElementById('section1').offsetHeight;
                         }
                         else {
                                section1Height = 0;
                                }
                        return section1Height;
                }

                function section2Height() {
                        var section2Height = 0;
                         if(document.getElementById('section2')){
                       section2Height = document.getElementById('section2').offsetHeight;
                         }
                         else {
                                section2Height = 0;
                                }
                        return section2Height;
                }

                function section3Height() {
                        var section3Height = 0;
                         if(document.getElementById('section3')){
                       section3Height = document.getElementById('section3').offsetHeight;
                         }
                         else {
                                section3Height = 0;
                                }
                        return section3Height;
                }

function place1Footer(){
var top=0;
var w=getWindowHeight();
var c1=section1Height();
var s=getStoryHeight();
var l=getLeftHeight();
var r=getRightHeight();
var footr='<div id="footer">';
footr += '<p class="copyright">Copyright &copy; 2008 &middot; Campaign for Press and Broadcasting Freedom &middot; All rights reserved</p>';
footr += '<ul class="inline"><li><a href="http://www.keywordsassociates.com">keywordsassociates.com</a> | </li><li><a href="http://www.bhd.co.uk">bhd.co.uk</a></li></ul></div>';
if(c1>=l && c1>=r) {
        top=2*c1;
        } else if(r>=l && r>=c1) {
                top = r*(0.12);
                } else {
                        top=l;
                        }
                      //alert("top:" +w +"|" +top);
                      top=top*(0.42);
document.write('<div style="clear:both;position:relative;z-index:80;left:0px;top:' +top +'px;">'  +footr  +'</div>');
}

function place2Footer(){
var top=0;
var w=getWindowHeight();
var c2=section2Height();
var s=getStoryHeight();
var l=getLeftHeight();
var r=getRightHeight();
var footr='<div id="footer">';
footr += '<p class="copyright">Copyright &copy; 2008 &middot; Campaign for Press and Broadcasting Freedom &middot; All rights reserved</p>';
footr += '<ul class="inline"><li><a href="http://www.keywordsassociates.com">keywordsassociates.com</a> | </li><li><a href="http://www.bhd.co.uk">bhd.co.uk</a></li></ul></div>';
if(c2>=l && c2>=r) {
        top=2*c2;
        } else if(r>=l && r>=c2) {
                top = r*(0.12);
                } else {
                        top=l;
                        }
                      //alert("top:" +w +"|" +top);
                      top=top*(0.42);
document.write('<div style="clear:both;position:relative;z-index:80;left:0px;top:' +top +'px;">'  +footr  +'</div>');
}

function place3Footer(){
var top=0;
var w=getWindowHeight();
var c3=section3Height();
var s=getStoryHeight();
var l=getLeftHeight();
var r=getRightHeight();
var footr='<div id="footer">';
footr += '<p class="copyright">Copyright &copy; 2008 &middot; Campaign for Press and Broadcasting Freedom &middot; All rights reserved</p>';
footr += '<ul class="inline"><li><a href="http://www.keywordsassociates.com">keywordsassociates.com</a> | </li><li><a href="http://www.bhd.co.uk">bhd.co.uk</a></li></ul></div>';
if(c3>=l && c3>=r) {
        top=2*c3;
        } else if(r>=l && r>=c3) {
                top = r*(0.12);
                } else {
                        top=l;
                        }
                     //alert("top:" +w +"|" +top);
                      top=top*(0.3);
document.write('<div style="clear:both;position:relative;z-index:80;left:0px;top:' +top +'px;">'  +footr  +'</div>');
}
