  $(document).ready(function() {
    DisplayNavigation();    
     
    if($('#slide .slogan').length > 0) {
      $("#slide .slogan .textitem").first().addClass('active');
      HideText();
    }

    if($("#slide .slogan_left").length > 0) {
      Cufon.replace('#slide .slogan_left',{textShadow: '#333 1px 1px'});  
    }
  
  	var Autostop = 2;
    if($('.homepage-check').length > 0){
    	Autostop = 0;	
    } 
    
    $("#slide .images").cycle({ 
      fx: 'fade',
      timeout: 2500,
      speed: 800,
      after: function(currSlide, nextSlide, opts) {
        // change timeout for first slide
       // var index = $(this).parent().children().index(this);
       // opts.timeout = Counter % 2 == 0 ? 3000 : 2000;
        slideSwitchDiv();
      } ,
      before: HideText, 
	  autostop:Autostop
    });
        
    if($('.partner-list').length > 0){
      positionImages();
    }
    
  });
  
  var Counter = 0;
    
  function HideText(){
    Cufon.replace('#slide .slogan .active',{textShadow: '#333 1px 1px'});
    if(Counter % 2 != 0 || Counter == 0) {
      return false;  
    }
      var ParentDiv = $('#slide .slogan');  
      var Active = $('.active', ParentDiv);
      //Active.removeFE(false);
      Active.fadeOut();
    
  }
    
  function slideSwitchDiv() {
    if(Counter % 2 != 0 || Counter == 0) {
      Counter++;
      return false;  
    }
    Counter++;
    var ParentDiv = $('#slide .slogan');  
    var Active = $('.active', ParentDiv);
    var Next    = "";

    if ( Active.length == 0 )  { 
      Active = $('.textitem:last', ParentDiv);
    }
    
    if(Active.next().length) {
      Next = Active.next();
    } else {
      Next = $('.textitem:first', ParentDiv);
    }

    Active.addClass('last-active').hide();
     
    Next.css("display", "none").addClass('active').show();
   Cufon.replace('#slide .slogan .active',{textShadow: '#333 1px 1px'});
   // Next.redrawFE();
          
    Active.removeAttr("filter").removeClass('active last-active');
    
  }

  function positionImages() { 
    var ImageDiv    = $('.partner-list');
    var ImageCount   = 0;
    var TotalImages = $('.partner-list .partner img').length;
    
    ImageDiv.css("visibility", "hidden");
     
    $('.partner-list .partner').each( function() {
    var _this = $(this);  
    var ImageObj = new Image();
    $(ImageObj).load(function () {
        $('img', _this).remove();
        $('a',_this).append(this);

        var top = ( _this.height() - parseInt($('img', _this).height()) ) / 2; 
        $('img', _this).css('margin-top', top + 'px');
        
        ImageCount++;   
        
        if(TotalImages == ImageCount) {
          ImageDiv.css("visibility", "visible");
        } 
      }).error(function () {
      }).attr({'src':$('img', _this).attr('src'), 'alt': $('img', _this).attr('alt')});
    }); 
  }

  function DisplayNavigation()
    {
      var NavigationElement      = $("a.slide");
      var SubNavigationContainer = $("ul.sub");
        
      NavigationElement.each(function(){
        NavigationElement.hover(function() {
          $(this).next("ul.sub").animate({
            height: $(this).next("ul")[0].scrollHeight + "px"
          }, {queue: false });  
        }, function() {
          $(this).next("ul.sub").animate({
            height: "0px"
          }, {queue: false });  
        });
    
        SubNavigationContainer.hover(function() {
          $(this).stop();
          $(this).animate({
            height: $(this)[0].scrollHeight + "px"
          }, {queue: false });  
        }, function() {
          $(this).animate({
            height: "0px"
          }, {queue: false });  
        });
      });      
    }
