$(document).ready(function(){
//	InitLightBox();
	InitGalary();
	InitAccordion();
});
function InitAccordion (){
	$('ul.addnav').accordion({
		active: '.active',
		header: 'a.header',
		collapsible: true
	});
};
function InitGalary(){
	var _speed = 500;
	//var _duration = 3000;
	var _hold = $('div.gallery div');
	var _slide = _hold.find('ul');
	var _list=_slide.find('>li');
	var _prev = $('a.link-prev');
	var _next = $('a.link-next');
	var _d = _list.eq(0).outerWidth(true);
	var _x=0;
	var _wh = _hold.width();
	var _ws = _list.length*_d;

	_next.click(function(){
		if (_x < _ws- _wh-_d){
			_x = _x + _d;
		}
		else{
			_x = 0;
		}
		RunAnimation(_x);
		return false;
	});
	_prev.click(function(){
		if (_x > _d){
			_x = _x - _d;
		}else{
			_x=_ws-_wh;
		}
		RunAnimation(_x);
		return false;
	});
	/*var _t;
	function runTimer(){
		if(_t) clearInterval(_t);
		_t = setInterval(function(){
			if (_x < _ws- _wh){
				_x = _x + _d;
			}
			else{
				_x = 0;
			}
			RunAnimation(_x);
		}, _duration);
	}
	runTimer();*/
	function RunAnimation(_x){
		_slide.animate({marginLeft: -_x}, {queue:false, duration:_speed, complete:function(){
			//runTimer();
		}});
	};
};
$(window).resize(function(){
	LightPlace();
});
$(window).scroll(function(){
	LightPlace();
});
//function InitLightBox(){
//	var _duration = 400;
//	var _light = $('.light-box').hide();
//	var _lay = $('<div class="overlay"></div>').css({opacity:0}).appendTo($('body')).hide();
//	var _close=$('a.close');
//	var _view = $('div.gallery li');
//	_view.each(function(){
//		var _hold = $(this);
//		_hold.click(function(){
//
//			if ($.browser.msie){
//				_light.show();
//				_lay.show().css({opacity:0.8}, {queue:false, duration:_duration});
//				LightPlace();
//
//				_lay.click(function(){
//					_light.hide();
//					_lay.hide();
//					return false;
//
//				});
//				_close.click(function(){
//					_light.hide();
//					_lay.hide();
//					return false;
//				});
//			}
//			else{
//				_light.css({opacity:0}).show().animate({opacity:1}, {queue:false, duration:_duration});
//				_lay.show().animate({opacity:0.8}, {queue:false, duration:_duration});
//				LightPlace();
//
//				_lay.click(function(){
//					_light.hide();
//					_lay.animate({opacity:0}, {queue:false, duration:_duration, complete:function(){$(this).hide();}});
//					return false;
//
//				});
//				_close.click(function(){
//					_light.animate({opacity:0}, {queue:false, duration:_duration, complete:function(){$(this).hide();}});
//					_lay.animate({opacity:0}, {queue:false, duration:_duration, complete:function(){$(this).hide();}});
//					return false;
//				});
//			}
//			return false;
//		});
//	});
//};

function LightPlace(_h){
	var _light = $('div.light-box');
	var _w = _light.width();
	var _lay = $('div.overlay');
	var _h = _light.height();
	if (window.innerHeight){var _wx = window.innerWidth; var _wy = window.innerHeight;}
	else{_wx = document.documentElement.clientWidth; _wy = document.documentElement.clientHeight;};

	_lay.css({height:$('body').height()});

	_light.css({left:(_wx-_w)/2, top:(_wy-_h)/2+$(document).scrollTop()});

};
