customSubmenuTimer      = null;
customToggleTimer       = null;
customCurrentSubmenu    = null;
customCurrentSubSubMenu = null;
contactPage             = false;
infoPage		        = false;
newsfeed_link           = '';
flash_text              = ''; 
flash_movie             = 1;
hide_flash              = true;


function init() { 
    loadFlashVars(); // place flash
        
    customLeftCol      = gObj('content_left');
    customRightCol     = gObj('content_right');
    customLeftContent  = gObj('leftsideContent');
    customFlashNormal  = gObj('flash_normal');
    customFlashContact = gObj('flash_contact');
    customFlashHideBtn = gObj('hideFlashButton');
    customContactDiv   = gObj('contactdiv');
    customPageHeader   = gObj('heading');
    customTextContent  = gObj('textcontent');
    customTickerLink   = gObj('news_ticker_link');
    
    if(flash_movie==3) { // Hide "hide flash button" if distributor-flash
        if(customFlashHideBtn!=null) { customFlashHideBtn.style.display= 'none'; }
    }
    
    if(customTickerLink!=null && newsfeed_link!='') { customTickerLink.href = newsfeed_link; }
    
    if(contactPage) { //Contact page composition
        if(customLeftCol!=null)      { customLeftCol.style.display     = 'none'; }
        if(customFlashNormal!=null)  { customFlashNormal.style.display = 'none'; }
        if(customFlashHideBtn!=null) { customFlashHideBtn.style.display= 'none'; }
        if(customPageHeader!=null)   { customPageHeader.style.display  = 'none'; }        
        if(customFlashContact!=null) { customFlashContact.style.display= 'block'; }
        if(customContactDiv!=null)   { customContactDiv.style.display  = 'block'; }
        if(customTextContent!=null)  { customTextContent.className     = 'textContent_contact'; }
        for(i=1;i<=12;i++) {
            if(gObj('div_col2_'+i)!=null) { gObj('div_col2_'+i).className='contact_country_'+i; }
        }
        
    } else { // Hide left column if empty
        if(customLeftCol!=null && customLeftContent!=null) {
            if(customLeftContent.innerHTML.length==0) {
                customLeftCol.style.display='none';
                customLeftCol.style.width='0px';
                customRightCol.style.width='964px';
            }
        }
    }
    

    if(infoPage) { // hide flash
        if(customFlashNormal!=null)  { customFlashNormal.style.display = 'none'; }	
        if(customFlashHideBtn!=null) { customFlashHideBtn.style.display= 'none'; }
    }
}


function showDistributorByContinent(continent) {

    if(continent.length>0) {
        continent = continent+'';
        
        if(continent=='europe') {    continentDivId = 'div_col2_2' }
        if(continent=='america') {   continentDivId = 'div_col2_3' }
        if(continent=='africa') {    continentDivId = 'div_col2_4' }
        if(continent=='asia') {      continentDivId = 'div_col2_5' }
        if(continent=='australia') { continentDivId = 'div_col2_6' }
        
        if( gObj(continentDivId)!=null ) { 
            window.scrollTo( findPosX(gObj(continentDivId)), findPosY(gObj(continentDivId)) );
        }
    }
}


function loadFlashVars() {
    flPlaceholder = document.getElementById('flash_here');
    flNormalIe    = document.getElementById('flash_normal');
    flNormalFf    = document.getElementById('flash_normal_firefox');
    
    urlPrefix = '/includes/designs/design_44/graphics/';
    movieNameArr = new Array("API_intro_edited.swf","API_Sunrise.swf","API_Distributor.swf");
    
    if(flash_movie<=movieNameArr.length) {
        movieName = movieNameArr[flash_movie-1];
    } else {
        movieName = movieNameArr[0];
    }
    
    if(flPlaceholder!=null) {                
        flMovieName = urlPrefix+movieName+'?flash_text='+flash_text;
        
        movieHeight = 229;
        if(flash_movie==3) { movieHeight = 378; }
        
        flCode = '<object id="flash_normal" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="984" height="'+movieHeight+'" align="center" style="height: '+movieHeight+'px;">';
        flCode = flCode + '<param name="movie" value="'+flMovieName+'" />';
        flCode = flCode + '<param name="quality" value="high" />';
        flCode = flCode + '<param name="wmode" value="opaque" />';
        flCode = flCode + '<embed src="'+flMovieName+'" quality="high" width="984" height="'+movieHeight+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;P2_Platform=Win32&amp;P5_Language=English" align="Center" wmode="opaque" style="height: '+movieHeight+'px;" id="flash_normal_firefox" />';
        flCode = flCode + '</object>';
        
        flPlaceholder.innerHTML = flCode;
    }
}


