$(document).ready(function(){
	InitGallery();
});


function InitGallery(){
	var _speed = 1000,
		_duration = 10000;
	var _hold = $('.gallery');
	var _holder = _hold;
	var _slide = _holder.find('ul.slider');
	var _list = _slide.find('>li');

	var _d = _list.eq(0).outerWidth(true);
	var _x=0;
	var _wh = _holder.width();
	var _ws = _list.length*_d;
	var _margin = parseInt(_list.eq(0).css('marginRight'));
	
/*--------CREATING THUMBNAILS----------*/
	var _num = _hold.find('.switcher').empty();
	_list.each(function(i){
		$('<li><a href="#"><span>'+(i+1)+'</span></a></li>').appendTo(_num);
	});
/*-------------------------------------*/
	var _thumb = _num.find('li');
	var _a = _list.index(_list.filter('.active:eq(0)'));
	if(_a == -1) {
		_a = 0; 
		_list.eq(_a).addClass('active');
		_thumb.eq(_a).addClass('active');
	}
	var _i = _a, _new, _old = _a, _t, _t1;

	
	Run(_a,_x);
	function Run(_a, _x){	
		_t = setTimeout(function(){
			_a++;
			if (_x < _ws- _wh -_margin){_x = _x + _d;
			}else{_x = 0; _a = 0
			}
			Slide(_a,_x);
		}, _duration);
	};
	function Slide(_new,_x){
		_list.eq(_old).removeClass('active');
		_list.eq(_new).addClass('active');
		_thumb.eq(_old).removeClass('active');
		_thumb.eq(_new).addClass('active');
		_slide.animate({marginLeft: -_x}, {queue:false, duration:_speed});
		_old=_new;_a=_new;
		if(_t) clearTimeout(_t);
		if(_t1) clearTimeout(_t1);
		Run(_new,_x);
	};
	
	_thumb.each(function(j){
		$(this).click(function(){
			if (j<_i) {_x = 0}
			else {_x = (j)*_d; }
			_a = j;
			Slide(_a,_x)
			return false;
		});
	});
};




eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9 t(a,b){g(3=0;3<a.h;3++){k c=[],d=[],n=[],e=[],4=[],l=[];8(a[3].5(\'.\')!=-1||a[3].5(\'#\')==-1){8(a[3].5(\'>\')!=-1){c[3]=a[3].f(a[3].5(\'>\')+2);a[3]=a[3].f(0,a[3].5(\'>\')-1)}8(a[3].5(\'.\')!=-1){d[3]=a[3].f(a[3].5(\'.\')+1);a[3]=a[3].f(0,a[3].5(\'.\'))}n[3]=a[3];8(!d[3])d[3]=\'\';8(c[3]){l[3]=r.o(n[3]);g(k j=0;j<l[3].h;j++){8(l[3][j].6.5(d[3])!=-1){4[3]=l[3][j].o(c[3]);g(k i=0;i<4[3].h;i++){4[3][i].p=9(){7.6+=\' \'+b};4[3][i].q=9(){7.6=7.6.m(b,\'\')}}}}}s{4[3]=r.o(n[3]);g(k i=0;i<4[3].h;i++){8(4[3][i].6.5(d[3])!=-1){4[3][i].p=9(){7.6+=\' \'+b};4[3][i].q=9(){7.6=7.6.m(b,\'\')}}}}}s 8(a[3].5(\'#\')!=-1){8(a[3].5(\'>\')!=-1){c[3]=a[3].f(a[3].5(\'>\')+2);a[3]=a[3].f(0,a[3].5(\'>\')-1)}a[3]=a[3].m(\'#\',\'\');e[3]=r.u(a[3]);8(e[3]){8(c[3]){4[3]=e[3].o(c[3]);g(k i=0;i<4[3].h;i++){4[3][i].p=9(){7.6+=\' \'+b};4[3][i].q=9(){7.6=7.6.m(b,\'\')}}}s{e[3].p=9(){7.6+=\' \'+b};e[3].q=9(){7.6=7.6.m(b,\'\')}}}}}}',31,31,'|||_hoverItem|_hoverElement|indexOf|className|this|if|function||||_class|_id|substr|for|length|||var|_parent|replace|_tag|getElementsByTagName|onmouseover|onmouseout|document|else|hoverForIE6|getElementById'.split('|'),0,{}));
/* insert your class and id ***********************
_hoverClassName = 'hover';
_hoverEl = ['ul.ul-class > li',	'div.div-class', 'span', '#box', '#nav > li'];
/**************************************************/
function ieHover() {
	hoverForIE6(['#nav > li'], 'hover');
}
if (window.attachEvent && !window.opera){
	window.attachEvent("onload", ieHover);
}
