$( document ).ready( function(){
  $.browser.msie || $( ".ellipsis>li" ).each( function(){
    $this = $( this );
    if (this.scrollWidth > this.clientWidth){
      trimli( this );
    }
  } );
  function trimli( element ){
    text = $( element ).text();
    $( element ).find( "a" ).text( text.slice( 0, -6 ) + '...' );
    if (element.scrollWidth > element.clientWidth){
      trimli( element );
    }
  }

  $( ".MenuTitle" ).each( function( i ){
    $( this ).mouseover( function(){
      $( ".MenuContent" ).eq( i ).show().mouseout( function(){
        $( this ).hide();
      } ).mouseover( function(){
        $( this ).show();
      } );
    } ).mouseout( function(){
      $( ".MenuContent" ).eq( i ).hide();
    } );
  } )
  $( ".Title_01Tab" ).each( function( i ){
    $( this ).mouseover( function(){
      $( ".Title_01Tab" ).removeClass( "active" );
      $( this ).addClass( "active" );
      $( ".Title_01Content" ).hide();
      $( ".Title_01Content" ).eq( i ).show();
    } ).css( 'cursor', 'default' );
  } );

  $( ".SearchKeyWord" ).each( function( i ){
    var SearchKeyWord = this;
    var KeyColor = $( this ).css( "color" );
    var KeyCue = "请输入关键字!";
    var KeyCueColor = "#bbbbbb";
    var KeyAlertColor = "#ff0000";
    $( this ).val() == "" && $( this ).val( KeyCue ) && $( this ).css( "color", KeyCueColor );
    $( this ).focus( function(){
      if ($( this ).val() == KeyCue){
        $( this ).val( "" );
      }
      $( this ).css( "color" ) != KeyColor && $( this ).css( "color", KeyColor );
    } );
    $( this ).blur( function(){
      $( this ).val() == "" && $( this ).val( KeyCue ) && $( this ).css( "color", KeyCueColor );
    } );
    $( this ).parents( "form" ).submit( function(){
      if ($( SearchKeyWord ).val() == KeyCue){
        $( SearchKeyWord ).css( "color", KeyAlertColor );
        return false;
      }
    } );
  } );

  $( ".SetHomePage" ).click( function(){
    var url = window.location.host;
    var pr = document.location.protocol;
    url = pr + '//' + url;
    if ($.browser.msie){
      document.body.style.behavior = 'url(#default#homepage)';
      document.body.setHomePage( url );
    }
    else
      if (browser.mozilla){
        if (window.netscape){
          try{
            netscape.security.PrivilegeManager.enablePrivilege( "UniversalXPConnect" );
          }catch (e){
            alert( "此项操作已被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'" );
          }
        }

        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService( Components.interfaces.nsIPrefBranch );
        prefs.setCharPref( title, url );
      }
  } ).css( "cursor", "pointer" );
  $( "#SignInForm" ).submit( function(){
    jCore.start( 'passport.signin', $( 'input[name]', $( this ) ), function( response ){
      if (response.success){
        $( "#UserPanel" ).html( response.userPanel );
      }
      else{
        $( "input[@name=Password]", $( this ) ).val( "" );
        alert( response.message );
      }
    } );
  } );
  $( ".SuffrageContainer" ).click( function( evt ){
    var container = this;
    var self = evt.target;
    construct = function( result ){

    }
    switch (true) {
      case $( self ).is( '.submit' ):
        if ( !$( '.SuffrageForm input.Suffrage[checked]', $( container ) ).length){
          alert( '未选择任何表单项' );
          break;
        }
        $( self ).remove();
        $( 'input.view', $( container ) ).remove();
        $( ".SuffrageForm", $( container ) ).hide();
         jCore.start( 'api.suffrage.append', $( '.SuffrageForm input', $( container ) ).serialize(), function( response ){
          $( ".SuffrageResult", $( container ) ).show().html( response.suffrage );

        } );
        break;
      case $( self ).is( '.view' ):
        $( ".SuffrageForm,.SuffrageResult", $( container ) ).toggle();
        $( self ).val( $( ".SuffrageResult", $( container ) ).is( ':visible' ) ? '返回' : '查看' );
        break;
    }
  } );
/*   window.setTimeout(function(){
	if(window.location.pathname !== '/index.html') return;
	$("#topic").css("background", "black url(/shared/images/topic.gif) no-repeat center center").height(521).slideDown("slow");
	  window.setTimeout(function(){
			$("#topic").slideUp("slow");
	  },8000);
  },1000); */
} );
