$(function()
{
	function b(txt)
	{
		if(!$('#bag').size())
		{
			$('body').append('<div id="bag" style="background:#000; color:#fff; font-size:12px; padding:20px; position:absolute; left:0; top:0; opacity:0.7; z-index:2000"></div>');
		}
		$('#bag').text(txt);
	}
	
	$('input:radio').checkbox({cls:'radio', empty:'images/empty.png'});
	
	$('.menu_tile a').collapsor();
	
	$('.menu_san').hover(function()
	{
		if(!$(this).find('.menu_btn').hasClass('menu_btn menu_btn_opened'))
		{		
			$(this).find('.menu_btn').addClass('menu_btn_hover');
		}
	}
	,function()
	{
		$(this).find('.menu_btn').removeClass('menu_btn_hover');
	});
	
	
	$(".carusel_inside").jCarouselLite(
	{
		btnNext: ".carusel .btn_next",
		btnPrev: ".carusel .btn_prev",
		visible: 3,
		mouseWheel: true
	});
	var sbtnGo = [];
	for (i=0; i<$('.img_big li').size(); i++)
	{
		sbtnGo[i] = '.carusel_inside .item'+(i+1);
	}
	$(".img_big").jCarouselLite(
	{
		btnNext: ".img_big .btn_next",
		btnPrev: ".img_big .btn_prev",
		start: 0,
		visible: 1,
		mouseWheel: true,
		btnGo: sbtnGo
	});
	
	$(".lightbox_content_block .photo .img_inside").jCarouselLite(
	{
		btnNext: ".lightbox_content_block .photo .btn_next",
		btnPrev: ".lightbox_content_block .photo .btn_prev",
		visible: 1,
		mouseWheel: true
	});

	function lightbox_bg()
	{
		$('.lightbox').height($('.page_wrap').height());
		$('.lightbox').width($('.main_content_wrap').width());
	}

	function catalog(catalog)
	{
		$('.'+catalog).each(function()
		{
			$(this).find('.'+catalog+'_bg').width('auto');
			$(this).find('.'+catalog+'_inside').width('auto');
			$(this).find('.'+catalog+'_item').css('margin-right','0');
			var all_width = $(this).width();
			var item_width = $(this).find('.'+catalog+'_item').width();
			var col_items = $(this).find('.'+catalog+'_item').size();
			var col_items_in_row = parseInt(all_width/(item_width+10));
			if (col_items < col_items_in_row)
			{
				if((col_items_in_row-col_items)<2)
				{
					col_items_in_row = col_items;
				}
			}
			var pad = (all_width-col_items_in_row*item_width)/(col_items_in_row-1);
			if(pad < 10) pad = (all_width-(col_items_in_row-1)*item_width)/(col_items_in_row-2);
			var item_width_pad = item_width+pad;
			$(this).find('.'+catalog+'_item').css('margin-right',pad);
			$(this).find('.'+catalog+'_bg').width(all_width);
			$(this).find('.'+catalog+'_inside').width(item_width_pad*col_items_in_row+item_width-10);
		});
	}
	catalog('catalog1');
	catalog('catalog2');
	catalog('collection_catalog');
	catalog('albums_table');
	//lightbox_bg();
	
	$(window).resize(function()
	{
		catalog('catalog1');
		catalog('catalog2');
		catalog('collection_catalog');
		catalog('albums_table');
		//lightbox_bg();
	});
	
	$('.catalog_man td:last').addClass('last');
	


})
