/*fadeGallery*/
jQuery.fn.fadeGallery = function(_options){
	var _options = jQuery.extend({
		listSelector: '> li',
		navHolder:		false,
		navCreate:		false,
		thumbsSelector: 'li',
		prev:			'a.prev',
		next:			'a.next',
		swichTime:		false,
		delay:			900,
		fadeIEfix:		false,
		onChange:		null
	},_options);
	return this.each(function(){
		var _swichTime = _options.swichTime;
		var _d = (_options.fadeIEfix) ? ($.browser.msie ? 0 : _options.delay) : (_options.delay);
		var _this = $(this);
		var _list = $(_options.listSelector, _this);
		var _linksHold = $(_options.navHolder, _this);

		if(_options.navCreate){
			var _htmlNav ='<ul>';
			for(var i=0; i<_list.length; i++) {
				_htmlNav += '<li><a href="#">'+(i+1)+'</a></li>';
			}
			_htmlNav +='</ul>';
			_linksHold.html(_htmlNav);
		}
		if(_options.navHolder) var _links = jQuery(_options.thumbsSelector, _linksHold);
		else var _links = jQuery(_options.thumbsSelector, _this);
		var _btnPrev = $(_options.prev , _this);
		var _btnNext = $(_options.next , _this);
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		var _t;
		_list.removeClass('active').css({display: 'none', opacity: 0}).eq(_a).addClass('active').css({display: 'block', opacity: 1}).css('opacity', 'auto');
		_links.eq(_a).addClass('active');

		autoSwitch();
		function autoSwitch(){
			if (_swichTime){
				_t = setTimeout(function(){
					if(_a < _list.length - 1) changeEl(_a + 1);
					else changeEl(0);
				}, _swichTime);
			}
		}

		if (_btnPrev){
			_btnPrev.click(function(){
				var _prevItem = 0;
				if (_a > 0) _prevItem = _a-1;
				else _prevItem = _list.length-1;
				changeEl(_prevItem);
				return false;
			})
		}
		if (_btnNext){
			_btnNext.click(function(){
				var _nextItem = 0;
				if (_a < _list.length - 1) _nextItem = _a+1;
				else _nextItem = 0;
				changeEl(_nextItem);
				return false;
			})
		}

		if(_links){
			_links.click(function(){
				var _ind = _links.removeClass('active').index($(this).addClass('active'));
				changeEl(_ind);
				return false;
			})
		}
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			if(_list.is(':animated')) _list.stop(true, true);
			if(_ind != _a){
				_links.removeClass('active').eq(_ind).addClass('active');
				_list.eq(_a).removeClass('active').animate({opacity: 0}, {queue:false, duration:_d, complete: function(){$(this).css({display:'none'})}});
				_list.eq(_ind).addClass('active').css({opacity: 0, display:'block'}).animate({opacity: 1}, {queue:false, duration:_d,complete:function(){
					$(this).css('opacity', 'auto');
					_a = _ind;
					autoSwitch();
					if (jQuery.isFunction(_options.onChange)) {
						_options.onChange.apply(_this);
					};
				}});
			}
		}
	});
};

function initHeight() {
    var windowHeight = $(window).height();
    var containerHeight = $('div#container').outerHeight(true);
    var footHeight = $('div#footer').outerHeight(true);

    if ((containerHeight + footHeight) < windowHeight) {
        $('div#container').height(windowHeight - footHeight);
    }

//	var _hardcode = 119;
//	var _hold = $('div#container');
//	var _foot = $('div#footer');
//	var _holdH = _hold.height();
//	var _footH = _foot.height();
//	if (window.innerHeight) {
//			_height = window.innerHeight;
//			_width = window.innerWidth;
//		}
//	else {
//		_height = document.documentElement.clientHeight;
//		_width = document.documentElement.clientWidth;
//	}
//	if(_holdH + _footH < _height){
//			_hold.css('height', (_height - _footH));
//		}
//	else {
//			_hold.css('height', (_holdH));
//		}
//	
//	
//	$(window).resize(function(){
//		if (window.innerHeight) {
//			_height = window.innerHeight;
//			_width = window.innerWidth;
//			}
//		else {
//			_height = document.documentElement.clientHeight;
//			_width = document.documentElement.clientWidth;
//		}
//		if(_holdH + _footH < _height){
//			_hold.css('height', (_height - _footH));
//		}
//		else {
//				_hold.css('height', (_holdH));
//			}
//	});
};

$(document).ready(function(){
	initHeight();
	jQuery('.fade-gal').fadeGallery({
		listSelector: '> img',
		swichTime:		5000,
		delay:			900
	});
});

$.fn.equalHeights = function() {
    var currentTallest = 0;
    $(this).each(function() {
        if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
        // for ie6, set height since min-height isn't supported
    });
    if ($.browser.msie && $.browser.version == 6.0) { $(this).css({ 'height': currentTallest }); }
    $(this).css({ 'min-height': currentTallest });
    return this;
};
