/**
 * Executed when document is finished loading elements into DOM
 */
$(document).ready(function()
{
	$('.item').each(function(){
		$(this).parent('a').hover(function(){
			$(this).children('.item').stop();
			$(this).find('.corner-b-l, .corner-b-r').stop();
			$(this).siblings().each(function(){
				$(this).find('.item, .corner-b-l, .corner-b-r').stop();
			});
			
			$(this).find('.corner-b-l, .corner-b-r').animate({
				top: 146
			}, 300);
			
			$(this).children('.item').animate({
				width: 475,
				height: 167
			}, 300);

			$(this).siblings().each(function(){
				var width = $(this).children('.item').width()
				$(this).children('.item').animate({
					width: 220,
					height: 134
				}, 300);

				$(this).find('.corner-b-l, .corner-b-r').animate({
					top: 113
				}, 310);
			});
			
			$(this).find('.text').show();
		},
		function(){
			$(this).find('.item, .corner-b-l, .corner-b-r').stop();
		
			$(this).children('.item').animate({
				width: 305,
				height: 134
			}, 300, function(){
				$(this).find('.text').hide();
			});
			
			$(this).find('.corner-b-l, .corner-b-r').animate({
				top: 113
			}, 310);
			
			$(this).siblings().each(function(){
				$(this).find('.item, .corner-b-l, .corner-b-r').stop();
			});
			
			$(this).siblings().each(function(){
				var width = $(this).children('.item').width()
				
				$(this).children('.item').animate({
					width: 305,
					height: 134
				}, 300, function(){
					$(this).find('.text').hide();
				});
				
				$(this).find('.corner-b-l, .corner-b-r').animate({
					top: 113
				});
			});
		});
	});

	$('#schema .box p').each(function(){
		$(this).css('padding-top', parseInt((86 - $(this).height()) / 2));
	});

	$('#schema .box').mouseover(function(){
		if ($(this).children('.tooltip').length > 0 && $(this).children('.tooltip').html() != ''){
			$('#schema-tooltip').css({ top: $(this).position().top + 162, left: $(this).position().left - 60 + $(this).parent().position().left }).show();
			$('#schema-tooltip span').html($(this).children('.tooltip').html()).css('padding-top', parseInt((115 - $('#schema-tooltip span').height()) / 2 - 15));
		}
	});

	$('#schema .box').mouseleave(function(){
		$('#schema-tooltip').hide();
	});
});

function showSubpage(container, active)
{
	$("#"+container+" .subpage").hide();
	$("#subpage-"+container+"-"+active).show();

	$("#"+container+" .paginator a").removeClass("active");
	$("#"+container+" .paginator"+active).addClass("active");
}

/**
 * Print email link (protection from spambots)
 * If javascript is disabled, nothing is visible
 *
 * @param string p1 Part 1 - this is username
 * @param string p2 Part 2 - this is domain and TLD
 */
function writemail(p1, p2)
{
	document.write("<a href='mailto:"+p1+"@"+p2+"'>"+p1+"@"+p2+"</a>");
}

function _writemail(p1, p2, span_id)
{
	name = p1+'@'+p2;

	$('#'+span_id).html('<a href="mailto:'+p1+'@'+p2+'">'+name+'</a>');
}

(function($){
	$.doAfter = function(time,f) {
		$('body').animate({opacity: 1}, time, f);
	};
})(jQuery);

function propositionPage(page){
	$('#proposition-method .page').hide();
	$('#proposition-method #pm-'+page).show();
}
