var Utils = {


    // id = the tab to display
    // tabs = array with all the tabs
    // extraClass = to add to the active tab

    showHideTabs : function (id, tabs,extraClass) {

        //Make all the tabs nonactive

        for (var i = 0; i < tabs.length; i++) {
            if (document.getElementById(tabs[i] + "Area") != null) {
                document.getElementById(tabs[i] + "Area").className = "none";
                document.getElementById(tabs[i] + "Button").className = "";
            }

        }

        if (extraClass != null && extraClass != "") {
            document.getElementById(id + "Area").className = "block " + extraClass;

        } else {
            document.getElementById(id + "Area").className = "block";
        }

        document.getElementById(id + "Button").className = "active";

    },

    changeLocale : function (id) {

        var value = document.getElementById(id).value;
        if (value != "select") {
            window.location = value;
        }

    },

    sfHover : function() {

        var sfEls = $$('#nav_primary li.topLevel a');

        for ( var i = 0 ; i < sfEls.length ; i++ ) {

            sfEls[i].addEvents({

                'mouseover': function() {

                    for (  var j = 0 ; j < sfEls.length ; j++  ) {

                        alert("sdsd: " + sfEls[j]);

                        sfEls[j].getParent().className = sfEls[j].getParent().className.replace(new RegExp(" sfhover\\b"), "");

                    }

                    this.className += " sfhover";
                }

            });

        }

    },


    highlightNavParent : function () {

        var elms = $$('#nav_primary li ul');

        for ( var i = 0 ; i < elms.length ; i++ ) {

            elms[i].addEvents({

                'mouseover': function() {
                    this.getParent().className = "active";
                },

                'mouseout' : function() {


                    if ( !(Browser.Engine.trident && Browser.Engine.version == 4) ) {

                        this.getParent().className = this.className.replace(new RegExp(" sfhover\\b"), "");

                    }                        

                }

            });

        }

    },

    heightHackShonk : function (className) {

        var shonkArray = $$("a."+className)

        for ( var i = 0 ; i < shonkArray.length ; i++ ) {

            var thisElm = shonkArray[i];
            var previousElm = thisElm.getPrevious();

            thisElm.setStyle('top', previousElm.getStyle('height').toInt()-25 );
            thisElm.setStyle('display', 'inline' );            

        }


    },

    submitHelpForm : function (form) {
        var selectHelpForm = $(form);
        var helpTopic = $('helpTopic');
        var value = helpTopic.options[helpTopic.options.selectedIndex].value;
        if (value.length > 0) {
            selectHelpForm.action = value;
            selectHelpForm.submit();
        }
        return false;
        
    },

    tabNavFix : function () {

        var navElms = $$('li.tabNavElm');

        for ( var i = 0 ; i < navElms.length ; i++ ) {

            navElms[i].addEvents({

                'mouseover': function() {

                    if ( Browser.Engine.trident && Browser.Engine.version == 4 ) {

                        this.setStyles({
                            background: 'url( ../images/productnavbar-left.gif) no-repeat top left transparent'
                        });

                        this.getChildren('a').setStyles({
                            background: 'url(../images/productnavbar-right.gif) no-repeat top right transparent'
                        })

                    }


                },

                'mouseout' : function() {

                    if ( !this.hasClass("active")) {

                        if ( Browser.Engine.trident && Browser.Engine.version == 4 ) {

                            this.setStyles({
                                background: 'none'
                            });

                            this.getChildren('a').setStyles({
                                background: 'none'
                            })

                        }

                    }
                },

                'click' : function() {

                    var tabArray = ['overview','features','screenshots','tour','pricing','awardstab','casestudies'];
                    var tabElm = this.getChildren('a')[0].getProperty('id');

                    if ( Browser.Engine.trident && Browser.Engine.version == 4 ) {

                        for ( var j = 0 ; j < tabArray.length ; j++ ) {

                            $(tabArray[j]).setStyles({
                                background: 'none'
                            });

                            $(tabArray[j]).getParent().setStyles({
                                background: 'none'
                            });
                        }


                        $(tabElm).getParent().setStyles({
                            background: 'url( ../images/productnavbar-left.gif) no-repeat top left transparent'
                        });


                        $(tabElm).setStyles({
                            background: 'url(../images/productnavbar-right.gif) no-repeat top right transparent'
                        });
                        
                    }


                    Utils.showHideTabs( tabElm, tabArray ,'tabArea');

                }

            });

        }

    }

};
