$(document).ready(function () 
{
	// --- Navigation : Remove the first vertical border.
	$('.nav>li:first>a').css({ 'border' : '0' });
	
	// --- Sub-Navigation : Remove the first vertical border.
	$('.sub-nav>li:first>a').css({ 'border' : '0' });
	
	// --- Share on facebook
	$('a._shareFacebook').click(function () {
		u=location.href;
		t=document.title;
		window.open('http://facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
	});		
	
	// --- Print the current page: 
	$('._print').click(function () { window.print(); });
	
	// --- New window
	$('._nw').click(function () {
		window.open($(this).attr('href'));
		return false;
	});
	
	// --- Flip arrow
	$('.cont-lnk-parallel').mouseover(	
		function () {
			flip_arrow(0);
		}
	);
	
	// --- Video nav position
	var t =	$('.video-holder>ul>li').size();
	var b = $('.video-holder>ul>li.on').prevAll('li').size();	
	
	var pos = parseInt($('.video-holder>ul').css('margin-top')) - (b-1) * 68;
	
	while (pos < ($('.video-holder>ul>li').size() * -68) + 4 * 68) {
		pos += 68;
	}
	
	if (pos > 0) {
		pos = 0;
	}

	$('.video-holder>ul').animate({ 'margin-top' :  pos + 'px' }, 0);
		
	$('.video-down').click(function () {
		var pos = parseInt($('.video-holder>ul').css('margin-top')) + 68;
		
		if (pos < 1)
		{
			$('.video-holder>ul').animate({ 'margin-top' :  pos + 'px' }, 100);
		}
		return false;
	});
	
	$('.video-up').click(function () {
		var pos = parseInt($('.video-holder>ul').css('margin-top')) - 68;
		if (pos > (t * -68) + 3 * 68)
		{
			$('.video-holder>ul').animate({ 'margin-top' :  pos + 'px' }, 100);
		}
		return false;
	});
	
	// --- lnk img on block's links
	$('.block-holder .block a').each(function () {
		if ($(this).attr('name') == '')
		{		
			$(this)
				.css({
					'display'	: 'inline-block',
					'width'		: $(this).width() + 15
				})
				.prepend('<span class="ui-icon ui-icon-extlink" style="float: right; margin-left: -4px;"></span>');
		}
	});
	
	// --- border on tables (left)
	$('.block-holder .block>div>table>tbody>tr').each(function () {
		$(this).children('td:first').css({ 'border-left' : '1px dotted #cacaca' });
	});

	// --- mail current page to someone.
	$('.mail').click(function () {
		$('#dialog').dialog({
			'draggable' : false,
			'modal' : true,
			'resizable' : false
		});
	});
	
	$('#dialog>form').submit(function (e) {
		e.preventDefault();
		$.post($(this).attr('action'), $(this).serialize(), function (data, textStatus, jqXHR) {
			$('#dialog').dialog('close');
		});
	});
});
