var tnt_module=1;
var rsUI = {
    /*
     * Simulate first-child, last-child on <li> elements
     */
    domLIFix:function(){
              if($('ul').length > 0){
        $('ul').find('>li:last').addClass('last-child');
        $('ul').find('>li:first').addClass('first-child');
              }
    },

    /*
     * Definition and function to create our navigation dropdown menus
     * @param caller DOM calling object
     * @returns object {menuObject: jQuery(object), controlElements: Array(jQuery(object),...)}
     */
    
    menuDefinitions:{
        
        
        _audioMenu:function(caller){
            var d = $('<div>').addClass('generated-audio');
            var c = $(caller);
            var p = c.offset();
            var w = c.width();          
            var html = '<strong>Reinforce your learning anywhere . at home, in the car, or on the go.</strong>';
            html += '<ul><li>Download the sound files to your MP3 player or computer.</li>';
            html += '<li>Access your lessons whenever and wherever you want.</li>';
            html += '<li>Hear and repeat questions and answers to use in conversations.</li></ul>';
            
            c.css({cursor:'help'});
            d.append($('<div>').addClass('top'));
            d.append($('<div>').addClass('mid').html(html));
            d.append($('<div>').addClass('bot'));

            d.css({display:'block',visibility:'hidden',top:p.top-20,left:p.left+w});
            
            $('body').append(d); // Add to top-level of DOM 
            
            d.css({visibility:'visible',display:'none'});
            
            return {menuObject:d, controlElements:[d,c]}
            
        },
        
        _comparisonTooltipMenu:function(caller){
            var d = $('<div>').addClass('generated-audio');
            var c = $(caller);
            var p = c.offset();
            var w = c.width();          
                        var html = '';
                        if(caller.id == 'rosetta-course') {
                          html += '<p>Our award-winning program where we recreate the natural way you learn a language.</p>';
                        }
                        else if(caller.id == 'conversation-skills') {
                          html += '<p>Learn how to introduce yourself, greet others, go shopping and more.</p>';
                        }
                        else if(caller.id == 'navigate-surroundings') {
                          html += '<p>Dine out, give and get directions, use transportation and more.</p>';
                        }
                        else if(caller.id == 'express-ideas') {
                          html += '<p>Share your thoughts, talk about your interests, everyday life and more.</p>';
                        }
                        else if(caller.id == 'negotiate-arrangements') {
                          html += '<p>Plan repairs, change appointments, move abroad and more.</p>';
                        }
                        else if(caller.id == 'manage-situations') {
                          html += '<p>Respond to emergencies, discuss work, explore culture and more.</p>';
                        }
                        else if(caller.id == 'rosetta-studio') {
                  html += '<p>Practice in our live online learning environment with a';
                          html += ' native-speaking Studio Coach.</p>';
                        }
                        else if(caller.id == 'native-speaking') {
                          html += '<p>Discover real-time feedback and guidance as you explore your new language.</p>';
                        }
                        else if(caller.id == 'guided-conversation') {
                          html += '<p>Strengthen your speaking skills with others while getting support';
                          html += ' from our Studio Coaches.</p>';
                        }
                        else if(caller.id == 'live-sessions') {
                          html += '<p>Schedule unlimited, one hour sessions and set reminders.</p>';
                        }
                        else if(caller.id == 'rosetta-world') {
                          html += '<p>Play in our exclusive online community dedicated to language and discovery.</p>';
                        }
                        else if(caller.id == 'structured-chart') {
                          html += '<p>Communicate with other learners in your new language.</p>';
                        }
                        else if(caller.id == 'language-games') {
                          html += '<p>Explore your new language through engaging games and activities.</p>';
                        }
                        else if(caller.id == 'exchange-simbio') {
                          html += '<p>Real-time sessions where native speakers help with your';
                          html += ' language discovery while you help with theirs.</p>';
                        }
                        else if(caller.id == 'success-agents') {
                          html += '<p>Success Agents who are always accessible for questions, concerns and support.</p>';
                        }
                        else if(caller.id == 'audio-companion') {
                          html += '<p>These CDs allow you to reinforce what you\'re learning with Rosetta Stone:';
                          html += ' at home, in the car and on the go.</p>';
                        }
                        else if(caller.id == 'six-month-guarantee') {
                          html += '<p>We.re so certain you.ll succeed in your language learning that we provide';
                          html += ' a 6-month money-back guarantee if you are not completely satisfied with our CD-ROM software.';
                          html += ' Available only when you buy directly through Rosetta Stone.</p>';
                        }
                        else if(caller.id == 'delivery-method') {
                          html += '<p>Our solutions can be purchased as CD-ROMs or as an online subscription';
                          html += ' that allows you to log-on with an internet connection.</p>';
                        }
            
            c.css({cursor:'pointer'});
            d.append($('<div>').addClass('top'));
            d.append($('<div>').addClass('mid').html(html));
            d.append($('<div>').addClass('bot'));

            d.css({display:'block',visibility:'hidden',top:p.top-20,left:p.left+w});
            
            $('body').append(d); // Add to top-level of DOM 
            
            d.css({visibility:'visible',display:'none','z-index':'5'});
            
            return {menuObject:d, controlElements:[d,c]}
            
        },
        
        /*
         * For internal sub menus
         */
       _subMenu:function(caller){

            var m = $(this).next('ul.sub-menu').get(0);
            var c = $(m).clone(true);
            var cc = $(m).clone(true);
                        if(this.id == "Languages")
              var d = $('<div onmouseover="rsUI.hide_dropdown(\'none\');" onmouseout="rsUI.hide_dropdown(\'block\');">').addClass('generated-sub-menu');
                        else
                          var d = $('<div>').addClass('generated-sub-menu');
            var p = $(caller).offset(); // Get X/Y of our calling object
            
            /* 
             * This needs to size dynamically so we need a width of the elements
             */
            var w = c.virtualWidth();
                w = w < 200 ? 200 : w;
            //w+=20; // Add 20 to width for padding
            var h4 = $('<h4>').append($(caller).clone());
            d.append($('<div>').addClass('generated-sub-menu-header').append(h4)); 
            d.append(
                $('<div>').addClass('generated-sub-menu-content').append(
                    $('<div>').addClass('sub-menu-content').append(c)
                )
            );  
            d.css({display:'none',top:p.top,left:p.left+7,width:w,height:1}); // Position according to design
            $('body').append(d); // Add to top-level of DOM 
            return {menuObject:d, controlElements:[h4,c]}   

        },

        /*
         * For top support list
         */
        _supportMenu:function(caller){
            var m = $(this).next('ul').get(0);
            var c = $(m).clone(true);
            var d = $('<div>').addClass('generated-support-list');
            var p = $(caller).offset(); // Get X/Y of our calling object

            var h4 = $('<h4>').text($(caller).text());
            d.append($('<div>').addClass('generated-support-list-header').append(h4));
            d.append($('<div>').addClass('generated-support-list-content').append(c));  
            d.css({display:'none',top:p.top-5,left:p.left-7});// Position according to design
            $('body').append(d); // Add to top-level of DOM 

            return {menuObject:d, controlElements:[h4,c]}           
        },
        
        /*
         * For top country list
         */
        _countryMenu:function(caller){
            var m = $(this).parent().parent('ul').get(0);
            var c = $(m).clone(true);
            var d = $('<div>').addClass('generated-country-list');
            var p = $(caller).offset();     
            
            c.find('li').each(function(){
                if($(this).find('a').text() == $(caller).text()){
                    $(this).remove();
                }
            }); 
            
            var h4 = $('<h4>').text($(caller).text());
            d.append($('<div>').addClass('generated-country-list-header').append(h4));
            d.append($('<div>').addClass('generated-country-list-content').append(c));
            d.css({display:'none',top:p.top-5,left:p.left-7}); // Position according to design
            $('body').append(d); // Add to top-level of DOM
            
            return {menuObject:d, controlElements:[h4,c]};          
        }   
        
    },

        hide_dropdown:function(style_property){
          if(navigator.userAgent.indexOf('MSIE 6')!= -1 && document.getElementById('BVRRDisplayContentSelectBVFrameID')){
            document.getElementById('BVRRDisplayContentSelectBVFrameID').style.display = style_property;
          }
        },

        initCountryDropdown:function(){
     if($('.country-select li.active a').length > 0){
           $('.country-select li.active a').enableMenuOverlay(rsUI.menuDefinitions._countryMenu);
         }
    },
    
    initSupportDropdown:function(){
          if($('.support-select>a').length > 0){
        $('.support-select>a').enableMenuOverlay(rsUI.menuDefinitions._supportMenu);
          }
    },
    
    initLangDropdown:function(){
      if($('#lang-dropdown span.title a')){
            $('#lang-dropdown span.title a').click(function(e){
        e.preventDefault();
                 var s = $('#lang-selections');
                 if($('#lang-list-selections').length > 0){
                     if($('#lang-list-selections').is(':visible')) 
                         $('#lang-list-selections').hide() 
                 }
                 if($('#lang-select-totale-buynow').length > 0){
                     if($('#lang-select-totale-buynow').is(':visible'))
                          $('#lang-select-totale-buynow').hide()
                 }
        if(s.is(':visible')){
                 $(this).removeClass('active');
             s.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)});
        }
                else{
            if(document.getElementById('product_review_frame')) document.getElementById('product_review_frame').style.display = 'block';
            $(this).addClass('active');
            $('body').bind('click',rsUI._closeLangBox);
            s.show(50,function(){
            if(s.find('a.close-selection').length == 0){
                  var a = $('<a>').addClass('close-selection').click(function(){s.hide();if(document.getElementById('product_review_frame')) document.getElementById('product_review_frame').style.display = 'none';});
                  s.append(a);
            }
            });
        }
         return false;          
         });
      } 
          if($('#buynow_img').length > 0){
              $('#buynow_img').click(function(e){ 
                 if(document.getElementById('popup_frame')) 
                  document.getElementById('popup_frame').style.display = 'block'; 
                  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
                    var ieversion=new Number(RegExp.$1); 
                    if(ieversion <= 6.5){ 
                          document.getElementById("lang-list-selections").style.left = "404px"; 
                      document.getElementById("lang-list-selections").style.top = "77px";
                    } 
                    else{ 
                      document.getElementById("lang-list-selections").style.left = "408px"; 
                      document.getElementById("lang-list-selections").style.top = "77px"; 
                    }        
                  } 
             else{ 
                  document.getElementById("lang-list-selections").style.left = "408px"; 
                  document.getElementById("lang-list-selections").style.top = "77px"; 
                  } 
             e.preventDefault(); 
             var s1 = $('#lang-list-selections'); 
             if($('#lang-selections').length > 0){
                 if($('#lang-selections').is(':visible'))
                      $('#lang-selections').hide() 
             } 
                 if($('#lang-select-totale-buynow').length > 0){
                     if($('#lang-select-totale-buynow').is(':visible'))
                          $('#lang-select-totale-buynow').hide()
                 }
             if(s1.is(':visible')){ 
                 $(this).removeClass('active'); 
                 s1.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)}); 
             } 
             else{ 
                 $(this).addClass('active'); 
                 $('body').bind('click',rsUI._closeLangBox); 
                 s1.show(50,function(){ 
                   if(s1.find('a.close-selection').length == 0){ 
                      var a = $('<a>').addClass('close-selection').click(function(){s1.hide()});
                      s1.append(a); 
                    } 
                 }); 
             } 
           return false; 
           }); 
         } 
             if($('#lang-totale-buynow').length > 0){
               $('#lang-totale-buynow').click(function(e){
                 if(document.getElementById('popup_frame'))
                      document.getElementById('popup_frame').style.display = 'block';
                      if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
                        var ieversion=new Number(RegExp.$1);
                        if(ieversion < 7){
                          document.getElementById("lang-select-totale-buynow").style.top = "7px";
                        }
                        else{
                          document.getElementById("lang-select-totale-buynow").style.top = "5px";
                        }
                      }
                 else{
                      document.getElementById("lang-select-totale-buynow").style.top = "3px";
                      }
                 e.preventDefault();
                 var s2 = $('#lang-select-totale-buynow');
                 if($('#lang-selections').length > 0){
                     if($('#lang-selections').is(':visible'))
                          $('#lang-selections').hide()
                 }
                 if($('#lang-list-selections').length > 0){
                     if($('#lang-list-selections').is(':visible'))
                          $('#lang-list-selections').hide()
                 }
                 if(s2.is(':visible')){
                        $(this).removeClass('active');
                        s2.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)});
                 }
                 else{
                        $(this).addClass('active'); 
                        $('body').bind('click',rsUI._closeLangBox);
                        s2.show(50,function(){
                          if(s2.find('a.close-selection').length == 0){
                            var a = $('<a>').addClass('close-selection').click(function(){s1.hide()});
                            s2.append(a);
                          }
                        });
                 }
               return false;
               });
             }
      
          if($('#totale-lang-dropdown span.title a').length > 0){
            $('#totale-lang-dropdown span.title a').click(function(e){
        e.preventDefault();
                 var s = $('#lang-select-totale-buynow');
                 if($('#lang-list-selections').length > 0){
                     if($('#lang-list-selections').is(':visible')) 
                         $('#lang-list-selections').hide() 
                 }
                 if($('#lang-select-totale-buynow').length > 0){
                     if($('#lang-select-totale-buynow').is(':visible'))
                          $('#lang-select-totale-buynow').hide()
                 }
        if(s.is(':visible')){
                 $(this).removeClass('active');
             s.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)});
        }
                else{
            $(this).addClass('active');
            $('body').bind('click',rsUI._closeLangBox);
            s.show(50,function(){
            if(s.find('a.close-selection').length == 0){
                  var a = $('<a>').addClass('close-selection').click(function(){s.hide()});
                  s.append(a);
            }
            });
        }
         return false;          
         });
      } 

    },
    
    _closeLangBox:function(e){
        var s = $('#lang-selections');
        if(s.is(':visible')){
            s.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)});
        if(document.getElementById('product_review_frame')) document.getElementById('product_review_frame').style.display = 'none';
        }   
               var s1 = $('#lang-list-selections'); 
           if(s1.is(':visible')){ 
                    s1.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)}); 
           } 
               var s2 = $('#lang-select-totale-buynow');
               if(s2.is(':visible')){
                        s2.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)});
               }
                  if(document.getElementById('popup_frame')) 
                    document.getElementById('popup_frame').style.display = 'none';  
    },
    
    /*
     * Create dynamic menus
     */   
   initSubMenus:function(){
     if($('#subnav>ul>li').length > 0){
       $('#subnav>ul>li').each(function(){
         var li = $(this);
     if(li.find('ul.sub-menu').length > 0){
       li.find('a:first').enableMenuOverlay(rsUI.menuDefinitions._subMenu);
     }  
       });
     }
     if($('#topnav>ul>li').length > 0){
         $('#topnav>ul>li').each(function(){
           var li = $(this);
     if(li.find('ul.sub-menu').length > 0){
       li.find('a:first').enableMenuOverlay(rsUI.menuDefinitions._subMenu);
     }  
         });
     }     
   },

    /*
     * Applies mouseover and mouseout to our menu calling element
     * @param menuCreateCallback function
     */
    _applyMenuControls:function(menuCreateCallback){
        $(this).each(function(){
            $(this).bind('mouseover', function(e){
                var caller = e.target;                  
                clearTimeout(caller.timer);
                if(!caller.menuActive){
                    rsUI._createMenu(caller, menuCreateCallback);
                }
            }).bind('mouseout',function(e){
                var caller = e.target;
                caller.menuActive = false;              
                caller.timer = setTimeout(function(){
                    if(caller.menuActive == false){
                        $(caller.menu).slideUp(50,function(){try{d.remove()}catch(e){}});
                    }
                },100);
            
            });
        });     
        
    },
    /*
     * Create menu dropdown
     * @param caller DOM node (<a>)
     * @param menu DOM node (<ul>)
     */
   _createMenu:function(caller, menuDefCallback){
   
        if(!caller.menuActive){
            
            $('.visible-generated-menu').remove();
        
            /*
             * Generate the menu in memory and append necessary elements
             * callback should return {menuObject:(object), controlElements:[array]}
             * Where controlElements are the elements in the menu that  
             * have the mouseover and mouseout events to control the display
             */
            var o = menuDefCallback.call(caller, caller);
            
            /*
             * Assign our menu to the caller for future use and create property
             * menuActive
             */
            caller.menu = o.menuObject.get(0);
            caller.menuActive = true;           
        
            /*
             * Attach mouse events to the <h4> and <ul> tag
             * We don't attach to the container itself because the design of
             * the menu overlays the regular navigation
             */             
            $(o.controlElements).each(function(){
                $(this).bind('mouseover',function(e){
                    caller.menuActive = true;
                    clearTimeout(caller.timer); // Clear timer if set
                }).bind('mouseout',function(e){
                    caller.menuActive = false;
                    /*
                     * The timer gives the user an interval to navigate from
                     * the original item to the menu.  If we don't do this, the menu
                     * would hide immedately after we mouseout of the <h4> tag
                     */
                    caller.timer = setTimeout(function(){
                        if(caller.menuActive == false){
                            $(caller.menu).slideUp(50,function(){o.menuObject.remove()});
                        }
                    },100);
                });
            });
        
            /*
             * Show the menu
             */
            o.menuObject.addClass('visible-generated-menu');
            o.menuObject.slideDown('fast',function(){caller.menuActive = true;});           
            
        }
      
   },
    signupInit:function(){
    if($('#signup-email, #newsletter-email, #sub-email').length > 0){
         $('#signup-email, #newsletter-email, #sub-email').focus(function(){
            var me = $(this);
            me.val((me.val().length > 0) ? '' : me.val());
        }).
        blur(function(){
            var me = $(this);
            me.val(me.val() == '' ? 'your e-mail address here' : me.val());         
        });     
     }     
    },
       
    setupAjaxFormHooks:function(){/*
       var timer; 
       var animate = function(){
          var txt = $('#processing');
          var text = txt.text();
          var idx = text.indexOf('.');
          if(idx != -1){
              if(text.substr(idx).length == 3){txt.text(text.substr(0,idx));}
              else{txt.text(text + '.');}
          }
          else{txt.text(text + '.');}
       };
       var kill_animation = function(){
          window.clearInterval(timer);
       };
       if($('#email-form').length > 0){
          $('#email-form').submit(function(e){
                    
                        e.preventDefault();
                        var email = this['email'].value;
                        var cname = this['cis_name'].value;
                        var redirect = this['redirect_to'].value;
                        var source = this['import_source'].value;
                        var formname = this['formname'].value;
                        var formurl = this['formurl'].value;
                        var id = this['identifier'].value;
                        //var id = '';
                        var post_str = 'email=' + email + '&cis_name=' + cname + '&import_source=' + source + '&redirect_to=' + redirect + '&identifier=' + id + '&formname=' + formname + '&formurl=' + formurl;
                               type: 'POST',
                               url: this.action,
                               data: post_str,
                               success: function(resp, status){
                                 kill_animation();
                                 if(resp.indexOf('errorExplanation') != -1){
                                   $('#processing').addClass('hide');
                                   $('#error-email').removeClass('hide');
                                   window.setTimeout(function() {$('#error-email').addClass('hide'); $('#email-form').removeClass('hide');}, 3000);
                                 }
                                 else{
                                   $('#processing').addClass('hide');
                                   $('#thank-you').removeClass('hide');
                                   // Reporting email sumbit on channel homepages only. (lazy regexp ok)
                                  if(s && s.tl && document.location.href.match(/(personal|schools|organizations|homeschool)$/)){ 
                                     //do the thing
                                     s.linkTrackVars="events";
                                     s.events = "event38";
                                     s.linkTrackEvents="event38";
                                     s.tl('true', 'o', 'eNewsletter Sign-up');
                                   }
                                 }
                                 return false;
                               },
                               error: function(resp, status, error){
                                 kill_animation();
                                 $('#processing').addClass('hide');
                                 $('#error').removeClass('hide');
                                 window.setTimeout(function() {$('#error').addClass('hide'); $('#email-form').removeClass('hide');}, 2000);
                                 return false;
                               }
                        
                 $('#email-form').addClass('hide');
                 $('#processing').removeClass('hide');
                 timer = window.setInterval(animate, 200);
                 return false;
                });
             }*/
        },

    subnavActivate:function(){
        /*if($('#subnav>ul>li>a.active').length > 0){
          var a = $('#subnav>ul>li>a.active');
          a.css({position:'relative',zIndex:3})
          if(a.length >0){
            var d = $('<div>').css({
                position:'absolute',
                background:'transparent url(/etc/designs/rosettastone/images/inavbgright.gif) no-repeat top right',
                height:'25px',
                top:a.get(0).offsetTop -4,
                left:a.get(0).offsetLeft - 7,
                zIndex:2,
                width:a.outerWidth() - 10
            });
            var dd = $('<div>').css({
                font:'normal 13px/25px Arial,sans-serif',
                background:'transparent url(/etc/designs/rosettastone/images/inavbgleft.gif) no-repeat top left',
                height:'25px', 
                color:'#000',
                paddingLeft:10,
                width:a.outerWidth() - 20
            });            
            //$(a).before(d.append(dd));          
        }
      }   */   
    },
    
    tertiaryNavActivate:function(){
       if($('.internal-nav ul li').length > 0){
          $('.internal-nav ul li').hover(function(){ $(this).addClass('hover')},function(){$(this).removeClass('hover')});}
       if($('.internal-nav-condensed ul li').length > 0){
          $('.internal-nav-condensed ul li').hover(function(){ $(this).addClass('hover')},function(){$(this).removeClass('hover')});}
    },
    
    offeringActivate:function(){
    if($('#product-offering>ul>li>a').length > 0){
        $('#product-offering>ul>li>a').click(function(e){
            e.preventDefault();
            var a = $(this);
            var h = a.attr('href').substr(1);
                        if(h!="what-I-get"){
                          if(document.getElementById("product_notes"))
                            document.getElementById("product_notes").style.display = "none";
                        }
                        else if(document.getElementById("product_notes"))
                          document.getElementById("product_notes").style.display = "block";
            $('#product-offering>ul>li>a').removeClass('active');
            $('.offering-content').each(function(){
                if($(this).is(':visible')){
                    $(this).fadeOut(function(){
                        $('#'+h).fadeIn();
                    });                 
                }
            });                     
            a.addClass('active');
        });     
         }
    },
    
    offeringActivateHS:function(){
    if($('#product-offering-hs>ul>li>a').length > 0){
        $('#product-offering-hs>ul>li>a').click(function(e){
            e.preventDefault();
            var a = $(this);
            var h = a.attr('href').substr(1);
                        if(h!="what-I-get-hs"){
                          if(document.getElementById("product_notes"))
                            document.getElementById("product_notes").style.display = "none";
                        }
                        else if(document.getElementById("product_notes"))
                          document.getElementById("product_notes").style.display = "block";
            $('#product-offering-hs>ul>li>a').removeClass('active');
            $('.offering-content-hs').each(function(){
                if($(this).is(':visible')){
                    $(this).fadeOut(function(){
                        $('#'+h).fadeIn();
                    });                 
                }
            });                     
            a.addClass('active');
        });     
         }
    },
    
    offeringActivate_def:function(){
          if($('#product_notes>ul>li>a').length > 0){
            $('.offering-content').each(function(){
              if($(this).is(':visible')){
                $(this).fadeOut(function(){
                   $('#sys-req').fadeIn();
                });
              }
            });
            op = $('#product-offering>ul>li>a');
            $(op[0]).removeClass('active');
            $(op[1]).removeClass('active');
            $(op[2]).addClass('active');
            document.getElementById("product_notes").style.display = "none";
          }
        },
    audioMenus:function(){
        if($('.audio-companion').length > 0){
      $('.audio-companion').each(function(){
            var tag = $(this);
            tag.enableMenuOverlay(rsUI.menuDefinitions._audioMenu);     
        });     }
    },
    comparisonTooltipMenus:function(){
            if($('.comparison-tooltip').length > 0){
                $('.comparison-tooltip').each(function(){
            var tag = $(this);
            tag.enableMenuOverlay(rsUI.menuDefinitions._comparisonTooltipMenu);     
        });
            }
    },
    loadVideoMoment:function(videoUrl, caller){
        var player = $('#moment-flash-video').get(0);       
        player.loadVideoBySrc(videoUrl);        
        
        $('.video-selections>ul>li>a').removeClass('active');
        $(caller).addClass('active');
        
    },
