/********************************************************************
    File:   
        index.js
    Brief:  
        Implementation of JavaScript functionality 
        for the index.html page
    Dependencies:
        jquery-1.3.2.min.js     (jQuery library)
        jquery.easing.1.2.js    (jQuery library plugin)
        cufon-yui.js            (font replacement tool)         
    Author:
        DigitalCavalry
    Author URI:
        http://graphicriver.net/user/DigitalCavalry
*********************************************************************/

// alias to jQuery library, function noConflict release control of the $ variable 
// to whichever library first implemented it
var $j = jQuery.noConflict();

/**************************
    NEWS BAR CODE
**************************/

// time interval between news text change
var g_newsBarInterval = 4000;
// number of news determined dynamically
var g_newsCount = 0;
// current number of displayed news, start index from one
var g_actualNews = 1;
// handle to displayed news
var g_newsThis = null;

// Auto play function for news bar, is calling itself in some period time
function newsBarAutoPlay()
{
   // switch to next news
   g_actualNews = g_actualNews + 1;
   // check news range
   if(g_actualNews > g_newsCount)
   {
      // back to first news
      g_newsThis = $j(".newsBarNews:first");
      g_actualNews = 1;
   } else
   {
      // move to next news
      g_newsThis = $j(g_newsThis).next(".newsBarNews");
   }
   
   // fade down current news
   $j("#newsBarLink").fadeOut(100);
   $j("#newsBarText").fadeOut(100, 
        function(){
            $j("#newsBarText").html($j(g_newsThis).find(".text").html());
            var link = $j(g_newsThis).find(".link").html();
            $j("#newsBarLink").attr("href", link); 
            });
            
   // fade up new news
   $j("#newsBarText").fadeIn(1500);
   $j("#newsBarLink").fadeIn(1500);
   
   // set auto call in some time period
   setTimeout(newsBarAutoPlay, g_newsBarInterval);
} // end of function newsBarAutoPlay

// This function setup news bar, and is called only once then page is loaded
function setupNewsBar()
{
    // determining number of news to display
    g_newsCount = $j(".newsBarNews").length;
    // get handle to the first news
    g_newsThis = $j(".newsBarNews:first");
    // copying news text and link to newsBarText and newsBarLink
    $j("#newsBarText").html($j(g_newsThis).find(".text").html());
    $j("#newsBarLink").attr("href", $j(g_newsThis).find(".link").html()); 
    // set auto play for news
    setTimeout(newsBarAutoPlay, g_newsBarInterval);
} // end of function setupNewsBar


/***************************************
    ADDITIONAL CUFON FONT REPLACEMENT
****************************************/

function setupAdditionalCufonFontReplacement()
{
    Cufon.replace(".tabHeader", {fontWeight: 400});
    Cufon.replace(".tabsHeader", {fontWeight: 700});
     
    Cufon.replace(".accordionDescHeader", {fontWeight: 700});
    Cufon.replace("#servicesProductsHeader", {fontWeight: 300});
    Cufon.replace("#latestNewsHeader", {fontWeight: 300});
} // end of function setupAddCufonFontReplacement

/***************************************
    ACTION FOR LATEST NEWS FIELDS
****************************************/

function setupLatestNews()
{
    $j(".lastNews").hover(
        function()
        {
            $j(this).find(".lastNewsTitle").css("color", "#222");
        },        
        function()
        {
            $j(this).find(".lastNewsTitle").css("color", "#444");
        }
    );
} // end of function setupLatestNews


       

       
/***************************************
    MAIN CODE - CALL THEN PAGE LOADED
****************************************/
       
// binding action to event onload page
$j(document).ready(
    function()
    {

        // common.js
        setupGlobal();
        setupCommunityButtons();            
        setupToolTipText();
        setupSearchBox();
        setupCufonFontReplacement();
        setupSideBarMiniSlider();
        setupLinkLightBox();
        setupSidebarTabsPanel();
        setupLoadingAsynchronousImages();
        setupToolTipImagePreview();
        setupTextLabelImagePreview();
        setupFaderMoverSlider();   
        // this file
        setupNewsBar();
        setupTabs();
        setupLatestNews();
    }
);
