var sscount = 0;
var barbgp = 0;
var speed = 2;
var nextImage = '';
var bAni = 0;


  $(document).ready(function() {
      
      initSlides();
    checkBrowser();
	
        $('.bottom_promo_inner').scrollLeft(0);
          if (navigator.appName != 'Microsoft Internet Explorer'){
        bAni = setInterval("promoSlide()",5000);
          }
    

        if (window.admin === undefined){
            // Normal user
        }
        else if (admin == 1) {
            // Admin user
            initAdmin();
        }
        if (navigator.appName != 'Microsoft Internet Explorer'){
        $('#bottom_promo').mouseover(function(){
            document.getElementById('slider_right').className = 'slider_on';
            document.getElementById('slider_left').className = 'slider_on';
            clearInterval(bAni);
        });
        $('#bottom_promo').mouseout(function(){
            document.getElementById('slider_right').className = 'slider_off';
            document.getElementById('slider_left').className = 'slider_off';
            if (navigator.appName != 'Microsoft Internet Explorer'){
            bAni = setInterval("promoSlide()",5000);
            }
        });
$(".bottom_pimg").hover(
function() {
$(this).stop().animate({"opacity": "1.0"}, "fast");
},
function() {
$(this).stop().animate({"opacity": "0.5"}, "fast");
});

        }
      else {
         document.getElementById('slider_right').className = 'slider_on';
            document.getElementById('slider_left').className = 'slider_on';   
      }
      
      

      
      
        $('#slider_right').click(function(){
            promoSlide();
        });
        $('#slider_left').click(function(){
            reverseSlide();
        });
        

  


        /* Dont run the bottom menu animation in Internet Explorer - It seems it requires better javascript performance than ie can deliver*/
          if (navigator.appName != 'Microsoft Internet Explorer'){
            setInterval("tick()",10);
          }
  });
function tick(){
		
		if (barbgp == -2001){
			barbgp = 0;
		}
		else {
			barbgp = (barbgp - speed);
		}
		$('#subnav').css('backgroundPosition', barbgp+'px 0px');
	}
function promoSlide(){
      var sl = $('.bottom_promo_inner').scrollLeft();
     
     // alert('Current Scroll = '+sl);
      if (sl > 3700){
            sl = 0;
            $('.bottom_promo_inner').scrollLeft(sl);
            sl = (sl + 1260);
            $(".bottom_promo_inner").animate({scrollLeft: sl}, 1000);
      }
      else {
            sl = (sl + 1260);
            //$('.bottom_promo_inner').scrollLeft(sl);
             $(".bottom_promo_inner").animate({scrollLeft: sl}, 1000);
      }
}
function reverseSlide(){
      /* Back up the image slider one screen */
      var sl = $('.bottom_promo_inner').scrollLeft();
      if (sl > 1200){
            sl = (sl - 1260);
            $(".bottom_promo_inner").animate({scrollLeft: sl}, 1000);
      }
      else {
          /* Go to the end */
          $('.bottom_promo_inner').scrollLeft(3780);
          $(".bottom_promo_inner").animate({scrollLeft: 2520}, 1000);
      }
}
function initSlideshow(){
    var max = bgz.length;
    if (max < 2){
    /* No slideshow.. only one image. */
    }
    else {
    //alert('Count:'+sscount+' Max: '+max)
        if (sscount < max){
          //  alert('change background');
          $( "#sshow" ).switchClass( "ssimg", "ssimgTrans", 200 );
          nextImage = bgz[sscount];
            setTimeout("changeImage()",300);
          
        }
        else {
         //   alert('restart bg count');
            sscount = 0;
          $( "#sshow" ).switchClass( "ssimg", "ssimgTrans", 200 );
          nextImage = bgz[sscount];
            setTimeout("changeImage()",300);
        }
        sscount++;
        setTimeout("initSlideshow()",10000);
    }
}

function changeImage(){
    document.getElementById('sshow').src = nextImage;
    $( "#sshow" ).switchClass( "ssimgTrans", "ssimg", 200 );
}



