window.catalogVisibleCount = 5;
window.galleryFullImageId = 'iwrap';
window.animated = 0;

$(document).ready(function(){
	if ( ($.browser.msie) && ( parseInt($.browser.version) < 7 ) )	{
		DD_belatedPNG.fix('#content, #primary, #logotype, #footer .inside, .logo_title, .phone img');
		$('#primary .inside > ul > li').hover(
			function(){
				$(this).addClass('hovered');
			},
			function(){
				$(this).removeClass('hovered');
			}
		);
	}
	
	if ($('#gallery').length)	{
		pos = $('.carousel li').has('a.active').eq(0).attr('pos');
		$('#' + window.galleryFullImageId + ' div.elem[pos="' +pos+ '"]').show();
		$('.carousel')
			.jCarouselLite({
				btnNext:	"#gallery .next",
				btnPrev:	"#gallery .prev",
				visible:	window.catalogVisibleCount
			})
			.clicker();
		
		$('#gallery .button').click(function(){
			currActive = $('#gallery li').has('a.active').eq(0);
			$(this).hasClass('next') ? currActive.next().find('> a').click() : currActive.prev().find('> a').click()                        
		}).dblclick(function(){
                    return false;
                });

                $('#gallery .next, #gallery .prev').hover(function(){
                    $(this).addClass('hover');                    
                },function(){
                    $(this).removeClass('hover');                    
                });
	}
	
	if ( ($.browser.msie) && ( parseInt($.browser.version) < 7 ) && ($('#bg').length) )	{
		$('#wrapper').resize(resizer);
		resizer();
	}
})


jQuery.fn.clicker = function(){
	obj = this;
	
	$('li a', obj).click(function(e){
		e.preventDefault();
		iChanger(obj, $(this));
		/*pos = $(this).parents('li').eq(0).attr('pos');
		
		if (!$(this).hasClass('active') )	{
			$('li a', obj).removeClass('active');
			$('li[pos="' +pos+ '"] a', obj).addClass('active');
		}
				
		iHolder = $('#' + window.galleryFullImageId);
		$('div.elem:visible', iHolder).hide();
		$('div.elem[pos="' +pos+ '"]').show();
		*/
	});
}

function iChanger(obj, elem)	{
	pos = elem.parents('li').eq(0).attr('pos');
	if (!elem.hasClass('active') )	{
		$('li a', obj).removeClass('active');
		$('li[pos="' +pos+ '"] a', obj).addClass('active');
	}
			
	iHolder = $('#' + window.galleryFullImageId);
	$('div.elem:visible', iHolder).hide();
	$('div.elem[pos="' +pos+ '"]').show();
}

function resizer(){
	setTimeout(function(){
		$('#bg, #bg img').height( $('#wrapper').height());
	}, 200);
}

function doSmth(){
	alert('you\'ve done smth');
}
