
var parts=40;
var MoveSpeed=5;
var subp=115;
var bgOffset=-80;

var mt1;
var mt2;
var mt3;
var mt4;
var WidthFull=0;
var WidthNormal=0;
var WidthMin=0;
var WidthMax=0;
var i=0;
var menu;
var img_mt1;
var img_mt2;
var img_mt3;
var img_mt4;
var mt1FromWidth=0;
var mt2FromWidth=0;
var mt3FromWidth=0;
var mt4FromWidth=0;
var mt1ToWidth=0;
var mt2ToWidth=0;
var mt3ToWidth=0;
var mt4ToWidth=0;
var mt1Step=0;
var mt2Step=0;
var mt3Step=0;
var mt4Step=0;
var timeMove=0;
var LastID;
var LastMove;
var mt1newWidth=0;
var mt2newWidth=0;
var mt3newWidth=0;
var mt4newWidth=0;
var sub1;
var sub2;
var sub3;
var sub4;
var sub1p=0;
var sub2p=0;
var sub3p=0;
var sub4p=0;
var textStep=0;
var bg1=0;
var bg2=0;
var bg3=0;
var bg4=0;
var bgStep=0;
var mt1d;
var mt2d;
var mt3d;
var mt4d;
var img_1=new Image();
img_1.src="img/tiz_bg_about.jpg";
var bg1i='tiz_bg_about.jpg';
var img_2=new Image();
img_2.src="img/tiz_bg_fl.jpg";
var bg2i='tiz_bg_fl.jpg';
var img_3=new Image();
img_3.src="img/tiz_bg_ul.jpg";
var bg3i='tiz_bg_ul.jpg';
var img_4=new Image();
img_4.src="img/tiz_bg_inet.jpg";
var bg4i='tiz_bg_inet.jpg';
var newSubWidth='false';

function BuildMenu() {
	if(!document.getElementById('dm1')) return false;
	if(navigator.appName != "Microsoft Internet Explorer") {
		document.getElementById('dm1').style.position='relative';
		document.getElementById('dm2').style.position='relative';
		document.getElementById('dm3').style.position='relative';
		document.getElementById('dm4').style.position='relative';
	}
	mt1 = document.getElementById('mt1');
	mt2 = document.getElementById('mt2');
	mt3 = document.getElementById('mt3');
	mt4 = document.getElementById('mt4');
	mt1d = document.getElementById('mt1d');
	mt2d = document.getElementById('mt2d');
	mt3d = document.getElementById('mt3d');
	mt4d = document.getElementById('mt4d');
	img_mt1 = document.getElementById('img_mt1');
	img_mt2 = document.getElementById('img_mt2');
	img_mt3 = document.getElementById('img_mt3');
	img_mt4 = document.getElementById('img_mt4');
	WidthFull=mt1.clientWidth+mt2.clientWidth+mt3.clientWidth+mt4.clientWidth-8;
	WidthNormal=Math.floor(WidthFull/4);
	WidthMin=Math.floor(WidthFull*(0.2));
	WidthMax=Math.floor(WidthFull*(0.4));
	sub1 = document.getElementById('sub1');
	sub2 = document.getElementById('sub2');
	sub3 = document.getElementById('sub3');
	sub4 = document.getElementById('sub4');
	sub1.style.padding='0 0 0 '+WidthNormal+'px';
	sub2.style.padding='0 0 0 '+WidthNormal+'px';
	sub3.style.padding='0 0 0 '+WidthNormal+'px';
	sub4.style.padding='0 0 0 '+WidthNormal+'px';
	sub1p=sub2p=sub3p=sub4p=WidthNormal;
	sub1.style.width='100%';
	sub2.style.width='100%';
	sub3.style.width='100%';
	sub4.style.width='100%';
	if (navigator.appName == "Microsoft Internet Explorer" || navigator.appName == "Opera")
		newSubWidth='true';
}

