$.menu = function(index1,index2,index3) {
  $('#banner').appendBanner(index1,index2,index3).innerfade({
    speed: 2500,
	  timeout: 8000,
	  type: 'random',
	  containerheight: '214px'
  });
  
  $(function(){		
    jQuery('#menu > a').eq(index1-1).css('background-position','0px -60px');
    if(index3 == 0) {
      jQuery('#leftMenu > li').eq(index2-1).find('a').eq(0).css('color','#196591')
      .css('background-image','url(img/common/icon_menuleft02.gif)');
      jQuery('#leftMenu > li').eq(index2-1).find('dl').eq(0).css('display','block');
    } else if(index3) {
      jQuery('#leftMenu > li').eq(index2-1).find('dl').eq(0).css('display','block')
      .find('dd').eq(index3-1).find('a').eq(0).css('color','#196591')
      .css('background-image','url(img/common/icon_menuleft04.gif)');   
    } else {   
      if(index1==3 && !!index2) {      	
        var a = jQuery('#leftMenu > li').eq(index2-1).find('a').eq(0);
        a.css('color','#196591').css('background-image',a.css('background-image').replace('_on','_off'));        
      } else {
        jQuery('#leftMenu > li').eq(index2-1).find('a').eq(0).css('color','#196591')
        .css('background-image','url(img/common/icon_menuleft02.gif)');
      }
    }  
  });	
};	

$.fn.appendBanner = function(m1,m2,m3) {	
  function add(o, count, id) {
    for(i=1; i<=count; i++) {
      o.append('<li style="display:none"><img src="img/banner/bn_'+id+i+'.png"></li>')
    }    	
  }
  
  return this.each(
    function() {
    	var o = $(this);
    	  
    	if(m1==1) {
    	  if(m2==3) {
    	    add(o, 5, 'z');
    	  } else {
    	    add(o, 3, 'a');
        }      	  
      } else if(m1==2) {
    	  add(o, 3, 'b');      	  
      } else if(m1==3) {
        if(m2==1) {
          add(o, 3, 'ca');	
        } else if(m2==2) {
          add(o, 3, 'cb');
        } else if(m2==3) {
          add(o, 3, 'cc');
        } else if(m2==4) {
          add(o, 3, 'cd');
        } else if(m2==5) {
          add(o, 3, 'ce');
        } else if(m2==6) {
          add(o, 3, 'cf');
        } else {
          add(o, 18, 'c'); 
        }    	  
      } else if(m1==4) {
    	  add(o, 5, 'd');      	  
      } else if(m1==5) {
    	  add(o, 2, 'e');      	  
      } else if(m1==6) {
    	  add(o, 2, 'f');      	  
      } else {
        add(o, 3, 'n');    	  
      }
      
    }
  );    	
}

$.fn.previewImg = function() {	
	$.pi = false;      
  $('<div id="iDiv" class="previewImg"><img id="iImg" src=""></div>').appendTo('body'); 
  
  this.each(function(i){ 
    (new Image()).src = this.href;                	      	  
  });
       
  this.mousemove(function(e){
    $('#iDiv').css({
      top: e.pageY + 12 + 'px',
      left: e.pageX + 12 + 'px'
    })
  })   
  .hover(function(){  
  	$.pi = false; 
    $('#iImg').attr('src',$(this).attr('href'));     
    $('#iDiv').fadeIn('normal',function(){
        if($.pi) $('#iDiv').hide(); 
    });            
  }, function(){
    $.pi = true;
    $('#iDiv').hide();          
  });  

  return this;
};

$.fn.previewText = function() {	  
	$.pt = false;  
  $('<div id="tDiv" class="previewText"></div>').appendTo('body'); 
       
  this.mousemove(function(e){
    $('#tDiv').css({
      top: e.pageY + 12 + 'px',
      left: e.pageX + 12 + 'px'
    })
  })   
  .hover(function(){   
  	$.pt = false;       
    $('#tDiv').html($(this).attr('title')).fadeIn('normal',function(){
        if($.pt) $('#tDiv').hide(); 
    });      
  }, function(){
    $.pt = true; 
    $('#tDiv').hide();            
  });  

  return this;
};

function showMyImg(i){
  var time = 800;
	$("#img img")
	  .eq(i).stop(true,true).fadeIn(time)
		.parent().siblings().find("img").hide();
	$("#msg dd")
	  .eq(i).stop(true,true).fadeIn(time)
		.siblings().hide();
	$("#btn span")
		.eq(i).addClass("hov")
		.siblings().removeClass("hov");
}

$(function(){	
/* init...start ------------------------------ */


if($('#bottom_info')[0]) {		
  var time = 5000;
  var len = 5;
	var index = 0;
	var MyTime = setInterval(function(){
	  showMyImg(index);
		index++;
		if(index==len) index=0;
	}, time);
	 
  $("#btn span").mouseover(function(){
		index = $("#btn span").index(this);
		showMyImg(index);
	});	
	
  $('#imgnav').hover(function(){
	  if(MyTime) clearInterval(MyTime);			  
	},function(){
	  MyTime = setInterval(function(){
		  showMyImg(index);
			index++;
			if(index==len) index=0;
		}, time);
	});	 
		
}		
			  	
if($('#textPreview')[0]) {	
  $("#textPreview a").previewText();    
}
  
	
/* init...end	------------------------------ */
});	