$ = jQuery;
function set_view(id)
{
	$('.underMenu li a').removeClass('active');
	$('#st_'+id).addClass('active');

	$('.cnt_txt').hide();
	$('#'+id).show();
	jQuery('#scroll-2').jScrollPane({showArrows:true, scrollbarWidth:10, dragMaxHeight:43});
	return false;
}

function selcard(sel_id)
{
	$('.underMenu li a').removeClass('active');
	$('#crd_t' + sel_id).addClass('active');
	
	$('.botGallery').hide();
	$('#crd' + sel_id).show();
	
	img_id = '#fimg_' + sel_id + '_img';
	eval($(img_id).attr('clk'))
}

function sel_index_view(own_id, item_id)
{
	$('#n_' + own_id + ' a').show();
	$('#s_n_' + item_id).hide();
	$('#col_' + own_id +' div').hide();
	$('#a_n_' + item_id).show();
	
	return false;
}

function index_prv(own_id)
{
	n ='';//own_id + "_n_1";
	set_val = false;

	$('#n_' + own_id + ' li a').each(function()
	{
		if(!set_val)
		{
			if(this.style.display =='none' && n.length > 0)
				set_val = true;
			else
				if(this.id.length > 0)n = this.id
				
		}
	});
	n=n.replace('s_n_','');
	sel_index_view(own_id, n)

	return false;
}

function index_nxt(own_id)
{
	n =own_id + "_n_1";
	set_val = false;

	$('#n_' + own_id + ' li a').each(function()
	{
		if(this.style.display =='none')
			set_val = true;
		else
			if(set_val && this.id.length > 0)
			{
				n = this.id
				set_val = false;
			}
	});
	n=n.replace('s_n_','');
	sel_index_view(own_id, n)
	return false;
}

pLeft = 0;
function sld_left()
{
	var w = $("#DHTMLgoodies_thumbs").css("width");
	cnt = $("#DHTMLgoodies_thumbs ul").length
	w = w.replace("pt","").replace("px","");
//	w /= 2;
	w = 225;
	pLeft = Number(pLeft)+Number(w)
	if(pLeft > 0) pLeft = -(cnt-1) *w;

	$("#DHTMLgoodies_thumbs_inner").animate({left: pLeft}, w, fix_sld());

	return false;
}

function sld_right()
{
	var w = $("#DHTMLgoodies_thumbs").css("width");
	cnt = $("#DHTMLgoodies_thumbs ul").length
	w = w.replace("pt","").replace("px","");
//	w /= 2;
	w = 222;
	pLeft = Number(pLeft)-Number(w)
	if(pLeft < -(cnt-1) *w) pLeft =0;
	$("#DHTMLgoodies_thumbs_inner").animate({left: pLeft}, w, fix_sld());
	
	return false;
}

function fix_sld()
{
//	alert(3)
	var w = $("#DHTMLgoodies_thumbs").css("width");
	cnt = $("#DHTMLgoodies_thumbs ul").length

	w = w.replace("pt","").replace("px","");
	if(Number(pLeft)+Number(w) >0) $('#tl').hide();else $('#tl').show();
	if(Number(pLeft)-Number(w) < -(cnt-1) *w) $('#tr').hide();else $('#tr').show();
}


function gsld_left()
{
	var w = $("#DHTMLgoodies_thumbs").css("width");
	cnt = $("#DHTMLgoodies_thumbs li").length
	w = w.replace("pt","").replace("px","");
	w = Number(w / cnt);

	pLeft = pLeft + 645;//+w*6
	if(pLeft > 0) pLeft = -645;//(cnt) *w;
	
	$("#DHTMLgoodies_thumbs_inner").animate({left: pLeft}, w);
	fix_global();
	return false;
}

function gsld_right()
{
	var w = $("#DHTMLgoodies_thumbs").css("width");

	cnt = $("#DHTMLgoodies_thumbs li").length
	w = w.replace("pt","").replace("px","");
	w = Number(w / cnt);
	w = 222;
	pLeft = pLeft-645;//(w*6)
	c = -(cnt) *w
	if(pLeft < c) pLeft =0;
	$("#DHTMLgoodies_thumbs_inner").animate({left: pLeft}, w );
	fix_global();
	return false;
}

function fix_global()
{
	var wall = $("#DHTMLgoodies_thumbs").css("width");

	cnt = $("#DHTMLgoodies_thumbs li").length
	wall = wall.replace("pt","").replace("px","");
	w = Number(wall / cnt);
//	alert(pLeft);
	if(pLeft >=0) $('#gl').hide(); else $('#gl').show();
//	alert(pLeft)
	if(-pLeft >= wall-w*6) $('#gr').hide(); else $('#gr').show();
}

function print_page(obj)
{
	window.print();

	return false;
	url = window.location.href
	url += url.indexOf('?')>=0?'&':'?';
	url += 'print=1';
	obj.href = url
}

empty_src = "Поиск";

function init_search()
{
	if($('#search').val()=="")$('#search').val(empty_src);
	
	$('#search').focus(function(){if(this.value == empty_src)this.value ='';})
	$('#search').blur(function() {if(this.value=="")this.value =empty_src;})
}

function ViewBnk(fs, bk)
{
	$('#face').attr('src', fs);
	$('#crnd').attr('src', bk);
	return false;
}
$(document).ready(function() {init_search();});