function setMax(menu) {
	if(typeof mt1=='undefined') return true;
	LastID=menu.id;
	mt1FromWidth=mt1.clientWidth;
	mt2FromWidth=mt2.clientWidth;
	mt3FromWidth=mt3.clientWidth;
	mt4FromWidth=mt4.clientWidth;
	mt1ToWidth=WidthMin;
	mt2ToWidth=WidthMin;
	mt3ToWidth=WidthMin;
	mt4ToWidth=WidthMin;

	switch(menu.id) {
		case 'mt1' :
			mt1ToWidth=WidthFull-WidthMin*3;
			document.getElementById('mt1t').style.background="#FF4E00";
			if (newSubWidth == 'true') sub1.style.width='560px';
			sub1.style.display='block';
			break;
		case 'mt2' :
			mt2ToWidth=WidthFull-WidthMin*3;
			document.getElementById('mt2t').style.background="#FF4E00";
			if (newSubWidth == 'true') sub2.style.width='560px';
			sub2.style.display='block';
			break;
		case 'mt3' :
			mt3ToWidth=WidthFull-WidthMin*3;
			document.getElementById('mt3t').style.background="#FF4E00";
			if (newSubWidth == 'true') sub3.style.width='560px';
			sub3.style.display='block';
			break;
		case 'mt4' :
			mt4ToWidth=WidthFull-WidthMin*3;
			document.getElementById('mt4t').style.background="#FF4E00";
			if (newSubWidth == 'true') sub4.style.width='560px';
			sub4.style.display='block';
			break;
		default :
			mt1ToWidth=WidthNormal;document.getElementById('mt1t').style.background="#00749C";
			mt2ToWidth=WidthNormal;document.getElementById('mt2t').style.background="#00749C";
			mt3ToWidth=WidthNormal;document.getElementById('mt3t').style.background="#00749C";
			mt4ToWidth=WidthFull-WidthNormal*3;document.getElementById('mt4t').style.background="#00749C";
			sub1.style.display='none';
			sub2.style.display='none';
			sub3.style.display='none';
			sub4.style.display='none';
			if (newSubWidth == 'true') {
				sub1.style.width='100%';
				sub2.style.width='100%';
				sub3.style.width='100%';
				sub4.style.width='100%';
			}
			break;
	}
	if(Math.abs(mt1ToWidth-mt1FromWidth)>2)
		mt1Step=((mt1ToWidth-mt1FromWidth)/parts);
	else
		mt1Step=0;
	if(Math.abs(mt2ToWidth-mt2FromWidth)>2)
		mt2Step=((mt2ToWidth-mt2FromWidth)/parts);
	else
		mt2Step=0;
	if(Math.abs(mt3ToWidth-mt3FromWidth)>2)
		mt3Step=((mt3ToWidth-mt3FromWidth)/parts);
	else
		mt3Step=0;
	if(Math.abs(mt4ToWidth-mt4FromWidth)>2)
		mt4Step=((mt4ToWidth-mt4FromWidth)/parts);
	else
		mt4Step=0;
	textStep=(WidthNormal-subp)/parts;
	bgStep=bgOffset/parts;
//	alert(mt1Step+' '+mt2Step+' '+mt3Step+' '+mt4Step);
	i=0;
	timeMove=setTimeout('MoveMenu();',MoveSpeed);
}