hideAnimationStarted = false;

function clickHideFlash() {
    if(!hideAnimationStarted) { hideFlashAnimation(); }
}

function hideFlashAnimation() {
    hideAnimationStarted = true;

    customFlashHideBtn = gObj('hideFlashButton');
    if(hide_flash) {
        if(document.all) { flNormal = document.getElementById('flash_normal'); }
        else             { flNormal = document.getElementById('flash_normal_firefox'); }

        pixelMove = 10;
        flHeight = flNormal.style.height.substr(0,flNormal.style.height.indexOf("px"));

        if(flHeight<200 && flHeight>150)  { pixelMove = 8; }
        if(flHeight<150 && flHeight>100)  { pixelMove = 6; }
        if(flHeight<100 && flHeight>50)   { pixelMove = 4; }
        if(flHeight<50 && flHeight>20)    { pixelMove = 2; }
        if(flHeight<20 && flHeight>0)     { pixelMove = 1; }
        
        if(flNormal.style.visibility!='hidden' && flHeight>0) {
            if(flHeight>=pixelMove+1) {
                flNormal.style.height=flHeight-pixelMove+'px';
            } else {
                flNormal.style.height='1px';
                flNormal.style.visibility='hidden';
                if(customFlashHideBtn!=null) { customFlashHideBtn.style.display= 'none'; }
            }
            flashHideTimer = window.setTimeout("hideFlashAnimation()",25);
        }
    }
}


function toggleSubMenu(clickObj, toggleState, submenuId) {

    if(submenuId>0) {
        subAnim = gObj('submenu_animation');
        subDiv  = gObj('submenu_'+submenuId);
        nTicker = gObj('news_ticker_link');
    }
    
    switch(toggleState) {
    case 0: // Start closing timer
        toggleSubMenu(null,3,0);
        customToggleTimer = window.setTimeout("toggleSubMenu(null,2,0);",2000);
    break;
    case 1: // Show sub menu
        toggleSubMenu(null,3,0);
        window.clearTimeout(customSubmenuTimer);
        nTicker.style.display='none';        
        if(customCurrentSubmenu!=null) { customCurrentSubmenu.style.display='none'; }
        
        if(customCurrentSubSubMenu!=null) {
            customCurrentSubSubMenu.style.display='none';
            customCurrentSubSubMenu = null;
        }
            
        if(subDiv!=null) {        
            customCurrentSubmenu = subDiv;        
            if(subAnim.src.substr(subAnim.src.length-5,1)=='1') { subDiv.style.display=''; }
                
            if(subAnim.src.substr(subAnim.src.length-5,1)=='0') {
                subAnim.style.display='';
                subAnim.src = subAnim.src.substr(0,subAnim.src.length-5)+'1.gif';
                customSubmenuTimer = window.setTimeout("gObj('submenu_"+submenuId+"').style.display='';",500);
            }
        } else {
            toggleSubMenu(null,0,0);
        }
    break;
    case 2: // Hide submenu
        window.clearTimeout(customSubmenuTimer);
        nTicker.style.display='';
        if(subAnim.src.substr(subAnim.src.length-5,1)=='1') {
            if(customCurrentSubmenu!=null) { customCurrentSubmenu.style.display='none'; }
            if(subDiv!=null) { subDiv.style.display='none'; }
            customCurrentSubmenu = null;
            subAnim.src = subAnim.src.substr(0,subAnim.src.length-5)+'0.gif';
            customSubmenuTimer = window.setTimeout("gObj('submenu_animation').style.display='none';",500);
        }
    break;
    case 3: // Reset closing timer
        customToggleTimer = window.clearTimeout(customToggleTimer);
    break;
    
    case 4: // Show sub-sub menu
            if(subDiv==null) {
                if(customCurrentSubSubMenu!=null) {
                    customCurrentSubSubMenu.style.display='none';
                    customCurrentSubSubMenu = null;
                }
            } else {
                if(customCurrentSubSubMenu!=null) { customCurrentSubSubMenu.style.display='none'; }
                customCurrentSubSubMenu = subDiv;
                subDiv.style.display='';
                subDiv.style.left   = findPosX(clickObj)+'px';
                subDiv.style.top    = parseInt(findPosY(clickObj)+21)+'px';
            }
    break;
    }

}

languageDivStatus = 0;
function toggleLanguage() {
    if(languageDivStatus==1) { languageDivStatus=0; } else { languageDivStatus=1; }

    switch(languageDivStatus) {
    case 0: gObj('language_div').style.display='none'; break;
    case 1: gObj('language_div').style.display=''    ; break;
    }    
}


function gObj(objName) {
    return document.getElementById(objName);
}

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

