$(function() {
	// ***** SLIDER-TOGGLING ***** 
	$('.slider-toggling-div-hidden').hide();
	$('.slider-toggling-control').click(function(e) {
		var div_id = this.id.replace( 'toggling-control','toggling-div' );
		var controllingObject = $('#' + div_id);
		controllingObject.toggle(500);
		e.preventDefault();
		return false;
	});
	
	// ***** HIGHSLIDE *****
	$('a.highslide').click(function(e) {
		var result = hs.expand(this);
		e.preventDefault();
		return result;
	});
	
	captcha = $('img#captcha');
	jQuery.data(captcha, 'captcha-refresh', {oldUrl:captcha.attr('src') } );
	
	// ***** CAPCHA *****
	$('a#captcha-refresh').click(function(e) {
		var oldUrl = jQuery.data(captcha, 'captcha-refresh').oldUrl;
		captcha.attr('src', oldUrl + '&t=' + Math.random() );
		e.preventDefault();
		return false;
	});
	
	// ****** TOOLTIPS *******
	$('.tooltipped').qtip({
	   content: { text: false },
	   position: {
		  corner: {
			 tooltip: 'bottomRight',
			 target: 'topLeft'
		  }
	   },
	   style: {
		  border: {
			 width: 1,
			 radius: 4
		  },
		  padding: 7, 
		  textAlign: 'left',
		  tip: true
	   }
	});
	
	$('.tooltipped-right').qtip({
	   content: { text: false },
	   position: {
		  corner: {
			 tooltip: 'bottomLeft',
			 target: 'topRight'
		  }
	   },
	   style: {
		  border: {
			 width: 1,
			 radius: 4
		  },
		  padding: 7, 
		  textAlign: 'left',
		  tip: true
	   }
	});
	
	// ***** STARS *****
	$(".stars-wrapper").each( function () {
		var thisQ = $(this);
		var thisQRating = thisQ.attr("rating");
		var thisQDisabled = (typeof thisQ.attr("disabled") != 'undefined') || (thisQ.attr("disabled")=='true');
		thisQ.starRating({
			clickable:true,
			rating:thisQRating,
			hoverable:!thisQDisabled,
			clickable:!thisQDisabled,
			showNumber:true
		});
	});
	
	// ****** SCROLLING EASING ******
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;
		var p=0;
		var a=c;
		if (t==0) return b;
		if ((t/=d)==1) return b+c; 
		if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	}; 
});

// ***** HIGHSLIDE Initialization *****

hs.graphicsDir = '/_scripts/highslide/graphics/';
hs.align = 'center';
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.75;

hs.lang = {
	cssDirection: 'ltr',
	loadingText : 'Загружается...',
	loadingTitle : 'Нажмите для отмены',
	focusTitle : 'Нажмите, чтобы передвинуть на передний план',
	fullExpandTitle : 'Растянуть до оригинального размера (f)',
	creditsText : 'Powered by <i>Highslide JS</i>',
	creditsTitle : ' ',
	previousText : 'Предыдущая',
	nextText : 'Следущая', 
	moveText : 'Передвинуть',
	closeText : 'Закрыть', 
	closeTitle : 'Закрыть (esc)', 
	resizeTitle : 'Изменить размер',
	playText : 'Слайдшоу',
	playTitle : 'Начать слайдшоу (пробел)',
	pauseText : 'Пауза',
	pauseTitle : 'Приостановить слайдшоу (пробел)',
	previousTitle : 'Предыдущая (стрелка влево)',
	nextTitle : 'Следующая (стрелка вправо)',
	moveTitle : 'Передвинуть',
	fullExpandText : '1:1',
	number: 'Картинка %1 из %2',
	restoreTitle : 'Нажмите, чтобы закрыть. Можно перетягивать.'
};