
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	}
});


if (window.jQuery) $(document).ready(function() {
	if ($('.album').length) gallery();
	if ($('#clinics_toggle').length) clinics_toggle();
	if ($('.feedback').length) mess_toggle();
	if ($('.collaps').length) collaps_toggle();
	$('div.carousel').each(block_carousel);
});

function collaps_toggle()
{
	$('a#video-collaps').bind('click', function(){
		$('.collaps').slideToggle();
		return false;
	});
}

function mess_toggle()
{
	$('.feedback .item .teaser').hide();
	$('.feedback .item .title a').bind('click', function() { $('#feed_' + this.rel).slideToggle(); });
}

function gallery()
{
	$('.preview td').each(function(i) {
		var a;
		a = $('a.mini_img', this);
		a[0].img_id = $('a.mini_img', this).attr('href');
		a[0].img_n = i+1;
		a.bind('click', img_change);
	});
	return true;
}

function img_change()
{
	var n, com, par, img, p, link;
	img = this.img_id;
	n = this.img_n;
	com = $('p.comment', $(this).parent()).html();
	$('.big').fadeTo('slow', 0.5);
	tmp = new Image();
	$(tmp).bind('load', function() {
		$('.big').queue(function () {
		$('.big img').attr('src', img);
		$('#img_comment').html(com);
		$('.big').fadeTo('slow', 1);
		$('.big').dequeue();
		});
	}).attr('src', img);
	$('#img_count em').html(n);
	p = $('.preview td').get(n);
	if (p) link= $('a', p).attr('href');
	return false;
}



function clinics_toggle()
{
	$('a#tog_clin').bind('click', function() {
		if ($('#clinics_toggle ul:not(:visible)').length)
		{
			$('#clinics_toggle ul').slideToggle('fast');
			$('body').bind('mousedown', clinics_toggle_hide);
		}
		return false;
	});
}

function clinics_toggle_hide(e)
{
	if ($(e.target).filter('#clinics_toggle ul *, #clinics_toggle ul').length <= 0)
	{
		$('body').unbind('mousedown', clinics_toggle_hide);
		$('#clinics_toggle ul:visible').slideUp('fast');
	}
	return false;
}



function block_carousel()
{
	var carousel, carousel_ul, timer, n, n_max, w, m, z;

	carousel = $(this);
	carousel_ul = $('.mid ul', this);
	timer = undefined;

	w = $('li', carousel_ul)[0].clientWidth;
	if (!w) return;

	n = 1;
	m = 1;
	n_max = $('li', carousel_ul).size() - Math.floor($('div.mid', this)[0].clientWidth / w);
	if (n_max < 0) n_max = 0;
	z = Math.round(n_max / m) + 1;

	$('a.prev', this).bind('click', function() {
		if (timer) { window.clearInterval(timer); timer = undefined; }
		if (n <= m)
		{
			carousel_ul.animate({left:"-="+(w*n_max)+"px"}, 1300, "easeInOutBack");
			n = n_max + 1;
		} else {
			carousel_ul.animate({left:"+="+(w*m)+"px"}, "slow", "easeInOutCubic");
			n -= m;
		}
		$('span.count', carousel).html(Math.round((n+m-1)/m)+' θη '+z);
		return false;
	});

	$('a.next', this).bind('click', function() {
		if (timer) { window.clearInterval(timer); timer = undefined; }
		if (n > n_max)
		{
			carousel_ul.animate({left:"0px"}, 1300, "easeInOutBack");
			n = 1;
		} else {
			carousel_ul.animate({left:"-="+(w*m)+"px"}, "slow", "easeInOutCubic");
			n += m;
		}
		$('span.count', carousel).html(Math.round((n+m-1)/m)+' θη '+z);
		return false;
	});

	timer = window.setInterval(function() {
		if (n > n_max)
		{
			carousel_ul.animate({left:"0px"}, 1300, "easeInOutBack");
			n = 1;
		} else {
			carousel_ul.animate({left:"-="+(w*m)+"px"}, "slow", "easeInOutCubic");
			n += m;
		}
		$('span.count', carousel).html(Math.round((n+m-1)/m)+' θη '+z);
		return false;
	}, 8000);

	return;
}

