var lInit = false;
var l1, l2, l3;

Chess.messages = {
	1: 'Шах',
	2: 'Вы под шахом',
	3: 'Мат',
	4: 'Пат'
}

myLines.prototype.init = function(){
	var _my = this;
	
	jQuery("#content .extend span.line").each(function(){
		_my.lines.push({ base: this});
	})
	
	this.createLine();
	
	jQuery(window).resize(function(){
		_my.draw();
	})
}

function isSwitch(status, before){
	switch(status){
		case '.short':
			if(before){
				il.hide();
			} else {
				if(!lInit){
					initPartnerLines();
				}
				showPartnerLines();
			}
			break;
		case '.extend':
			if(!before){
				if(!il){
					il = new myLines("#Lines");	
					il.init();
				}
				il.show();
			} else {
				hidePartnerLines();
			}
			break;
	}
	if(!before){
		updateNavigation(status)
	}
	
}


function initInnerLine(){
	if(jQuery("#content-layout .full").length != 0){
		il = new myLines("#Lines");
		il.init();
		il.show();
	} else {
		initPartnerLines();
	}
}

function initPartnerLines(){
	lInit = true;
	
	l1 = new AdaptiveLine(function(){
		return { x: 0, y: 0 }
	}, function(){
		_o = $('.short .start');
		_ofs = _o.offset()
		return { x: _ofs.left-10, y: _ofs.top+Math.round(_o.height()/2) }
	}, '#Lines');
	
	l2 = new AdaptiveLine(function(){
		_o = $('#chess');
		_ofs = _o.offset()
		return { x: _ofs.left+_o.find(".board").width()+50 }
	}, function(){
		_o = $('#finish .start');
		_ofs = _o.offset()
		return { x: _ofs.left-10, y: _ofs.top+Math.round(_o.height()/2) }
	}, '#Lines');
	
	l3 = new AdaptiveLine(function(){
		_o = $('#finish .end');
		_ofs = _o.offset()
		return { x: _ofs.left+10 }
	}, function(){
		_o = $('#finish .end');
		_ofs = _o.offset()
		return { x: $("#bodywidth").width(), y: _ofs.top+Math.round(_o.height()/2) }
	}, '#Lines');
	
	
}

function hidePartnerLines(){
	l1.hide(); l2.hide(); l3.hide();
}

function showPartnerLines(){
	l1.draw(); l2.draw(); l3.draw();
	l1.show(); l2.show(); l3.show();
}

function showVacancy(){
	$("#Vacancy .wrap").css({ top: -$("#Vacancy .wrap").height()-50, visibility: 'visible' }).animate({ top: $(".vacancy").offset().top-55 }, 500, 'easeout')
}

function hideVacancy(){
	$("#Vacancy .wrap").animate({ top: -$("#Vacancy .wrap").height()-50 }, 500, 'easein', function(){
		$(this).css({ visibility: 'hidden' });
	})
}
