/* MENU */

(function($)
{
	$.fn.menuMagnify = function(o) {

		o = $.extend({
			effect1: {'font-size': '240%'},
			effect2: {'font-size': '150%'},
			effect3: {'font-size': '120%'},
			resetEffect: {'font-size': '120%'}
		}, o);

		$(this).mouseleave(function() {
			$(this).stop(true, true);

			$(this).children().each(function(index, element) {
				$(element).animate(o.resetEffect, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
			})
		});

		$(this).children().each(function(index, element) {
			$(element).hover(function() {
				$(this).stop(true, true);

				$(this).animate(o.effect1, {duration: 100, easing: jQuery.easing.easeInOutSine(), queue: false});

				$(this).nextAll().each(function(index, element) {
					if (index == 0) {
						$(element).animate(o.effect2, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
					} else if (index == 1) {
						$(element).animate(o.effect3, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
					} else {
						$(element).animate(o.resetEffect, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
					}
				});

				$(this).prevAll().each(function(index, element) {
					if (index == 0) {
						$(element).animate(o.effect2, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
					} else if (index == 1) {
						$(element).animate(o.effect3, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
					} else {
						$(element).animate(o.resetEffect, {duration: 200, easing: jQuery.easing.easeInOutSine(), queue: false});
					}
				});
			});
		});
	};
})(jQuery);

/* MIMIMIZE */

(function($)
{
	$.fn.minimize = function(params) {
		var target = params.target;

		$(this).click(function() {
			if ($(target).is(":hidden")) {
				$(this).find('img').attr('src', '/images/frontend/icon-minimize.png');
				$(target).slideDown(300,  jQuery.easing.easeInOutSine());
			} else {
				$(this).find('img').attr('src', '/images/frontend/icon-maximize.png');
				$(target).slideUp(300, jQuery.easing.easeInOutSine());
			}

			return false;
		});
	}
})(jQuery);

/* DRAGGABLE */

(function($)
{
	$.fn.draggable = function(params) {
		$(this).drag('start', function(ev, dd) {
				dd.limit = {top: 0, left: 0};
				dd.limit.bottom = $(this).parent().innerHeight() - $(this).outerHeight();
				dd.limit.right = $(this).parent().innerWidth() - $(this).outerWidth();
		}, {
			relative: true,
			handle: params.handle
		})
		.drag(function(ev, dd) {
			$(this).css({
				top: Math.min(dd.limit.bottom, Math.max(dd.limit.top, dd.offsetY )),
				left: Math.min(dd.limit.right, Math.max(dd.limit.left, dd.offsetX))
			});
		},
		{
			relative: true,
			handle: params.handle
		});

		$(this).css({top: $(this).position().top});
		$(this).css({bottom: 'auto'});

		return false;
	}
})(jQuery);

/* TABS */

(function($)
{
	$.fn.tabs = function(callback) {
		$(this).find('li a').click(function() {
			callback($(this));

			return false;
		});
	};
})(jQuery);

(function($)
{
	$.fn.tab = function(callback) {
		$(this).parent().parent().find('li a').removeClass('selected');
		$(this).addClass('selected');

		return false;
	}
})(jQuery);

/* LOAD */

$(document).ready(function() {
	$('#left-menu').menuMagnify();

	$('#accessibility a.resizer').textresizer({
		target: '#page-wrapper',
		type: 'css',
		sizes: [
			{'font-size': '100%'},
			{'font-size': '120%'},
			{'font-size': '130%'}
		],
		selectedIndex: 0
	});

	$('#share-box .minimize-link').click(function() {
		var minLeftPos = -630;
		var maxLeftPos = 0;

		$(this).stop(true, true);

		if ($('#share-box-wrapper').position().left == minLeftPos) {
			$(this).find('img').attr('src', '/images/frontend/icon-minimize.png');
			$('#share-box-wrapper').animate({'left': maxLeftPos + 'px'}, {duration: 500, easing: jQuery.easing.easeInOutSine(), queue: false});
		} else {
			$(this).find('img').attr('src', '/images/frontend/icon-maximize.png');
			$('#share-box-wrapper').animate({'left': minLeftPos + 'px'}, {duration: 500, easing: jQuery.easing.easeInOutSine(), queue: false});
		}
	});

	$('#youtube-link').colorbox({
		href: '#youtube-popup',
		inline: true,
		innerWidth: '720px',
		innerHeight: '446px',
		escKey: true,
		onLoad: function() { $('#youtube-popup').show(); },
		onCleanup: function() {  $('#youtube-popup').hide(); }
	});

	$('#facebook-link').colorbox({
		href: '#facebook-popup',
		inline: true,
		innerWidth: '720px',
		innerHeight: '446px',
		escKey: true,
		onLoad: function() { $('#facebook-popup').show(); },
		onCleanup: function() { $('#facebook-popup').hide(); }
	});

	$('#twitter-link').colorbox({
		href: '#twitter-popup',
		inline: true,
		innerWidth: '720px',
		innerHeight: '446px',
		escKey: true,
		onLoad: function() { $('#twitter-popup').show(); },
		onCleanup: function() { $('#twitter-popup').hide(); }
	});
	
});

