// this event fires as soon as DOM is loaded successfully, so it's fired faster than $(window).ready()
jQuery(function(){
	
});

// thisi event is triggered only when all DOM elements are downloaded and loaded
$(window).ready(function (){
	
});

$(document).ready(function(){
	if($.browser.msie && $.browser.version < 7 ){
		$(".positionFixed").css('position', 'absolute');
		
		$(window).scroll(function() {
			$(".positionFixed").css("top", $(window).scrollTop() + "px");
		});
	}
	
	$('a.colorbox').colorbox();
});

var previousPage = 0;

function validate(type, name, param1, param2) {
	
	value = $('input[name='+name+']').val();

	$.post(validatorUrl, { type: type,  name: name, value: value, param1: param1, param2: param2 },
		function(data){
			data = $.trim(data);
			
			if (data == 1) {
				$('#validatorReturn'+name).addClass('validatorSuccess');
				$('#validatorReturn'+name).removeClass('validatorError');
			} else if (data == 2) {
				$('#validatorReturn'+name).addClass('validatorError');
				$('#validatorReturn'+name).removeClass('validatorSuccess');
			}
		}
	, 'text');
}

function showBlock(id, excludeScrool) {
	$('#block' + id).slideDown(400);
	$('#suspend' + id).show();
	$('#expand' + id).hide();
	$('#mainMenuItem' + id).addClass('active');
	$('#footerMenuItem' + id).addClass('active');
	
	if (!excludeScrool) {
		scrool('#entireBlock' + id);
	}
}

function hideBlock(id) {
	$('#block' + id).slideUp(400);
	$('#expand' + id).show();
	$('#suspend' + id).hide();
	$('#mainMenuItem' + id).removeClass('active');
	$('#footerMenuItem' + id).removeClass('active');
}

function showOnlyOne(id, excludeScrool, excludeHide) {
	if (previousPage == id) {
		if (!excludeHide) {
			previousPage = 0;
			hideBlock(id);
		}
	} else {
		previousPage = id;
		
		$('.itemContent').hide();
		$('#block' + id).slideDown(400);
		
		$('.expand').show();
		$('.suspend').hide();
		
		$('#expand' + id).hide();
		$('#suspend' + id).show();
		
		// menu 
		$('li.mainMenuItem a').removeClass('active');
		$('#mainMenuItem' + id).addClass('active');
		// footer menu 
		$('li.footerMenuItem a').removeClass('active');
		$('#footerMenuItem' + id).addClass('active');
		
		if (!excludeScrool) {
			scrool('#entireBlock' + id);
		}
	}
}

function showSubMenu(id) {
	$('#' + id).show();
}

function hideSubMenu(id) {
	//setTimeout( "hideSub('" + id + "')", 100);
	hideSub(id);
}

function hideSub(id) {
	$('#' + id).hide();
}

function showOnlyOneSub(id, parentId, excludeScrool) {
	$('.subMenu' + parentId + 'Block').hide();
	$('#subMenu' + parentId + 'Block' + id).show();
	
	// main menu 
	$('li.mainMenuSubItem a').removeClass('active');
	$('#mainMenu' + parentId + 'SubItem' + id).addClass('active');
	
	// sub menu 
	$('li.subMenu' + parentId + 'Item a').removeClass('active');
	$('#subMenu' + parentId + 'Item' + id).addClass('active');
	
	if (!excludeScrool) {
		scrool('#entireBlock' + parentId);
	}
}

function showOnlyOneSubSub(id, parentId, rootId, excludeScrool) {
	$('.sub' + rootId + 'subMenu' + parentId + 'Block').hide();
	$('#sub' + rootId + 'subMenu' + parentId + 'Block' + id).show();
	
	// main menu 
	$('li.mainMenuSubSubItem a').removeClass('active');
	$('#mainMenu' + rootId + 'Sub' + parentId + 'SubItem' + id).addClass('active');
	
	// sub menu 
	$('li.sub' + rootId + 'subMenu' + parentId + 'Item a').removeClass('active');
	$('#sub' + rootId + 'subMenu' + parentId + 'Item' + id).addClass('active');
}

function scrool(id, correctionPosition) {
	correction = 0;
	
	if (correctionPosition) {
		correction = correctionPosition;
	}
	
	//setTimeout("javascript:scroll(0, $('" + id + "').position().top - correction);");
}

function paging(type, page) {
	switch(type) {
		case 'first':
			if (pagingCurrent > 0 && pagingCurrent <= pagingTotal && !lock) {
				lock = true;
				$('#staffBlock' + pagingCurrent).fadeOut(300, function() 	{
																				pagingCurrent = 0;
																				$('#staffBlock' + pagingCurrent).fadeIn(300, function () { lock = false; });
																			});
			}
			break;
		case 'back':
			if (pagingCurrent > 0 && pagingCurrent <= pagingTotal && !lock) {
				lock = true;
				$('#staffBlock' + pagingCurrent).fadeOut(300, function () 	{
																				pagingCurrent--;
																				$('#staffBlock' + pagingCurrent).fadeIn(300, function () { lock = false; });
																			});
			}
			break;
		  break;
		case 'next':
			if (pagingCurrent >= 0 && pagingCurrent < pagingTotal && !lock) {
				lock = true;
				$('#staffBlock' + pagingCurrent).fadeOut(300, function ()	{
																				pagingCurrent++;
																				$('#staffBlock' + pagingCurrent).fadeIn(300, function () { lock = false; });
																			});
			}
			break;
		case 'last':
			if (pagingCurrent >= 0 && pagingCurrent < pagingTotal && !lock) {
				lock = true;
				$('#staffBlock' + pagingCurrent).fadeOut(300, function ()	{
																				pagingCurrent = pagingTotal;
																				$('#staffBlock' + pagingCurrent).fadeIn(300, function () { lock = false; });
																			});
			}
			break;
		case 'fixed':
			if (pagingCurrent >= 0 && pagingCurrent <= pagingTotal && pagingCurrent != page && !lock) {
				lock = true;
				$('#staffBlock' + pagingCurrent).fadeOut(300, function ()	{
																				pagingCurrent = page;
																				$('#staffBlock' + pagingCurrent).fadeIn(300, function () { lock = false; });
																			});
			}
			break;
		default:
			if (!lock) {
				lock = true;
				$('#staffBlock' + pagingCurrent).fadeIn(300, function () { lock = false; });
			}
			break;
	}
}

