// class for managing the navigation through the web
function navigationManager() {
    var oNavigator = new Object;
    oNavigator.lang = "";
    oNavigator.news = null;
    oNavigator.currentSection = 'home'; // Home
    oNavigator.current2Section = "";
    oNavigator.current3Section = ""; 

    // function to invoke the navigation when the page is loaded
    oNavigator.init = function(lang,news) {
        var is_ie6 = (window.external &&typeof window.XMLHttpRequest == "undefined");
        if (is_ie6) {
            dialogIE6(lang);
        }
        var section = gup("section");
        this.lang = lang;
        this.navigateFirst(section,true);
        this.news = news;
    }

    // function to make the changes needed for the navigation through first level sections
    oNavigator.navigateFirst = function(section,loading) {
        if (loading) { // the initial state
            if (section==null || section=="") {
                section = 'home';
            }
            $(".firstLevel:eq(0)").attr('class','firstSelected');
            $(".contentWrapper:eq(0)").show();
            $(".sectorsHeader:eq(0)").show();
            $(".sectorsContent:eq(0)").show();
            this.currentSection = section;
            var block = $("#blockHome");
            block.attr("src","./images/elements/blockHomeOn_"+this.lang+".png");
        } else if (section!=this.currentSection || (this.currentSection=='sectors' && this.current2section!="")) {
            if (this.currentSection=='sectors' && this.current2Section!="") {
                $(".sectorsHeader:eq(0)").show();
                $(".sectorsContent:eq(0)").show();
                $(".openLevel:eq(0):first").attr("src","./images/elements/hTriangle.png");
                $(".openLevel:eq(0)").removeClass('openLevel');
                $(".secondSelected:eq(0)").attr('class','secondLevel');
                $(".visibleSector:eq(0)").hide();
                $(".visibleSector:eq(0)").removeClass("visibleSector");
                $(".visibleSector:eq(0)").hide();
                $(".visibleSector:eq(0)").removeClass("visibleSector");
                $(".sectorActiveImg:eq(0)").attr('class','sectorImg');
                switch (this.current2Section)  {
                    case 'environment':
                        $(".sectorImg:eq(0)").attr('id','imageEnvironment_'+this.lang);
                        break;
                    case 'industry':
                        $(".sectorImg:eq(1)").attr('id','imageIndustry_'+this.lang);
                        break;
                    case 'broadcast':
                        $(".sectorImg:eq(2)").attr('id','imageBroadcast_'+this.lang);
                        break;
                    default:
                        null;
                }
                if (this.current3Section!="") {
                    $(".openLevel:eq(0):first").attr("src","./images/elements/hTriangle.png");
                    $(".openLevel:eq(0)").removeClass('openLevel');
                    $(".thirdSelected:eq(0)").attr('class','thirdLevel');
                }
            }
            var selected = $(".firstSelected");
            if (selected.length!=0) {
                $(".firstSelected:eq(0)").attr('class','firstLevel');
            }
            $('#'+this.currentSection).hide();
            $('#'+section).toggle("slide",[],500);
            switch (this.currentSection)  {
                case 'home': 
                    var block = $("#blockHome");
                    block.attr("src","./images/elements/blockHomeOff_"+this.lang+".png");
                    block.attr("class","sectionBlock");
                    break;
                case 'company':
                    var block = $("#blockCompany");
                    block.attr("src","./images/elements/blockCompanyOff_"+this.lang+".png");
                    block.attr("class","sectionBlock");
                    break;
                case 'sectors':
                    var block = $("#blockSectors");
                    block.attr("src","./images/elements/blockSectorsOff_"+this.lang+".png");
                    block.attr("class","sectionBlock");
                    if (this.current2Section=="environment") {
                        $(".secondLevelWrapper:eq(0)").slideUp(500);
                        this.current3Section = "";
                    }
                    if (section!="sectors") {
                        $(".firstLevelWrapper:eq(0)").slideUp(500);
                    }
                    break;
                case 'news':
                    var block = $("#blockNews");
                    block.attr("src","./images/elements/blockNewsOff_"+this.lang+".png");
                    block.attr("class","sectionBlock");
                    break;
                case 'contact':
                    var block = $("#blockContact");
                    block.attr("src","./images/elements/blockContactOff_"+this.lang+".png");
                    block.attr("class","sectionBlock");
                    break;
                default:
                    var block = $("#blockClientArea");
                    block.attr("src","./images/elements/blockClientAreaOff_"+this.lang+".png");
                    block.attr("class","sectionBlock");
            }
            this.current2Section = "";
            switch (section)  {
                case 'home': 
                    var block = $("#blockHome");
                    block.attr("src","./images/elements/blockHomeOn_"+this.lang+".png");
                    block.attr("class","activeSectionBlock");
                    block.unbind("mouseover");
                    block.unbind("mouseout");
                    $(".firstLevel:eq(0)").attr('class','firstSelected');
                    this.currentSection = section;
                    break;
                case 'company':
                    var block = $("#blockCompany");
                    block.attr("src","./images/elements/blockCompanyOn_"+this.lang+".png");
                    block.attr("class","activeSectionBlock");
                    block.unbind("mouseover");
                    block.unbind("mouseout");
                    $(".firstLevel:eq(1)").attr('class','firstSelected');
                    this.currentSection = section;
                    break;
                case 'sectors':
                    var block = $("#blockSectors");
                    block.attr("src","./images/elements/blockSectorsOn_"+this.lang+".png");
                    block.attr("class","activeSectionBlock");
                    block.unbind("mouseover");
                    block.unbind("mouseout");
                    $(".sectorsHeader:eq(0)").addClass("visibleSector");
                    $(".sectorsContent:eq(0)").addClass("visibleSector");
                    $(".firstLevel:eq(2)").attr('class','firstSelected');
                    $(".firstLevelWrapper:eq(0)").slideDown(500);
                    this.currentSection = section;
                    break;
                case 'news':
                    this.news.reset(this.lang);
                    var block = $("#blockNews");
                    block.attr("src","./images/elements/blockNewsOn_"+this.lang+".png");
                    block.attr("class","activeSectionBlock");
                    block.unbind("mouseover");
                    block.unbind("mouseout");
                    $(".firstLevel:eq(3)").attr('class','firstSelected');
                    this.currentSection = section;
                    break;
                case 'contact':
                    var block = $("#blockContact");
                    block.attr("src","./images/elements/blockContactOn_"+this.lang+".png");
                    block.attr("class","activeSectionBlock");
                    block.unbind("mouseover");
                    block.unbind("mouseout");
                    $(".firstLevel:eq(4)").attr('class','firstSelected');
                    this.currentSection = section;
                    break;
                default:
                    var block = $("#blockClientArea");
                    block.attr("src","./images/elements/blockClientAreaOn_"+this.lang+".png");
                    block.attr("class","activeSectionBlock");
                    block.unbind("mouseover");
                    block.unbind("mouseout");
                    $(".firstLevel:eq(5)").attr('class','firstSelected');
                    this.currentSection = section;
            }
        }
    }

    // function to make the changes needed for the navigation through second level sections
    oNavigator.navigateSecond = function(section) {
        if (this.current2Section!=section || (this.current2Section=="environment" && this.current3Section!="" )) {
            if (this.current2Section=="") {
                $(".sectorsHeader:eq(0)").hide();
                $(".sectorsContent:eq(0)").hide();
                $(".firstSelected:eq(0)").addClass('openLevel');
                $(".firstSelected:eq(0):first").attr('src','./images/elements/vTriangle.png');
            } else {
                $(".sectorActiveImg:eq(0)").attr('class','sectorImg');
                switch (this.current2Section)  {
                    case 'environment':
                        $(".sectorImg:eq(0)").attr('id','imageEnvironment_'+this.lang);
                        if (this.current3Section!="") {
                            $(".thirdSelected:eq(0)").attr('class','thirdLevel');
                            $(".openLevel:eq(1):first").attr("src","./images/elements/hTriangle.png");
                            $(".openLevel.eq(1)").removeClass('openLevel');
                            this.current3Section = "";
                            if (section!="environment") {
                                $(".secondLevelWrapper:eq(0)").slideUp(500);
                            }
                        } else {
                            if (section!="environment") {
                                $(".secondLevelWrapper:eq(0)").slideUp(500);
                            }
                        }
                        break;
                    case 'industry':
                        $(".sectorImg:eq(1)").attr('id','imageIndustry_'+this.lang);
                        break;
                    case 'broadcast':
                        $(".sectorImg:eq(2)").attr('id','imageBroadcast_'+this.lang);
                        break;
                    default:
                        null;
                }
            }
            $(".visibleSector:eq(0)").hide();
            $(".visibleSector:eq(0)").removeClass("visibleSector");
            $(".visibleSector:eq(0)").hide();
            $(".visibleSector:eq(0)").removeClass("visibleSector");
            var selected = $(".secondSelected");
            if (selected.length!=0) {
                $(".secondSelected:eq(0)").attr('class','secondLevel');
            }

            switch (section)  {
                case 'environment':
                    $(".sectorImg:eq(0)").attr('id','imageEnvironmentOn_'+this.lang);
                    $(".sectorImg:eq(0)").attr('class','sectorActiveImg');
                    $(".sectorsHeader:eq(1)").addClass("visibleSector");
                    $(".sectorsContent:eq(1)").addClass("visibleSector");
                    $(".secondLevel:eq(0)").attr('class','secondSelected');
                    $(".secondLevelWrapper:eq(0)").slideDown(500);
                    this.current2Section = section;
                    break;
                case 'industry':
                    $(".sectorImg:eq(1)").attr('id','imageIndustryOn_'+this.lang);
                    $(".sectorImg:eq(1)").attr('class','sectorActiveImg');
                    $(".sectorsHeader:eq(2)").addClass("visibleSector");
                    $(".sectorsContent:eq(2)").addClass("visibleSector");
                    $(".secondLevel:eq(1)").attr('class','secondSelected');
                    this.current2Section = section;
                    break;
                case 'broadcast':
                    $(".sectorImg:eq(2)").attr('id','imageBroadcastOn_'+this.lang);
                    $(".sectorImg:eq(2)").attr('class','sectorActiveImg');
                    $(".sectorsHeader:eq(3)").addClass("visibleSector");
                    $(".sectorsContent:eq(3)").addClass("visibleSector");
                    $(".secondLevel:eq(2)").attr('class','secondSelected');
                    this.current2Section = section;
                    break;
                default:
                    null;
            }
            $(".visibleSector:eq(0)").toggle("slide",[],500);
            $(".visibleSector:eq(1)").toggle("slide",[],500);
        }
    }

    // function to make the changes needed for the navigation through third level sections
    oNavigator.navigateThird = function(section) {
        if (this.current3Section!=section) {
            if (this.current3Section=="") {
                $(".sectorsHeader:eq(0)").hide();
                $(".sectorsContent:eq(0)").hide();
                $(".secondSelected:eq(0)").addClass('openLevel');
                $(".secondSelected:eq(0):first").attr('src','./images/elements/vTriangle.png');
            }
            $(".visibleSector:eq(0)").hide();
            $(".visibleSector:eq(0)").removeClass("visibleSector");
            $(".visibleSector:eq(0)").hide();
            $(".visibleSector:eq(0)").removeClass("visibleSector");
            switch (section)  {
                default:
                    $(".sectorsHeader:eq(4)").addClass("visibleSector");
                    $(".sectorsContent:eq(4)").addClass("visibleSector");
                    $(".thirdLevel:eq(0)").attr('class','thirdSelected');
                    this.current3Section = section;
            }
            $(".visibleSector:eq(0)").toggle("slide",[],500);
            $(".visibleSector:eq(1)").toggle("slide",[],500);
        }
    }

    // function to make the changes needed for the navigation through first level sections
    oNavigator.navigateNews = function(index) {
        this.navigateFirst("news",false);
        this.news.show(index,true);
    }
    
    return oNavigator;
}

// object to invoke the navigatorManager
var nManager = new navigationManager();

