function add_null_before (n)
{
	if (n < 10) return '0' + n;
	else return n;
}

$(document).ready(function(){	

	$(".rounded").corner();	

	/*Galleria.loadTheme('/design/scripts/galleria/themes/classic/galleria.classic.js');*/

	//$('#galleria').galleria();


	$("input[name=callnum]").mask("(999) 999-9999");
	$("input[name=calldate]").mask("9999.99.99 99:99");
	
	
	var d = new Date;
	$('input[name=calldate]').val( d.getFullYear() + '.' + add_null_before(d.getMonth() + 1) + '.' + add_null_before(d.getDate()) + ' ' + add_null_before(d.getHours()) + ':' + add_null_before(d.getMinutes()));
	
	if ($('#galleria2').length >= 1) 
	{
		$('#galleria2').galleryView({
			panel_width: 700,
			panel_height: 600,
			frame_width: 100,
			frame_height: 100,
			
			overlay_color: '#222',
			overlay_text_color: 'white',
			caption_text_color: '#222',
			background_color: 'transparent',
			border: 'none',
			nav_theme: 'dark',
			easing: 'easeInOutQuad',
			pause_on_hover: true
		});

	}
	

	$("a.visit").fancybox({
		width				: 425,
		height				: 600,
		autoScale			: false,
		transitionIn		: 'none',
		transitionOut		: 'none',
		type				: 'iframe',
		titleShow			: false,
		overlayShow 		: false,
		showCloseButton	 	: false,
		onComplete			: function(){setTimeout("$('#fancybox-close').css({display: 'block'}).addClass('blank_close')",2000);}
	});

});





// разворачивающееся меню



function changeClass(source) {
	$(source).toggleClass('open');
}



function deletClass(source) {
	//debugger;
	$(source).removeClass('open');
}



function menuFunction(source, link) {
//	debugger;
// проверяем - есть у <li>, родительского для нажатой ссылки, внутри другие списки
	if ($(source).parent("li").children("ul").length) {
// если есть - просто открываем внутренний список
		changeClass('#' + $(source).parents('li[id*=item]').attr('id'));	
		return false;
	} else {	
// если нет - переходим по ссылке
		 window.location.href = link;
		}
  	};
 	

function cabinetFunction(source) {
	changeClass($(source).parents('li'));	
};


$(function() {

	$('ul#tabs').delegate('li:not(.current)', 'click', function() {
		$(this).addClass('current').siblings().removeClass('current')
			.parents('div#section').find('div.box').hide().eq($(this).index()).fadeIn(150);
	})

})