//Not the best code but works for now
        replaceMomentVideo:function(params, flashvars, caller, current){
          parameters = {
            allowFullScreen: "true",
            bgcolor: params['bgcolor'],
            wmode: params['wmode'],
            base: params['base'],
            allowscriptaccess: 'always'
          };

         width = params['width'];
         height = params['height'];
         min_version = params['min_version'];
         player = params['player'];
         express_install = params['express_install'];

         attributes = {
           id: 'moment-flash-video'
         };

        vars = {
          video: flashvars['video'],
          dataSource: flashvars['dataSource'],
          preview: flashvars['preview']
        };

        swfobject.embedSWF(player, caller, width, height, min_version, express_install, vars, parameters, attributes);
        $('.video-selections>ul>li>a').removeClass('active');
        $(current).addClass('active');

        },
        setDefaultsAndReplaceMomentVideo:function(video_url, preview_url,data_url, caller, current){
          params = {
            width: '230',
            height: '152',
            min_version: '9.0.28',
            player: 'http://www.rosettastone.com/content/dam/rosettastonecom/flash/VideoApplication.swf',
            express_install: 'http://www.rosettastone.com/content/dam/rosettastonecom/flash/expressInstall.swf',
            bgcolor: 'fbf8e5',
            wmode: 'transparent',
            base: 'http://www.rosettastone.com/content/dam/rosettastonecom/flash/'
          };

          vars = {
            video: video_url,
            dataSource: data_url,
            preview: preview_url
          };
          rsUI.replaceMomentVideo(params, vars, caller, current);
        },
    setDefAndReplaceMomentVideo:function(wid, hght, video_url, preview_url,data_url, caller, current){
          params = {};
            params.width = wid;
            params.height = hght;
            params.min_version = '9.0.28';
            params.player = 'http://www.rosettastone.com/content/dam/rosettastonecom/flash/VideoApplication.swf';
            params.express_install = 'http://www.rosettastone.com/content/dam/rosettastonecom/flash/expressInstall.swf';
            params.bgcolor = 'fbf8e5';
            params.wmode = 'transparent';
            params.base = 'http://www.rosettastone.com/content/dam/rosettastonecom/flash/';
          vars = {};
            vars.video = video_url;
            vars.dataSource = data_url;
            vars.preview = preview_url;
          rsUI.replaceMomentVideo(params, vars, caller, current);
        },
    loadVideoLightbox:function(flvFile){
        
        var iframeHeight = 601;
        var iframeWidth = 708;
        
        if(typeof flvFile != 'undefined'){
            iframeHeight = 500;
        iframeWidth = 708;
        }
        
       $(document.documentElement).css('overflow','hidden');
       
       var st = document.documentElement.scrollTop||document.body.scrollTop;
       var wh = $(window).height();
       var ww = $(window).width();
    
        /*if(wh < 630){
            if(!confirm("The video you are about to play is larger than your viewable area and controls may not be visible.\n\nWhen the video has completed, you must click your browser's reload or refresh button to close the video.")){
                return;
            }           
        }*/
        
           var d = $('<div>').addClass('video-lightbox').css({zIndex:8000,background:'#000',opacity:0.85,position:'absolute',top:0,left:0,width:ww,height:'2000px'});
           var ifr = $('<iframe>').addClass('video-iframe').attr({scrolling:'no',border:'0','frameBorder':'none',src:'/us_assets/redesign/flash/personal_demo/lightbox.html'}).css({zIndex:8001,position:'absolute',border:0,width:796,height:565,top:(wh/2-275)+st,left:(ww/2-355)});

       $('body').append(d);    
       $('body').append(ifr);
       
       $(window).bind('resize', rsUI.redrawLightbox);
    },
    
    redrawLightbox:function(){
       if($('.video-lightbox').length > 0){
          setTimeout(function(){
           var st = document.documentElement.scrollTop||document.body.scrollTop;
           var wh = $(window).height();
           var ww = $(window).width();
           $('.video-lightbox').css({top:0,left:0,width:ww,height:wh+st});   
           $('.video-iframe').css({top:(wh/2-300)+st,left:(ww/2-355)});
        },10);
       }
    },
    
    resizeLightbox:function(width,height,callback){
       if($('.video-lightbox').length > 0){
          setTimeout(function(){
           var st = document.documentElement.scrollTop||document.body.scrollTop;
           var wh = $(window).height();
           var ww = $(window).width();
           $('.video-iframe').animate({top:(wh/2-height/2)+st,width:width,height:height,left:(ww/2-width/2)},function(){
              callback.call(this);                
           });
        },10);
       }
    },
    
    closeVideoLightbox:function(){
        $('.video-lightbox, .video-iframe').remove();
        $(document.documentElement).css('overflowY','auto');
        $(window).unbind('resize', rsUI.redrawLightbox);
    },
    
    curLangImage:0,
    
    rotateLangs:function(){
        if($('#rotate-langs>li').length > 0){
        if($('#rotate-langs>li').length == 0) return;
        
        this.langImages = $('#rotate-langs>li');
        var me = this;
        
        setInterval(function(){
            me.langImageLoop();
        },9000);
           }
    },
    
    langImageLoop:function(){
        var me = this;
        me.curLangImage++;
        if(me.curLangImage > me.langImages.length -1) me.curLangImage = 0;
        
        $('#rotate-langs>li:visible').fadeOut(function(){
            $(me.langImages[me.curLangImage]).fadeIn(function(){
            
            });
        });     
    },
    isValidEmailAddress:function(emailAddress) {
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        return pattern.test(emailAddress);
    },
    emulate_dropdown:function(element){
	$element = jQuery(element);
	$element.find('li').click(function(){
		if(jQuery(this).hasClass('selected-disp')) {
			$element.removeClass('error');
			$element.addClass('dropdowned');
		}
		else
		{
			$element.find(' li.selected-disp').html(jQuery(this).html());
			$element.find('li.selected').removeClass('selected');
			jQuery(this).addClass('selected');
			$element.removeClass('dropdowned');
			$element.css('border','none');
		}	
	});
	$element.mouseleave(function(){
		$element.removeClass('dropdowned');
	});
	$element.find('li').hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
    },
	emulate_dropdown_tnt:function(element){
    $element = jQuery(element);
    $element.find('li').click(function(){
        if(jQuery(this).hasClass('selected-disp-tnt')) {
            $element.removeClass('error');
            $element.addClass('dropdowned-tnt');
        }
        else
        {
            $element.find(' li.selected-disp-tnt').html(jQuery(this).html());
            $element.find('li.selected').removeClass('selected');
            jQuery(this).addClass('selected');
            $element.removeClass('dropdowned-tnt');
            $element.css('border','none');
        }   
    });
    $element.mouseleave(function(){
        $element.removeClass('dropdowned-tnt');
    });
    $element.find('li').hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");});
    },
    setupDemoModule:function() {
	if(document.getElementById('cat-demo-module')){
	if(tnt_module==1){    rsUI.emulate_dropdown('ul#drpdown');}
      else{     rsUI.emulate_dropdown_tnt('ul#drpdown-tnt');}
	
	$(document).ready(function(){
		jQuery('ul#drpdown li').each(function() {
			if(window.languageCode !== undefined && jQuery(this).attr('id') == languageCode)
				jQuery(this).click();
		});
		jQuery('ul#drpdown-tnt li').each(function() {
            if(window.languageCode != undefined && jQuery(this).attr('id') == languageCode)
                jQuery(this).click();
        });
		
        });
	jQuery('#get-started').click(function(){
		if(!jQuery('ul#drpdown li').hasClass('selected')){
			jQuery('ul#drpdown').addClass('error');
		}
		else{
			jQuery('#demo-pre-module').hide();
			jQuery('#demo-module').show();
		}
	});
	jQuery('#get-started-tnt').click(function(){
        if(!jQuery('ul#drpdown-tnt li').hasClass('selected')){
            jQuery('ul#drpdown-tnt').addClass('error');
        }
        else{
            jQuery('#demo-tnt-module').hide();
            jQuery('#demo-module').show();
        }
    });
	jQuery('#email-req').focus(function(){
		jQuery(this).removeClass('error');
		jQuery('#mail-me-sel #textbox').removeClass('errorbox');
		var me = jQuery(this);
		me.val((me.val().length > 0) ? '' : me.val());
		}).
		blur(function(){
		var me = jQuery(this);
		me.val(me.val() == '' ? 'E-mail Address' : me.val());
	});
	jQuery('#mail-me #email').focus(function(){
		jQuery(this).removeClass('error');
		var me = jQuery(this);
		me.val((me.val().length > 0) ? '' : me.val());
		}).
		blur(function(){
		var me = jQuery(this);
		me.val(me.val() == '' ? 'E-mail Address' : me.val());
	});
	}	
    },
    load_v4_demo:function(){
		jQuery.facebox({ajax:'/content/rs/us/en_US/pe/demo.html'});
                jQuery('#facebox').addClass("mt");$('#facebox .heading').html('Online Demo');
                jQuery('#facebox .close_image').attr('src', '/content/dam/rosettastonecom/images/mt/btn_close.png');
                jQuery('#facebox_overlay').css('opacity','0.7');
    },
    submitform_and_load_demo:function(){
	var email_val = jQuery('#email-req').val();
      if(document.getElementById("language") != null)
                document.getElementById("language").value = fullLangName;
      /* Code added for Page URL  */
      if(document.getElementById("page_url") != null)
		document.getElementById("page_url").value = window.location.href;

	if(email_val && email_val != "E-mail Address" && rsUI.isValidEmailAddress(email_val)) {
		if(jQuery.inArray(email_val,pre_email_val) == -1){
		jQuery.post('/content/rs/us/en_US/form/ajax.html?skipvalidation=true', jQuery('#flash-demo-module').serialize(),function(data){
			data=jQuery.trim(data);
			if(data == '[{"cisFlag":"true"}]') rsUI.load_v4_demo();
			else jQuery('#textbox').html('Error processing.');
		});
		pre_email_val.push(email_val);
		}
		else rsUI.load_v4_demo();
	}
	else {
		jQuery('#email-req').attr('value','Invalid e-mail address.');
		jQuery('#email-req').addClass('error');
		jQuery('#mail-me-sel #textbox').addClass('errorbox');
	}	
    },
	load_v4_demo_new:function(){
		jQuery.facebox({ajax:"/content/rs/us/en_US/pe/new_demo.html"});
                jQuery('#facebox').addClass("mt");$('#facebox .heading').html('Online Demo');
                jQuery('#facebox .close_image').attr('src', '/content/dam/rosettastonecom/images/mt/btn_close.png');
                jQuery('#facebox_overlay').css('opacity','0.7');
    },
    submitform_and_load_demo_new:function(){
	var email_val = jQuery('#email-req').val();
	if(document.getElementById("language") != null)
		document.getElementById("language").value = fullLangName;
	if(email_val && email_val != "E-mail Address" && rsUI.isValidEmailAddress(email_val)) {
		if(jQuery.inArray(email_val,pre_email_val) == -1){
		jQuery.post('/content/rs/us/en_US/form/ajax.html?skipvalidation=true', jQuery('#flash-demo-module').serialize(),function(data){
			data=jQuery.trim(data);
			if(data == '[{"cisFlag":"true"}]') rsUI.load_v4_demo_new();
			else jQuery('#textbox').html('Error processing.');
		});
		pre_email_val.push(email_val);
		}
		else rsUI.load_v4_demo_new();
	}
	else {
		jQuery('#email-req').attr('value','Invalid e-mail address.');
		jQuery('#email-req').addClass('error');
		jQuery('#mail-me-sel #textbox').addClass('errorbox');
	}	
    },
	trackFlash:function(msg){
        s.eVar34=msg;
        s.t();
    },
    submitform_and_open_personal_demo:function(){
        var langCode = $('ul#drpdown li.selected').attr('id');
        if(tnt_module == 0){ 
        langCode = $('ul#drpdown-tnt li.selected').attr('id');}
        var email_val = jQuery('#email-req').val();
        if(document.getElementById("language") != null)
            document.getElementById("language").value = fullLangName;
        if(email_val && email_val != "E-mail Address" && rsUI.isValidEmailAddress(email_val)) {
			var redirtodemo = false;
            if(jQuery.inArray(email_val,pre_email_val) == -1){
                jQuery.post('/content/rs/us/en_US/form/ajax.html?skipvalidation=true', jQuery('#flash-demo-module').serialize(),function(data){
                    data=jQuery.trim(data);
                    if(data == '[{"cisFlag":"true"}]') {
						if (catDemoFlag != null && window.location.pathname.match(/^[\/a-zA-Z]*\/(learn-english|learn-spanish|learn-german|learn-japanese)[^-]*$/) != null) {
							$.facebox(function() {
								$.ajax({
									error: function() {
									$.facebox('There was an error when attempting to fetch page. Please try again shortly.');
									},
									success: function(data) {
									$.facebox(data);
									},
									type: 'get',
									url: '/catalog-demo-test'
								});
							});
						}
						else {
							window.location="/personal/demo?language=" + langCode;
						}
						return false;
					}
                    else {
                        jQuery('#textbox').html('Error processing.');
					}
                });
                pre_email_val.push(email_val);
            }
			else {
				redirtodemo = true;
			}

			if (redirtodemo == true) {
				if (catDemoFlag != null && window.location.pathname.match(/^[\/a-zA-Z]*\/(learn-english|learn-spanish|learn-german|learn-japanese)[^-]*$/) != null) {
					$.facebox(function() {
						$.ajax({
							error: function() {
							$.facebox('There was an error when attempting to fetch page. Please try again shortly.');
							},
							success: function(data) {
							$.facebox(data);
							},
							type: 'get',
							url: '/catalog-demo-test'
						});
					});
				}
				else {
					window.location="/personal/demo?language=" + langCode;
				}
			}
        }
        else {
            jQuery('#email-req').attr('value','Invalid e-mail address.');
            jQuery('#email-req').addClass('error');
            jQuery('#mail-me-sel #textbox').addClass('errorbox');           
        }   
    },
    getQueryParameter:function(name)
    {
  	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  	var regexS = "[\\?&]"+name+"=([^&#]*)";
  	var regex = new RegExp( regexS );
  	var results = regex.exec( window.location.href );
  	if( results == null )
    	return "";
  	else
    	return decodeURIComponent(results[1].replace(/\+/g, " "));
    },
    initiateLightBoxes:function(){
	jQuery(document).ready(function(){
		jQuery('a[rel*=storiesbox]').facebox({skin:'mt',fb_heading:'Real People. Real Results',opacity:0.7});
        jQuery('a[rel*=researchbox]').facebox({skin:'mt',fb_heading:'Research',opacity:0.7});
		jQuery('a[rel*=celebritiesbox]').facebox({skin:'mt',fb_heading:"Look who's using Rosetta Stone",opacity:0.7});
		jQuery('a[rel*=reviewsvideo]').facebox({skin:'reviews',opacity:0.7,close_img_url:'/content/dam/rosettastonecom/images/mt/reviews/close-icon.png'});
	});
    },
    closeFacebox:function(){
      if(document.getElementById('facebox'))
        document.getElementById('facebox').style.display = "none";
      jQuery(document).trigger('close.facebox');
      return false;
    },
    setupFaqLink:function(){
        //When a user clicks on the FAQ link from the footer they can view the corresponding faq page depending on which silo
        if(document.getElementById("faq-link")){
                var url=document.location.href;
                if(url.indexOf("enterprise")!=-1) {
                        jQuery("#faq-link").attr("href","/enterprise/faq");
                } else if(url.indexOf("government")!=-1) {
                        jQuery("#faq-link").attr("href","/government/faq");
                } else if(url.indexOf("schools")!=-1) {
                        jQuery("#faq-link").attr("href","/schools/faq");
                } else if(url.indexOf("homeschool")!=-1) {
                        jQuery("#faq-link").attr("href","/homeschool/faq");
                }
        }
    }
}

var loadVideoLightbox = rsUI.loadVideoLightbox; // For home flash

/*
 * Extend jQuery for _applyMenuControls
 */
$.fn.enableMenuOverlay = rsUI._applyMenuControls;

var pre_email_val=new Array(); 

$.fn.virtualWidth = function(){
    var cc = $(this).clone(true);
    cc.css({width:'auto',position:'absolute',visibility:'hidden',display:'block'});
    $('body').append(cc);
    var w = cc.outerWidth();
    cc.remove();
    return w;   
};


/*
 * Initialize the page(s)
 */ 

$(function(){
    rsUI.domLIFix();
    rsUI.initCountryDropdown();
    rsUI.initSubMenus(); 
    rsUI.initLangDropdown();
    rsUI.initSupportDropdown();
    rsUI.signupInit();
    rsUI.subnavActivate();
    rsUI.setupAjaxFormHooks();
    rsUI.tertiaryNavActivate();
    rsUI.offeringActivate();
    rsUI.offeringActivateHS();
    rsUI.rotateLangs();
    rsUI.audioMenus();
    rsUI.comparisonTooltipMenus();
    rsUI.initiateLightBoxes();
    rsUI.setupDemoModule();
    rsUI.setupFaqLink();
});



