$(function(){
	ieHover("#menu li", "hover");
	initImg();
});


/* hover for IE6 */
function ieHover(h_list, h_class){
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		if(!h_class) var h_class = 'hover';
		jQuery(h_list).mouseenter(function(){
			jQuery(this).addClass(h_class);
		}).mouseleave(function(){
			jQuery(this).removeClass(h_class);
		});
	};
};

function initImg(){
	var _holder = $('.gallery-block ul > li');
	var _imgBlock = $('.increased-image > .image-area');
	_holder.each(function(){
		var _this = $(this);
		var _src = _this.find('.g-img > a').attr('href');
		var _img = _imgBlock.find('img');
		_this.click(function(e) {
			e.preventDefault();
			if(!_this.hasClass('active')) {
				_imgBlock.addClass('loading');
				var _newImg = new Image();
				_imgBlock.empty();
				$(_newImg).load(function() {
					_imgBlock.removeClass('loading');
					var imgh = _newImg.height;
					var imgw = _newImg.width;
					var divh = _imgBlock.height();
					var divw = _imgBlock.width();
					if (imgh / imgw > divh / divw) {
						_newImg.style.height = divh+'px';
						_newImg.style.width = (imgw * divh / imgh) + 'px';
					} else {
						_newImg.style.width = divw+'px';
						_newImg.style.height = (imgh * divw / imgw) + 'px';
					}
				});
				_imgBlock.append(_newImg).css('backgroundColor', '#fff');
				_newImg.src = _src;
			}
			return false;
		})
	});
}
