//This has been added since jquery 1.3 does not support delay fn
$.fn.delay = function(time, callback){
   // Empty function:
   jQuery.fx.step.delay = function(){};
   // Return meaningless animation, (will be added to queue)
   return this.animate({delay:1}, time, callback);
}
$(document).ready(function () {
	$('#first-tab').delay(0).animate({'background-position': '0px 10px'});
	$('#second-tab').delay(400).animate({'background-position': '0px 10px'});
	$('#third-tab').delay(800).animate({'background-position': '0px 10px'});
	$('#fourth-tab').delay(1200).animate({'background-position': '0px 10px'});	
	
	$('#catalog_guarantee,#cat-demo-module').hide().delay(1400).fadeIn(0400);
	$('#levels').hide().delay(1600).fadeIn(0400);
	$('#savings-footnote').hide().delay(1800).fadeIn(0400);
	$('#social-media').hide().delay(2000).fadeIn(0400);
	$('#footer').hide().delay(1600).fadeIn(0400);
	
	$('#first-tab').addClass('active-firsttab');
    $('#first-tab').hover(function() {
    //hover in
        if($('#first-tab').hasClass("inactive-firsttab")){ 
		var current_url=window.location.href;
              if(current_url.indexOf("learn-arabic")!=-1){
                 $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/arabic-hover.png')"); 
            }else if(current_url.indexOf("learn-dutch")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-dutch-hover.png')"); 
			}else if(current_url.indexOf("learn-english")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-english-hover.png')"); 
			}else if(current_url.indexOf("learn-english-british")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-english-hover.png')"); 
			}else if(current_url.indexOf("learn-tagalog")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-tagalog-hover.png')"); 
			}else if(current_url.indexOf("learn-french")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-french-hover.png')"); 
			}else if(current_url.indexOf("learn-german")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-german-hover.png')"); 
			}else if(current_url.indexOf("learn-greek")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-greek-hover.png')"); 
			}else if(current_url.indexOf("learn-hebrew")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-hebrew-hover.png')"); 
			}else if(current_url.indexOf("learn-hindi")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-hindi-hover.png')"); 
			}else if(current_url.indexOf("learn-irish")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-irish-hover.png')"); 
			}else if(current_url.indexOf("learn-italian")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-italian-hover.png')"); 
			}else if(current_url.indexOf("learn-japanese")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-japanese-hover.png')"); 
			}else if(current_url.indexOf("learn-korean")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-korean-hover.png')"); 
			}else if(current_url.indexOf("learn-farsi")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-persian-hover.png')"); 
			}else if(current_url.indexOf("learn-polish")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-polish-hover.png')"); 
			}else if(current_url.indexOf("learn-portuguese")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-portuguese-hover.png')");  
			}else if(current_url.indexOf("learn-spanish")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-spanish-hover.png')"); 
			}else if(current_url.indexOf("learn-spanish-spain")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-spanish-hover.png')"); 
			}else if(current_url.indexOf("learn-swedish")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-swedish-hover.png')"); 
			}else if(current_url.indexOf("learn-turkish")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-turkish-hover.png')"); 
			}else if(current_url.indexOf("learn-vietnamese")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-vietnamese-hover.png')"); 
			}else if(current_url.indexOf("learn-chinese")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-chinese-hover.png')"); 
			}else if(current_url.indexOf("learn-russian")!=-1){
                   $(this).css("background-image", "url('/content/dam/rosettastonecom/images/animatedtabs/learn-russian-hover.png')"); 
			}
           
           $(this).stop().animate({'background-position': '0px 0px'})
         }
     }, function (){
     //hover out
	 // condition changed to active-firsttab to stop hover function on the active image
          if($('#first-tab').hasClass("active-firsttab")){
            $(this).stop().animate({'background-position': '0px 10px'})
         }
		  if($('#first-tab').hasClass("inactive-firsttab")){
            $(this).stop().animate({'background-position': '0px 10px'})
         }
    });
	
	$('#second-tab').hover(function() {
	//hover in
	 if($('#second-tab').hasClass("active-secondtab")){ 
		$(this).stop().animate({'background-position': '0px 10px'})
            }
			else {
			$(this).stop().animate({'background-position': '0px 0px'})
			}
	}, function (){
	//hover out
		$(this).stop().animate({'background-position': '0px 10px'})

		}); 
		$('#third-tab').hover(function() {
	//hover in
	 if($('#third-tab').hasClass("active-thirdtab")){ 
		$(this).stop().animate({'background-position': '0px 10px'})
            }
			else {
			$(this).stop().animate({'background-position': '0px 0px'})
			}
	}, function (){
	//hover out

		$(this).stop().animate({'background-position': '0px 10px'})

		
		}); 
		
		
		
		$('#fourth-tab').hover(function() {
	//hover in
	 if($('#fourth-tab').hasClass("active-fourthtab")){ 
		$(this).stop().animate({'background-position': '0px 10px'})
            }
			else {
			$(this).stop().animate({'background-position': '0px 0px'})
			}
	}, function (){
	//hover out
		$(this).stop().animate({'background-position': '0px 10px'})

		}); 
    
  $('#first-tab').click( function() {
      $('#second-tab,#third-tab,#fourth-tab').removeClass('active-secondtab').removeClass('active-thirdtab').removeClass('active-fourthtab');
      $(this).addClass('active-firsttab');
      $('#first-tab').removeClass('inactive-firsttab'); // to bring the active image on click
});
  $('#second-tab').click( function() {
     $('#first-tab,#third-tab,#fourth-tab').removeClass('active-firsttab').removeClass('active-thirdtab').removeClass('active-fourthtab');;
     $(this).addClass('active-secondtab');
	 $('#first-tab').addClass('inactive-firsttab');
   });
  $('#third-tab').click( function() {
     $('#first-tab,#second-tab,#fourth-tab').removeClass('active-firsttab').removeClass('active-secondtab').removeClass('active-fourthtab');;
     $(this).addClass('active-thirdtab');
	 $('#first-tab').addClass('inactive-firsttab');
    
});
 $('#fourth-tab').click( function() {
     $('#first-tab,#second-tab,#third-tab').removeClass('active-firsttab').removeClass('active-secondtab').removeClass('active-thirdtab');
     $(this).addClass('active-fourthtab');
	 $('#first-tab').addClass('inactive-firsttab');
     
});
});



