/*--- IE6 hover ---*/
function ieHover(h_list, h_class){
	if($.browser.msie && $.browser.version < 8){
		if(!h_class) var h_class = 'hover';
		$(h_list).live('mouseover', function(){
			$(this).addClass(h_class);
		}).live('mouseout', function(){
			$(this).removeClass(h_class);
		});
	}
}
/*--- tabs ---*/
function initTabs(){
	$('ul.tabset').each(function(){
		var btn_h = $(this);
		btn_h.find('li:first').addClass('first');
		var _btn = $(this).find('a.tab');
		var _a = _btn.index(_btn.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		_btn.removeClass('active').eq(_a).addClass('active');
		_btn.each(function(_i){
			this._box = this.href.substr(this.href.indexOf("#") + 1);
			if(this._box){
				
				this._box = $('#'+this._box);
				if(_i == _a) this._box.show();
				else this._box.hide();
			}
			this.onclick = function(){
				changeTab(_i);
				
				return false;
			}
		});
		function changeTab(_ind){
			if(_ind != _a){	
				if(_btn.get(_a)._box) _btn.get(_a)._box.hide();
				if(_btn.get(_ind)._box) _btn.get(_ind)._box.show();
				_btn.eq(_a).removeClass('active');
				_btn.eq(_ind).addClass('active');
				//initScrollpane();
				_a = _ind;
			}
		}
	});
	/*$('.catalog').css({
		'position':'static',
		'top':'0'
	});*/
	$('.box').css({
		'position':'static',
		'top':'0'
	});
	$('img.png').addClass('png2');
}
$(document).ready(function(){
	$(".slideshow").css('width','497px');
	$(".slideshow").css('height','372px');
	ieHover('#main-nav>li', 'hover');
	initTabs();
	$('ul.accordion').accordion({ 
        autoheight: false,
        header: ".opener",
        active: '.selected',
        selectedClass: 'active',
        alwaysOpen: false,
        event: "click"
    });
	
	$('#carusel').gallSlide({
		duration: 700,
		autoSlide: 5000
	});
	
});


jQuery.fn.gallSlide = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: 5000
	},_options);

	/* return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		var _timer = _options.autoSlide;
		var _wrap = _hold.find('div.carusel-list');
		var _el = _hold.find('div.holder').find('div.carusel-item');
		var _next = $('a.link-next');
		var _prev = $('a.link-prev');
		var _count = _el.index(_el.filter(':last'));
		var _w = _el.outerHeight(true);
		var _wrapHolderW = Math.ceil(_wrap.parent().height()/_w);
		
		var _active = 0;
		function scrollEl(){
			_wrap.eq(0).animate({
				marginTop: -(_w * _active) + "px"
			}, {queue:false, duration: _speed});
		}
		_next.click(function(){
			_active++;
			_active++;
			if (_active > (_count - _wrapHolderW + 2)) _active = 0;
			if (_active > (_count - _wrapHolderW + 1)) _active--;
			scrollEl();
			return false;
		});
		_prev.click(function(){
			_active--;
			_active--;
			if (_active < 0) _active++;
			if (_active < 0) _active = _count - _wrapHolderW +1;
			
			scrollEl();
			return false;
		});
	}); */
	
	return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		var _timer = _options.autoSlide;
		var _wrap = _hold.find('div.carusel-list');
		var _el = _hold.find('div.holder').find('div.carusel-item');
		var _next = $('.link-next');
		var _prev = $('.link-prev');
		var _count = _el.index(_el.filter(':last'));
		var _w = _el.outerWidth(true);
		var _wrapHolderW = Math.ceil(_wrap.parent().width()/_w);
		
		var _active = 0;
		function scrollEl(){
			_wrap.eq(0).animate({
				marginLeft: -(_w * _active) + "px"
			}, {queue:false, duration: _speed});
		}
		_next.click(function(){
			_active++;
			if (_active > (_count - _wrapHolderW + 1)) _active=0;
			scrollEl();
			return false;
		});
		_prev.click(function(){
			_active--;
			if (_active < 0) _active = _count - _wrapHolderW +1;
			scrollEl();
			return false;
		});
	});
}
