var Browser={
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
}

if(Browser.IE){
	var setOpacity=function(element,value){
		function stripAlpha(filter){
			return filter.replace(/alpha\([^\)]*\)/gi,'');
		}

		element=document.getElementById(element);
		var currentStyle=element.currentStyle;

		if((currentStyle&&!currentStyle.hasLayout)||(!currentStyle&&element.style.zoom=='normal'))
			element.style.zoom=1;

		var filter=element.style['filter'],style=element.style;

		if(value==1||value===''){
			(filter=stripAlpha(filter))?style.filter=filter:style.removeAttribute('filter');

			return element;
		}else if(value<0.00001)
			value=0;
		
		style.filter=stripAlpha(filter)+'alpha(opacity='+(value * 100)+')';
		style.display=value!=0?'':'none';

		return element;
	};
}else if(Browser.Gecko&&/rv:1\.8\.0/.test(navigator.userAgent)){
	function setOpacity(element,value){
		element=document.getElementById(element);

		element.style.opacity=(value==1)?0.999999:(value==='')?'':(value<0.00001)?0:value;
		element.style.display=value!=0?'':'none';

		return element;
	};
}else if(Browser.WebKit){
	function setOpacity(element,value){
		element=document.getElementById(element);

		element.style.opacity=(value==1||value==='')?'':(value<0.00001)?0:value;
		element.style.display=value!=0?'':'none';

		if(value==1)
			if(element.tagName=='IMG'&&element.width){
				element.width++; element.width--;
		}else try{
			var n=document.createTextNode(' ');
			element.appendChild(n);
			element.removeChild(n);
		}catch(e){ }

		return element;
	};
}else{
	var setOpacity=function(element,value){
		element=document.getElementById(element);
		element.style.opacity=(value==1||value==='')?'':(value<0.00001)?0:value;
		element.style.display=value!=0?'':'none';

		return element;
	};
}

function setZ(element,value){
	element=document.getElementById(element);
	element.style.zIndex=value;
	
	return element;
}

function setRankings(){
	for(i in morphList){
		setZ(morphList[i],i==morphNo?1:0);
		setOpacity(morphList[i],i==((morphNo<(morphList.length-1))?(morphNo+1):0)?1:0);
	}
}

var morphTime=1000;
var morphInterval=100;
var morphBreak=1500;
var morphStarttime=0;
var morphNo=0;
var morphFct;
var morphList=new Array();

var c=0;

while(document.getElementById('mm_b_art'+c)){
	morphList.splice(morphList.length,0,'mm_b_art'+c);
	c++;
}

if(morphList.length>1){
	morphNo=morphList.length-2;
	setRankings();
	morphFct=window.setInterval("morph()",morphBreak);
}

function morph(){
	var date=new Date();
	var current=date.getTime();

	window.clearInterval(morphFct);

	if(!morphStarttime){
		morphStarttime=current;
		morphFct=window.setInterval("morph()",morphInterval);
	}else if(current>=(morphStarttime+morphTime)){
		setOpacity('mm_b_art'+morphNo,1);
		morphNo=morphNo<1?morphList.length-1:morphNo-1;
		morphStarttime=0;
		setRankings();
		morphFct=window.setInterval("morph()",morphBreak);
	}else{
		setOpacity('mm_b_art'+morphNo,(current-morphStarttime)/morphTime);
		morphFct=window.setInterval("morph()",morphInterval);
	}
}
