(function($){

  $(document).ready(function(){

    var class_array = $('body').attr('class').split(' ');
    var cate = class_array[1];


$('.photos a').lightBox();

    function hookHover () {
      $('div#ghNav a.hover').each(function(){
        $(this).children('img').each(function(){
          this.orgsrc = this.src;
          var src = this.src.split('.');
          src[src.length - 2] = src[src.length - 2] + '_o';
          this.hoversrc = src.join('.');

/* alert($(this).parent().parent().attr('class')) */
          
          if ($(this).parent().parent().hasClass(cate)) {
            $(this).attr('src', this.hoversrc);
            this.orgsrc = this.hoversrc;
          }
        });
      });

/*
		var current = $('body').attr('class');
		var postfix = '_o';
		$('a.hover img').not('[src*="'+ postfix +'."]').each(function() {
			var img = $(this);
			var src = img.attr('src');
			var src_on = src.substr(0, src.lastIndexOf('.'))
									+ postfix
									+ '.png';
			if (img.parent().parent().hasClass(current)) {
				img.attr('src', src_on);
			}
		}
*/

      $('a.hover').parent().mouseover(function(){
        $(this).find('a.hover img').each(function(){
          this.src = this.hoversrc;
        });
      });

      $('a.hover').parent().mouseout(function(){
        $(this).find('a.hover img').each(function(){
          this.src = this.orgsrc;
        });
      });
    }

    function hookRel () {
      $('a').each(function(){
        if($(this).attr("rel") == "external"){
          $(this).attr("target", "_blank");
        }
      });
    }
    
    function sidebarCurrent () {
      $('div#sideBar a').each(function(){
        if ($(this).attr("href") == location.href) {
          $(this).parent().attr("class", "current");
        }
      });
    }

    function pulldownMenu() {
      $('.pulldown-item').each(function() {
        var theContent = $(this).find('.pulldown-content');
        var contentHeight = theContent.height();
        $(this).hover(function(){
          theContent.stop();
          theContent.show();
          theContent.height(0);
          theContent.animate(
            {height: contentHeight + 'px'},
            {duration: contentHeight / 4 + 125, easing: 'swing'}
          );
        },function(){
          theContent.stop();
          theContent.hide();
        });
      });
    }
    
    function hotNews() {
      $('div#hotNews').each(function(){
        var theDiv = $(this);
        var theLi = $(this).find('li');
        if (theLi.length > 1) {
          var currentLi = 0;
          var liWidth = $(this).width() - $(this).find('dt').width() - 10;
          theLi.css({position:'absolute', top:'0', left:'0', width: liWidth + 'px'});
          theLi.hide();
          theLi.eq(currentLi).show();
          
          setInterval(function(){
            liWidth = theDiv.width() - theDiv.find('dt').width() - 10;
            theLi.eq((currentLi + 1) % theLi.length).css({
              left: liWidth + 10 + 'px',
              width: liWidth + 'px'
            });
            theLi.eq((currentLi + 1) % theLi.length).show();
            theLi.eq(currentLi).animate({
              left: -liWidth + 'px'
            },{
              duration: 1000,
              easing: 'swing'
            });
            theLi.eq((currentLi + 1) % theLi.length).animate({
              left: '0'
            },{
              duration: 1000,
              easing: 'swing',
              complete: function(){
                theLi.eq(currentLi).hide();
                currentLi = (currentLi + 1) % theLi.length;
              }
            });
          }, 5000);
        }
      });
    }

/*
    var bodyElement = document.getElementsByTagName('body')[0];
    var bodyClasses = bodyElement.className;
    classNames = bodyClasses.toString();
    var className_array = classNames.split(" ");
    langName = className_array[0];

*/
    
    hookHover();
    hookRel();
    sidebarCurrent();
    pulldownMenu();
    hotNews();
  });

  $(document).resize(function(){
  });

})(jQuery.noConflict());





