/* 
 *  careersglobal.js
 *  @purpose: main js file for pages created using careers-global templates under edfenergy.com site
 *  @date:Nov, 2009
 *  @requires: prototype1602.js - this file must be included in the page beforehand
 *
 */


           document.observe("dom:loaded", function() {

                   /*
                    * Attaches event listener for the home page tab option clicks
                    */
                   var n = 0 ; //count of tab-heading number
                   var anodes =  $$('#home-page-highlights .hph-head li a');
                   
                   if(anodes){
                       //will come here, only if we are on the home page
                        $A(anodes).each(function(node){
                                node.observe('click',respondToHomeTabClick.bindAsEventListener(this,n));
                                n++;
                        });
                   }


                   /*
                    * Attach event listener for 'print this page' link
                    */

                    var printButton = $$('#printthis a');
                    if(printButton){
                        printButton[0].observe('click',printThisPage.bindAsEventListener(this));
                        //printButton[0].observe('click', function(event){ ; });
                    }


            });


            /*
             * @purpose : Activates Page printing
             *
             */
             function printThisPage(event){
                 //alert('tada again');
                 window.print();
                 event.stop();
                 return false;
             }



            /*
             * @purpose: To respond to home page tab clicks and
             *           show the content of the tab clicked
             *           and make the clicked tab active
             */

            function respondToHomeTabClick(event,n) {
                     
                      //gets the element that was clicked
                      var elm = event.element(event);

                      //remove 'current' class from all the tab-headers
                      var tabs = $$('#home-page-highlights .hph-head li');
                      $A(tabs).each(function(nd){
                          nd.removeClassName('current');
                      });

                      // add 'current' class to the tab that has been clicked
                      elm.up().addClassName('current');

                      //show/hide the contents
                      var  tabscontent = $$('#home-page-highlights .hph-body div.tab-data');
                      var tabscount = $A(tabscontent).length;

                          for(var i = 0; i < tabscount ; i++){

                                tabscontent[i].removeClassName('visible');
                                if( i==n ) {
                                    tabscontent[i].addClassName('visible'); //make the content pane for the current tab active
                                }
                          }


                      //stop the default click action
                      event.stop();
                      return false;
             }