function MoveMenu() {
	if(typeof mt1=='undefined') return true;
	if(LastID && LastMove==LastID) {
		return true;
	}
	if(i>=parts) {
		clearTimeout(timeMove);
		img_mt1.style.width=mt1ToWidth+'px';
		img_mt2.style.width=mt2ToWidth+'px';
		img_mt3.style.width=mt3ToWidth+'px';
		img_mt4.style.width=mt4ToWidth+'px';
		sub1p=WidthNormal;
		sub2p=WidthNormal;
		sub3p=WidthNormal;
		sub4p=WidthNormal;
		bg1=0;
		bg2=0;
		bg3=0;
		bg4=0;
		if(LastID=='mt1') {
			sub1p=subp;
			bg1=bgOffset;
		} else if(LastID=='mt2') {
			sub2p=subp;
			bg2=bgOffset;
		} else if(LastID=='mt3') {
			sub3p=subp;
			bg3=bgOffset;
		} else if(LastID=='mt4') {
			sub4p=subp;
			bg4=bgOffset;
		}
		sub1.style.padding='0 0 0 '+sub1p+'px';
		sub2.style.padding='0 0 0 '+sub2p+'px';
		sub3.style.padding='0 0 0 '+sub3p+'px';
		sub4.style.padding='0 0 0 '+sub4p+'px';
		mt1d.style.left=Math.round(bg1)+'px';
		mt2d.style.left=Math.round(bg2)+'px';
		mt3d.style.left=Math.round(bg3)+'px';
		mt4d.style.left=Math.round(bg4)+'px';
		document.getElementById('dmt1d').style.width=190+Math.round(bg1)+'px';
		document.getElementById('dmt2d').style.width=190+Math.round(bg2)+'px';
		document.getElementById('dmt3d').style.width=190+Math.round(bg3)+'px';
		document.getElementById('dmt4d').style.width=190+Math.round(bg4)+'px';
		LastMove=LastID;
		return true;
	}
	i++;
	mt1newWidth=Math.ceil(mt1FromWidth+mt1Step*i);
	mt2newWidth=Math.ceil(mt2FromWidth+mt2Step*i);
	mt3newWidth=Math.ceil(mt3FromWidth+mt3Step*i);
	mt4newWidth=Math.ceil(mt4FromWidth+mt4Step*i);
	if((mt1Step>0 && mt1newWidth>=mt1ToWidth) || (mt1Step<0 && mt1newWidth<=mt1ToWidth))
		mt1newWidth=mt1ToWidth;
	if((mt2Step>0 && mt2newWidth>=mt2ToWidth) || (mt2Step<0 && mt2newWidth<=mt2ToWidth))
		mt2newWidth=mt2ToWidth;
	if((mt3Step>0 && mt3newWidth>=mt3ToWidth) || (mt3Step<0 && mt3newWidth<=mt3ToWidth))
		mt3newWidth=mt3ToWidth;
	if((mt4Step>0 && mt4newWidth>=mt4ToWidth) || (mt4Step<0 && mt4newWidth<=mt4ToWidth))
		mt4newWidth=mt4ToWidth;
	switch(LastID) {
		case 'mt1' :
			mt1newWidth=WidthFull-mt2newWidth-mt3newWidth-mt4newWidth;
			if(sub1p>subp)
				sub1p-=textStep;
			if(bg1>bgOffset)
				bg1+=bgStep;
			break;
		case 'mt2' :
			mt2newWidth=WidthFull-mt1newWidth-mt3newWidth-mt4newWidth;
			if(sub2p>subp)
				sub2p-=textStep;
			if(bg2>bgOffset)
				bg2+=bgStep;
			break;
		case 'mt3' :
			mt3newWidth=WidthFull-mt1newWidth-mt2newWidth-mt4newWidth;
			if(sub3p>subp)
				sub3p-=textStep;
			if(bg3>bgOffset)
				bg3+=bgStep;
			break;
		case 'mt4' :
			mt4newWidth=WidthFull-mt1newWidth-mt3newWidth-mt2newWidth;
			if(sub4p>subp)
				sub4p-=textStep;
			if(bg4>bgOffset)
				bg4+=bgStep;
			break;
		default:
			mt1newWidth=WidthFull-mt2newWidth-mt3newWidth-mt4newWidth;
			break;
	}
	if(LastID!='mt1' && sub1p<WidthNormal) {
		sub1p+=textStep;
	} else if(LastID!='mt2' && sub2p<WidthNormal) {
		sub2p+=textStep;
	} else if(LastID!='mt3' && sub3p<WidthNormal) {
		sub3p+=textStep;
	} else if(LastID!='mt4' && sub4p<WidthNormal) {
		sub4p+=textStep;
	}
	if(LastID!='mt1' && bg1<0) {
		bg1-=bgStep;
	} else if(LastID!='mt2' && bg2<0) {
		bg2-=bgStep;
	} else if(LastID!='mt3' && bg3<0) {
		bg3-=bgStep;
	} else if(LastID!='mt4' && bg4<0) {
		bg4-=bgStep;
	}
	sub1.style.padding='0 0 0 '+sub1p+'px';
	sub2.style.padding='0 0 0 '+sub2p+'px';
	sub3.style.padding='0 0 0 '+sub3p+'px';
	sub4.style.padding='0 0 0 '+sub4p+'px';
	mt1d.style.left=Math.round(bg1)+'px';
	mt2d.style.left=Math.round(bg2)+'px';
	mt3d.style.left=Math.round(bg3)+'px';
	mt4d.style.left=Math.round(bg4)+'px';
	document.getElementById('dmt1d').style.width=190+Math.round(bg1)+'px';
	document.getElementById('dmt2d').style.width=190+Math.round(bg2)+'px';
	document.getElementById('dmt3d').style.width=190+Math.round(bg3)+'px';
	document.getElementById('dmt4d').style.width=190+Math.round(bg4)+'px';
	img_mt1.style.width=Math.round(mt1newWidth)+'px';
	img_mt2.style.width=Math.round(mt2newWidth)+'px';
	img_mt3.style.width=Math.round(mt3newWidth)+'px';
	img_mt4.style.width=Math.round(mt4newWidth)+'px';
	timeMove=setTimeout('MoveMenu();',MoveSpeed);
}

window.onresize=BuildMenu;