var lbw,rbw,lc,rc,lhbwbg,rhbwbg,lhcbg,rhcbg;

changecolors();
function changecolors() {
	lc = document.getElementById('left-header-colored');
	rc = document.getElementById('right-header-colored');
	if(lc!=null && typeof(lc)!='undefined' && rc!=null && typeof(rc)!='undefined') {lc.style.display='none'; rc.style.display='none'; initPictures();}
	else {setTimeout(function () {changecolors(); }, 0); }
	
}

function initPictures() {
	lbw = document.getElementById('left-header-bw');
	rbw = document.getElementById('right-header-bw');
	
	lhbwbg = document.createElement('img');
	lhbwbg.setAttribute('src','/i/left-header-bg-bw2.gif');
	rhbwbg = document.createElement('img');
	rhbwbg.setAttribute('src','/i/right-header-bg-bw.jpg');
	lhcbg = document.createElement('img');
	lhcbg.setAttribute('src','/i/left-header-bg.gif');
	rhcbg = document.createElement('img');
	rhcbg.setAttribute('src','/i/right-header-bg.jpg');
	tester();
}

function tester() {

	if(lhbwbg.complete && rhbwbg.complete && lhcbg.complete && rhcbg.complete) {
		lbw = document.getElementById('left-header-bw');
		rbw = document.getElementById('right-header-bw');
		lc = document.getElementById('left-header-colored');
		rc = document.getElementById('right-header-colored');
		lbw.style.display = 'block';
		rbw.style.display = 'block';
		lc.style.display = 'block';
		rc.style.display = 'block';
		setTimeout(function() {bwToColor(); }, 3000);
	}
	else {setTimeout(function () {tester(); }, 0); }
	
}

function bwToColor() {
	
	lbw = document.getElementById('left-header-bw');
	rbw = document.getElementById('right-header-bw');
	
	
	var opacityProperty = getOpacityProperty();
	if (opacityProperty == 'opacity') {
		lbw.style.opacity = 1;
		rbw.style.opacity = 1;
		lint = window.setInterval('fadeopac(lbw)', 2);
		rint = window.setInterval('fadeopac(rbw)', 2);

	}
	else if (opacityProperty == 'filter' && navigator.userAgent.indexOf('5.5')==-1 && navigator.userAgent.indexOf('5.0')==-1) {
		fadefilteropac(lbw);
		fadefilteropac(rbw);
	}
	else {
		lbw.style.display = 'none';
		rbw.style.display = 'none';
	}
}

function fadeopac(element) {
	if (element == lbw) {
		if(lbw.style.opacity>0){
			lbw.style.opacity-=0.01;
			return;
		}
		clearInterval(lint);
	}
	if (element == rbw) {
		if(rbw.style.opacity>0){
			rbw.style.opacity-=0.01;
			return;
		}
		clearInterval(rint);
	}
}


function fadefilteropac(element) {
	if (element == lbw) {
		var oAlpha = lbw.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		var nOpacity = oAlpha.opacity;
		if(nOpacity>0){
			nOpacity-=1;
			oAlpha.opacity = nOpacity;
			setTimeout('fadefilteropac(lbw)', 0.0001);
		}
	}
	if (element == rbw) {
		var oAlpha = rbw.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		var nOpacity = oAlpha.opacity;
		if(nOpacity>0){
			nOpacity-=1;
			oAlpha.opacity = nOpacity;
			setTimeout('fadefilteropac(rbw)', 0.0001);
		}
	}
}




function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9, IE7)
    return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8 
    return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
    return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Explorer 5.5+
    return 'filter';

  return false; //нет прозрачности
}
