// JavaScript Document

/* Objects compatibility */
try { Window;} catch(err){ Window = Object;}

/* Object properties */
Element.prototype.getStyleValue = function(property){
	var styleValue;

	if (this.currentStyle){
		if (property.indexOf('-') > -1){
			property = property.substr(0, property.indexOf('-'))+property.substr(property.indexOf('-')+1).ucFirst();
		}

		styleValue = this.currentStyle[property];
	} else if (window.getComputedStyle){
		styleValue = document.defaultView.getComputedStyle(this, null).getPropertyValue(property);
	} 
	
	if (!styleValue){ styleValue = this.style[property];}

	return styleValue;
}

/* Fading effects */
Element.prototype.fade = function(opacity){
	(this.filters)? this.style.filter = 'alpha(opacity='+opacity+');' : this.style.opacity = (opacity/100);
}

Element.prototype.getFade = function(){	
	try{
		return this.filters.alpha.opacity;
	} catch(err){
		return this.getStyleValue('opacity')*100;
	}
}

Element.prototype.fadeTo = function(opacity, delay){
	if (this.getFade() == opacity){ return;}
	if (!delay || delay < 0){ delay = 50;}
	
	var changeFade = function(obj){
		var currentFade = obj.getFade();
	
		if ((currentFade-10) > opacity){
			obj.fade(currentFade-10);	
		} else if ((currentFade+10) < opacity){
			obj.fade(currentFade+10);	
		} else {
			obj.fade(opacity);
		}
	
		if (currentFade != opacity){
			var t = window.setTimeout(function(){ changeFade(obj);}, delay);	
		} else {
			clearTimeout(t);	
		}
	}
	
	changeFade (this);
}

var promoTiker = {
	start: function(){
		var panels = promoTiker.getPanels();
		promoTiker.runPanels(panels, 0);
	},
	getPanels: function(){
		var tiker = document.getElementById('tiker');
		var divs = tiker.getElementsByTagName('div');
		
		var panels = Array();
		for (d = 0; d < divs.length; d++){
			if (divs[d].className == 'panel'){ panels[panels.length] = divs[d];}
		}
		return panels;
	},
	runPanels: function(panels, idx){
		panels[idx].fade(0);
		panels[idx].style.display = 'none';
		
		var nidx = (idx == panels.length-1)? 0 : idx+1;
				
		panels[nidx].style.display = 'block';
		if (document.all){
			panels[nidx].fade(100);
		} else {
			panels[nidx].fadeTo(100, 100);
		}
		
		setTimeout(function(){ promoTiker.runPanels(panels, nidx);}, 7000);
	}
}

window.onload = function(){ promoTiker.start();}
