// JavaScript Document
//信息切换
function TabsSwitcher( tabButtons,tabs,toggleCSS )
{
	for( var j = 0; j < tabButtons.length; j++ )
	{
		if( document.getElementById( tabButtons[j] ) )
		{
			document.getElementById( tabButtons[j] ).onmouseover = function()
			{
				for( var i = 0; i < tabButtons.length; i++ )
					if( tabButtons[i] == this.id )
					{
						document.getElementById( tabs[i] ).style.display = 'block';
						if( toggleCSS && this.className.indexOf( toggleCSS ) == -1 )
							AddClass( this.id, toggleCSS );
					}else{
						document.getElementById( tabs[i] ).style.display = 'none';
						if( toggleCSS && document.getElementById( tabButtons[i] ).className.indexOf( toggleCSS ) != -1 )
							RemoveClass( tabButtons[i], toggleCSS );
					}
				this.blur();
				return false;
			}
			if( j > 0 )
				document.getElementById( tabs[j] ).style.display = 'none';
		}
	}
}
AddClass = function( id, className )
{
	var this_ = document.getElementById( id );
	if( this_.className.indexOf( className ) == -1 )
		this_.className = ( this_.className ? this_.className + ' ' : '' ) + className;
	return this_;
}
RemoveClass = function( id, className )
{
	var this_ = document.getElementById( id );
	if( this_.className.indexOf( className ) != -1 )
		if( this_.className.indexOf( ' ' ) == -1 )
		
			this_.className = '';
			
		else{
			
			var arr = this_.className.split( ' ' );
			
			for( var k = 0; k < arr.length; k++ )
				if( arr[k] == className )
					break;
			arr.splice( k, 1 );		
			this_.className = arr.join( ' ' );
		}
	return this_;
}

function enterHandler(event)
{
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13) {
   //处理函数
   	if( typeof(arguments[1]) == 'function' )
   		arguments[1]();
	else
		return true;
  }
  return false;
} 

//var imgw,imgh,imgid;
//比例缩小图片
function DrawImage(ImgD,w,h){ 
 var image=new Image(); 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= w/h){ 
   if(image.width>w){
    ImgD.width=w; 
    ImgD.height=(image.height*w)/image.width; 
   }/*else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } */
   //ImgD.alt="点击查看详细信息..."; 
  } 
  else{ 
   if(image.height>h){
    ImgD.height=h; 
    ImgD.width=(image.width*h)/image.height; 
   }/*else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } */
   //ImgD.alt="点击查看详细信息..."; 
  } 
 }
}



var ShowGarllery = function(list){
	var photoList;
	photoList = '<div class="demo" id="demo"><div id="main_image"></div><ul class="gallery_demo_unstyled">';
	photoList += list;
	photoList += '</ul><p class="nav"><a href="#" onclick="$.galleria.prev(); return false;">&laquo;上一张</a>'+
				'| <a href="#" onclick="$.galleria.next(); return false;">下一张&raquo;</a></p></div>'
				
		   $.fn.facebox({opacity:.45});
		   $( '#opengallery' ).click(function(){
			   $.facebox( photoList );
			   $('.gallery_demo_unstyled').addClass('gallery_demo'); 
			   $('ul.gallery_demo').galleria({history:false, clickNext:true, insert:'#main_image', 
					onImage:function(image,caption,thumb) {
						image.css('display','none').fadeIn(1000).attr('id', 'gallery_image_big');
						caption.css('display','none').fadeIn(1000);
						var _li = thumb.parents('li');
						_li.siblings().children('img.selected').fadeTo(500,0.3);
						thumb.fadeTo('fast',1).addClass('selected');
						image.attr('title','下一张>>');
						var imgid = document.getElementById(image.attr('id'));
						DrawImage(imgid, 780, 530);
				},
				onThumb:function(thumb) {
					var _li = thumb.parents('li');
					var _fadeTo = _li.is('.active') ? '1' : '0.3';
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
					thumb.hover(function() { thumb.fadeTo('fast',1); }, function() { _li.not('.active').children('img').fadeTo('fast',0.3); });
				}
			});
		   /*$(".galleria_container .galleria_wrapper").draggable({ containment: 'body', scroll: false });*/
			return false;			   
	 		});
}