

$(document).ready( function() {
                //function doing the switching of items
                function switchTabs(){
                    //init variables
                    var me = $(this);
                    var myWrapperType = this.id;
                    myWrapperType = myWrapperType.substring(0, myWrapperType.indexOf('_tab'));
                    var myID = this.id.substring(myWrapperType.length);
                    myID = myID.substring('_tab'.length);
                    var myItemArr = $('#' + myWrapperType + '_tabs').children();
                    var willRotate = false;
                    
                    for(var i=0; i<myItemArr.length; i++)
                    {
                        var currID = (i+1);
                        var currItem = $('#' + myWrapperType + '_wrap' + currID);
			var currTab = $('#' + myWrapperType + '_tab' + currID);
                        if(myID == currID)
                        {
                            currItem.addClass(myWrapperType + '_wrapselected');
                            currTab.addClass(myWrapperType + '_tabselected');
                            currItem.show(fadeInDuration);
                        }
                        else
                        {
                            currItem.hide(fadeInDuration);
                            currItem.removeClass(myWrapperType + '_wrapselected');
                            currTab.removeClass(myWrapperType + '_tabselected');
                        }
                    }
                    
                    //IE does not support array.indexOf, search manually
                    for(var i=0; i<rotateArr.length; i++)
                    {
                        if(rotateArr[i] == myWrapperType)
                            willRotate = true;
                    }
                    if(willRotate)
                    {
                        //function for doing the fading
                        var fadeTime = function()
                        {
                            var nextID = (myID == myItemArr.length ? 1 : (parseInt(myID)+1));
                            var next = $('#' + myWrapperType + '_tab' + nextID);
							
                            next.click();
                        };
                        
                        //stop the current switching, and start a new switching on the next item as set above
                        switchStop(timerFade);
                        switchStart(fadeTime);
                    }
                    return false;
                }
                
                //stop a specific switch
                var switchStop = function(e){
                    clearTimeout(e);
                    e = 0;
                };
                
                //begin a switch at some point in the future
                var switchStart = function(e){
                    timerFade = window.setTimeout(e, fadeInWait);
                };
                
                //variables that hold timeout values and timers
                var fadeInDuration = 0;
                var fadeInWait = 0; 
                var timerFade = 0;
                var rotateArr = [''];
                
                //set the proper actions on the items that need switching/fading
                $('#features_tabs h5').click(switchTabs);
                $('#features_tab1').click();
            });

