var rsUI = {
	/*
	 * Simulate first-child, last-child on <li> elements
	 */
	domLIFix:function(){
              if($('ul')){
		$('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>Refuerce su aprendizaje en cualquier lugar, en el hogar, en el auto o mientras est\341 de viaje.</strong>';
			html += '<ul><li>Descargue los archivos de sonido en su reproductor de MP3 o computadora.</li>';
			html += '<li>Acceda a sus lecciones en cualquier momento o lugar.</li>';
			html += '<li>Escuche y repita preguntas y respuestas para utilizar en conversaciones.</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 == 'curso rosetta') {
                          html += '<p>Nuestro galardonado programa que recrea la manera natural en la que se aprende un idioma.</p>';
                        }
                        else if(caller.id == 'conversation-skills') {
                          html += '<p>Aprenda a presentarse, saludar a los dem\341s, ir de compras y m\341s.</p>';
                        }
                        else if(caller.id == 'navigate-surroundings') {
                          html += '<p>Cene fuera, d\351 y reciba direcciones, use el transporte y m\341s.</p>';
                        }
                        else if(caller.id == 'express-ideas') {
                          html += '<p>Comparta sus ideas, hable de sus intereses, la vida diaria y m\341s.</p>';
                        }
                        else if(caller.id == 'negotiate-arrangements') {
                          html += '<p>Coordine reparaciones, cambie citas, m\372dese al extranjero y m\341s.</p>';
                        }
                        else if(caller.id == 'manage-situations') {
                          html += '<p>Responda a emergencias, discuta sobre trabajo, explore la cultura y m\341s.</p>';
                        }
                        else if(caller.id == 'rosetta estudio') {
		    	  html += '<p>Practique en nuestro entorno de aprendizaje en vivo con un';
                          html += ' profesor de habla nativa en Studio.</p>';
                        }
                        else if(caller.id == 'hablante nativo') {
                          html += '<p>Descubra comentarios y orientaci\363n en tiempo real mientras explora su nuevo idioma.</p>';
                        }
                        else if(caller.id == 'conversaci\363n guiada') {
                          html += '<p>Refuerce sus habilidades de hablar con otros mientras recibe asistencia';
                          html += ' de nuestros profesores en Studio.</p>';
                        }
                        else if(caller.id == 'sesiones en vivo') {
                          html += '<p>Horario ilimitado, sesiones de una hora y recordatorios establecidos.</p>';
                        }
                        else if(caller.id == 'mundo rosetta') {
                          html += '<p>Juegue en nuestra exclusiva comunidad en l\355nea dedicada a los idiomas y a la investigaci\363n.</p>';
                        }
                        else if(caller.id == 'gr\341fica estructurada') {
                          html += '<p>Comun\355quese con otros estudiantes en su nuevo idioma.</p>';
                        }
                        else if(caller.id == 'juegos con idiomas') {
                          html += '<p>Explore un nuevo idioma mediante atractivos juegos y actividades.</p>';
                        }
                        else if(caller.id == 'simbio de intercambio') {
                          html += '<p>Sesiones en tiempo real en las que hablantes nativos le ayudan con su';
                          html += ' investigaci\363n sobre el idioma, mientras ayuda a otros tambi\351n.</p>';
                        }
                        else if(caller.id == 'agentes de \351xito') {
                          html += '<p>Agentes de \351xito que siempre est\341n disponibles para preguntas, preocupaciones y asistencia.</p>';
                        }
                        else if(caller.id == 'audio-companion') {
                          html += '<p>Estos CD le permiten reforzar lo que aprende con Rosetta Stone:';
                          html += ' en su hogar, en el auto o mientras est\341 de viaje.</p>';
                        }
                        else if(caller.id == 'six-month-guarantee') {
                          html += '<p>Estamos tan seguros de que usted tendr\341 \351xito en su aprendizaje de idiomas que le proporcionamos';
                          html += ' una garant\355a de devoluci\363n del dinero de 6 meses si usted no est\341 totalmente satisfecho con nuestro software en CD-ROM.';
                          html += ' Disponible s\363lo al comprar directamente de Rosetta Stone.</p>';
                        }
                        else if(caller.id == 'delivery-method') {
                          html += '<p>Nuestra soluciones se pueden comprar como CD-ROM o como una suscripci\363n en l\355nea';
                          html += ' que le permite iniciar sesi\363n con una conexi\363n a internet.</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-men\372').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>');
                        if(navigator.userAgent.indexOf('MSIE 6')!= -1 && document.getElementById('bgi-frame')) d.bgiframe();
                        d = d.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')){
           $('.country-select li.active a').enableMenuOverlay(rsUI.menuDefinitions._countryMenu);
         }
	},
	
	initSupportDropdown:function(){
          if($('.support-select>a')){
	    $('.support-select>a').enableMenuOverlay(rsUI.menuDefinitions._supportMenu);
          }
	},



        hide_langdropdown:function(){
          var s1 = $('#lang-selections');
            $('#lang-selections ul li a').click(function(e){
              e.preventDefault();
              $(this).addClass('active');
              $('body').bind('click',rsUI._closeLangBox);
              s1.show(50,function(){});
            });
        },


	
	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')){ 
                     if($('#lang-list-selections').is(':visible')) 
                         $('#lang-list-selections').hide() 
                 }
                 if($('#lang-select-totale-buynow')){
                     if($('#lang-select-totale-buynow').is(':visible'))
                          $('#lang-select-totale-buynow').hide()
                 }
                 if($('#holiday-lang-selections')){
                     if($('#holiday-lang-selections').is(':visible'))
                          $('#holiday-lang-selections').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.cerrar selecci\363n').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')){
              $('#buynow_img').mouseover(function(e){
                 $('#buynow_img').addClass('active');
              });
              $('#buynow_img').mouseout(function(e){
                 if($('#lang-list-selections').is(':hidden'))
                   $('#buynow_img').removeClass('active');
              });
              $('#buynow_img').click(function(e){
                 $('#buynow_img').addClass('active'); 
                 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 = "400px"; 
	                  document.getElementById("lang-list-selections").style.top = "76px";
	                } 
	                else{ 
	                  document.getElementById("lang-list-selections").style.left = "407px"; 
	                  document.getElementById("lang-list-selections").style.top = "76px"; 
	                }        
	              } 
	              else{ 
	              document.getElementById("lang-list-selections").style.left = "407px"; 
	              document.getElementById("lang-list-selections").style.top = "76px"; 
	              } 
	         e.preventDefault(); 
	         var s1 = $('#lang-list-selections'); 
	         if($('#lang-selections')){ 
	             if($('#lang-selections').is(':visible')) 
 	                  $('#lang-selections').hide() 
	         } 
                 if($('#lang-select-totale-buynow')){
                     if($('#lang-select-totale-buynow').is(':visible'))
                          $('#lang-select-totale-buynow').hide()
                 }
                 if($('#holiday-lang-selections')){
                     if($('#holiday-lang-selections').is(':visible'))
                          $('#holiday-lang-selections').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.cerrar selecci\363n').length == 0){ 
	                  var a = $('<a>').addClass('close-selection').click(function(){s1.hide();$('#buynow_img').removeClass('active');});
	                  s1.append(a); 
	                } 
	             }); 
	         } 
	       return false; 
	       }); 
	     }
             if($('#drpdwn')){
               $('#drpdwn').click(function(e){
               $('#drpdwn').addClass('active'); 
               e.preventDefault(); 
               var s1 = $('#lang-selections'); 
               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(){});
               }
               return false; 
              }); 
             }
             if($('#lang-totale-buynow')){
               $('#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')){
                     if($('#lang-selections').is(':visible'))
                          $('#lang-selections').hide()
                 }
                 if($('#lang-list-selections')){
                     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.cerrar selecci\363n').length == 0){
                            var a = $('<a>').addClass('close-selection').click(function(){s1.hide()});
                            s2.append(a);
                          }
                        });
                 }
               return false;
               });
             }
	  
          if($('#totale-lang-dropdown span.title a')){	
            $('#totale-lang-dropdown span.title a').click(function(e){
	    e.preventDefault();
                 var s = $('#lang-select-totale-buynow');
                 if($('#lang-list-selections')){ 
                     if($('#lang-list-selections').is(':visible')) 
                         $('#lang-list-selections').hide() 
                 }
                 if($('#lang-select-totale-buynow')){
                     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.cerrar selecci\363n').length == 0){
		 	      var a = $('<a>').addClass('close-selection').click(function(){s.hide()});
			      s.append(a);
			}
		    });
		}
	     return false;			
	     });
	  }	
            if($('#holiday-drpdwn')){
               var s2 = $('#holiday-lang-selections');
               $('#holiday-drpdwn').click(function(e){
                 if(document.getElementById('popup_frame'))
                 e.preventDefault();
                 if($('#lang-selections')){
                     if($('#lang-selections').is(':visible'))
                          $('#lang-selections').hide()
                 }
                 if($('#lang-list-selections')){
                     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.cerrar selecci\363n').length == 0){
                            var a = $('<a>').addClass('close-selection').click(function(){s2.hide()});
                            s2.append(a);
                          }
                        });
                 }
               return false;
               });
             }

          if($('#totale-lang-dropdown span.title a')){
            $('#totale-lang-dropdown span.title a').click(function(e){
            e.preventDefault();
                 var s = $('#lang-select-totale-buynow');
                 if($('#lang-list-selections')){
                     if($('#lang-list-selections').is(':visible'))
                         $('#lang-list-selections').hide()
                 }
                 if($('#lang-select-totale-buynow')){
                     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.cerrar selecci\363n').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)}); 
                        $('#buynow_img').removeClass('active');
	       } 
               var s2 = $('#lang-select-totale-buynow');
               if(s2.is(':visible')){
                        s2.hide(50,function(){ $('body').unbind('click',rsUI._closeLangBox)});
               }
               var s3 = $('#holiday-lang-selections');
               if(s3.is(':visible')){
                        s3.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')){   
       $('#subnav>ul>li').each(function(){
         var li = $(this);
	 if(li.find('ul.sub-men\372').length > 0){
	   li.find('a:first').enableMenuOverlay(rsUI.menuDefinitions._subMenu);
	 }	
       });
     }
     if($('#hispanic_subnav>ul>li')){
       $('#hispanic_subnav>ul>li').each(function(){
         var li = $(this);
         if(li.find('ul.sub-men\372').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')){
         $('#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() == '' ? 'su direcci\363n de e-mail aqu\355' : me.val());			
		});		
         }
	},

        setupAjaxFormHooks:function(){
                var timer;
                // naive
                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')){
                $('#email-form').submit(function(e){
                        e.preventDefault();
                        var email = this['form[email]'].value;
                        var name = this['form[cis_name]'].value;
                        var redirect = this['form[redirect_to]'].value;
                        var source = this['form[import_source]'].value;
                        var id = this['form[identifier]'].value;
                        var post_str = 'form[email]=' + email + '&form[cis_name]=' + name + '&form[import_source]=' + source + '&form[redirect_to]=' + redirect + '&form[identifier]=' + id;
                        jQuery.ajax({
                               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 and homepage only. (lazy regexp ok)
                                   if(s && s.tl && document.location.href.match(/(personal|schools|organizations|homeschool|\/)$/)){ 
                                     //do the thing
                                     s.linkTrackVars="eventos";
                                     s.events = "event38";
                                     s.linkTrackEvents="event38";
                                     s.tl('true', 'o', 'Inscribirse al bolet\355n electr\363nico');
                                   }
                                 }
                                 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.activa')){
		 /* This style is blocked for the new second level navigation
                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(/us_assets/redesign/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(/us_assets/redesign/images/inavbgleft.gif) no-repeat top left',
				height:'25px', 
				color:'#000',
				paddingLeft:10,
                                width:a.outerWidth() - 20
			});
			
			//$(a).before(d.append(dd));			
		}*/
           }
           if($('#hispanic_subnav>ul>li>a.activa')){
                var a = $('#hispanic_subnav>ul>li>a.activa');
                a.css({position:'relative',zIndex:3})
                if(a.length >0){
                        var d = $('<div>').css({
                                position:'absolute',
                                background:'transparent url(/us_assets/redesign/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(/us_assets/redesign/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')){
                $('.internal-nav ul li').hover(function(){ $(this).addClass('hover')},function(){$(this).removeClass('hover')});}
if($('.internal-nav-condensed ul li')){
                $('.internal-nav-condensed ul li').hover(function(){ $(this).addClass('hover')},function(){$(this).removeClass('hover')});
}
	},
	offeringActivate:function(){
	if($('#product-offering>ul>li>a')){	
		$('#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');
		});		
         }
	},
        offeringActivate_def:function(){
          if($('#product_notes>ul>li>a')){
            $('.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')){
      $('.audio-companion').each(function(){
			var tag = $(this);
			tag.enableMenuOverlay(rsUI.menuDefinitions._audioMenu);		
		});		}
	},
	comparisonTooltipMenus:function(){
            if($('.comparison-tooltip')){
                $('.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://espanol.rosettastone.com/us_assets/redesign/flash/MiniVideo.swf',
            express_install: 'http://espanol.rosettastone.com/us_assets/redesign/flash/expressInstall.swf',
            bgcolor: 'fbf8e5',
            wmode: 'transparent',
            base: 'http://espanol.rosettastone.com/us_assets/redesign/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://espanol.rosettastone.com/us_assets/redesign/flash/VideoApplication.swf';
            params.express_install = 'http://espanol.rosettastone.com/us_assets/redesign/flash/expressInstall.swf';
            params.bgcolor = 'fbf8e5';
            params.wmode = 'transparent';
            params.base = 'http://espanol.rosettastone.com/us_assets/redesign/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:'http://espanol.rosettastone.com/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')){
		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(){
			
			});
		});		
	}
}

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

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

$.fn.virtualWidth = function(){
	var cc = $(this).clone(true);
	cc.css({width:'auto',cssFloat:'left',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.rotateLangs();
	rsUI.audioMenus();
        rsUI.comparisonTooltipMenus();
});
