$.fn.TopMenu = function(){
	return this.find("li:has(ul)").each(function(i,n){
		var _this	= $(this);
		_this.hover(function(){
			_this.addClass("hover");
			//_this.find('>ul').show();
			_this.find('>ul').slideDown()
		},function(){
			_this.removeClass("hover");
			//_this.find('>ul').hide();
			_this.find('>ul').slideUp()
		});
	});
}
$(function(){	
	$('.TopMenu ul').TopMenu();
	$('.slide').Slide({auto:2000,width:940,height:254});
	$('.certificate .item .img a').lightBox();
	$('.index .item3 .content').scrollable({size:4}).circular().mousewheel().autoscroll({
		steps    : 2,
		interval : 3000
	});
	$('.imglist .items').scrollable({
		vertical : true,
		size     : 3
	}).mousewheel();
	$('.products .img img').each(function(){
		var obj = $(this);
		var img		= new Image();
		img.onload = function(){
			var _tmp = {
				w	: this.width,
				h	: this.height
			}
			_tmp.p	= _tmp.h/_tmp.w;
			var _size = {
				width	: 200,
				height	: 150
			}
			if(_tmp.w>_size.width){
				_tmp.w = _size.width; _tmp.h = _size.width * _tmp.p;
			}
			if(_tmp.h>_size.height){
				_tmp.w = _size.height/_tmp.p; _tmp.h = _size.height;
			}
			obj.css({width:_tmp.w,height:_tmp.h});
		}
		img.src = obj.attr('src');
		if(obj.parent().find('img.align').size()<1){
			obj.parent().append($('<img class="align" />').css({
				width	: '0px',
				height	: '100%',
				border	: 'none'
			}));
		}
	});
	$(".imglist ul li a").click(function() { 
		var __img	= $('<img />');
		var img		= new Image();
		img.onload	= function(){
			var _tmp = {
				w	: this.width,
				h	: this.height
			}
			_tmp.p	= _tmp.h/_tmp.w;
			var _size = {
				width	: 500,
				height	: 375
			}
			if(_tmp.w>_size.width){
				_tmp.w = _size.width; _tmp.h = _size.width * _tmp.p;
			}
			if(_tmp.h>_size.height){
				_tmp.w = _size.height/_tmp.p; _tmp.h = _size.height;
			}
			__img.css({width:_tmp.w,height:_tmp.h});
			__img.attr('src',this.src);
			$('.product .images .img').empty().append('<img class="align" />').append(__img);
		}
		img.src = $(this).attr('href');
		return false;
	}).filter(":first").click();
	$('.imglist ul li a img').each(function(){
		var obj = $(this);
		var img		= new Image();
		img.onload = function(){
			var _tmp = {
				w	: this.width,
				h	: this.height
			}
			_tmp.p	= _tmp.h/_tmp.w;
			var _size = {
				width	: 120,
				height	: 90
			}
			if(_tmp.w>_size.width){
				_tmp.w = _size.width; _tmp.h = _size.width * _tmp.p;
			}
			if(_tmp.h>_size.height){
				_tmp.w = _size.height/_tmp.p; _tmp.h = _size.height;
			}
			obj.css({width:_tmp.w,height:_tmp.h});
		}
		img.src = obj.attr('src');
		if(obj.parent().find('img.align').size()<1)
			obj.parent().append('<img class="align" />');
	});
//	$('.imglist ul li a').click(function(){
//		var img	= $('<img />');
//		img.width(500);
//		img.height(375);
//		img.attr('src',$(this).attr('href'));
//		$('.product .images .img').html(img);
//		return false;
//	}).filter(':first').click();
});

