
/*

	BANNERS

*/


	
	
	
	function preloadList(list){
		if (document.images)
	    {
	       var i = 0;
	       for(i=0; i<list.length; i++){
	       	   eval("preload_image_object_"+i+" = new Image();");
	            eval("preload_image_object_"+i+".src = list[i][1];");
	       }
	    }
	}	
	
		/*myRequest.callback = function (responseText, responseStatus) {
		  if (responseStatus==200) {
		    alert(responseText);
		  } else {
		    alert(responseStatus + ' -- Error Processing Request');
		  }  
		} */
	function opacity(id, opacStart, opacEnd, millisec) {
		if(millisec==null) millisec = 1000
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
	
		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				if(i!=0){
					/*setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));*/
					timer++;
				} else {
					setTimeout("removeElem('" + id + "')",(timer * (speed*3)));
				}
			}
		} else if(opacStart < opacEnd) {
			changeOpac(0,id)
			for(i = opacStart; i <= opacEnd; i++)
				{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
	}
	function removeElem(id){
		var elem = document.getElementById(id)
		elem.parentNode.removeChild(elem) 
	}
	//change the opacity for different browsers
	function changeOpac(opacity, id) {
		/*
		 *
		 *
		 * LOG
		 *
		 *
		 *
		var log = document.getElementById("banner_log")
		
		var log_chunk = document.getElementById("log_"+id)
		if(log_chunk==null) {
			var log_chunk = document.createElement("p")
			log_chunk.id= "log_"+id
			log.appendChild(log_chunk)
		}
		
		log_chunk.innerHTML = id+":"+opacity
		*/
		
		var parent = document.getElementById(id); 
		var imgs = parent.getElementsByTagName("img")
		for (i=0; i<imgs.length ; i++){
			object = imgs[i].style
			object.opacity = (opacity / 100);
			object.MozOpacity = (opacity / 100);
			object.KhtmlOpacity = (opacity / 100);
			object.filter = "alpha(opacity=" + opacity + ")";
		}
	}
	
	function pointer(size){
		this.position = 0
		this.size = size?size:0
		this.next = function(){
			if(this.position >= (this.size - 1))
				this.position = 0
			else 
				this.position++
			return this.position
		}
		this.setSize = function(size){
			this.size = size
		}
	}
	function startMovie(frequency){
		this.pointer_a = new pointer(banners_a.length)
		this.pointer_b = new pointer(banners_b.length)
		this.pointer_l = new pointer(banners_l.length)
		this.frequency = frequency  
		this.show = "s_0_0".split("_")
		this.last_tipo = ""
		this.last = ""
		this.next = function(){
			this.last = this.show
			this.last_tipo = this.last[0]

			
			
			var will_change = false
				
			var check = "l"
			
			if(check == "s"){
				var pos_a = pointer_a.next()
				var pos_b = pointer_b.next()
				this.show = new Array(check, pos_a, pos_b)
			} else {
				var pos = pointer_l.next()
				this.show = new Array(check, pos)
			}
			if(this.show!=this.last){
				this.showNext()
				this.setTimeout("this.next()", this.frequency)
				
			}
		}
		this.showNext = function(){
			opacity(this.last.join("_"), 100, 0)
			
			this.createElement()
			
		}
		this.createElement = function (){
			var elem = document.createElement("div")
			elem.id=this.show.join("_")
			elem.className ="bannerContainer"
			
			if(this.show[0]=="l"){
				var bannerl = this.createBanner("L", banners_l[show[1]])
				elem.appendChild(bannerl)
			} else {
				var bannera = this.createBanner("A", banners_a[show[1]])
				var bannerb = this.createBanner("B", banners_b[show[2]])
				elem.appendChild(bannera)
				elem.appendChild(bannerb)
			}
			var blockBanner = document.getElementById("blockBanner")
			
			blockBanner.appendChild(elem)
			
			opacity(elem.id, 0, 100)
		} 
		this.createBanner = function(type, info){
			var elem = document.createElement("div")
			elem.className = "headerBanner"+type
			var link = document.createElement("a")
			link.href= info[2]
			link.target = "_blank"
			var img = document.createElement("img")
			img.src=info[1]
			img.alt=info[0]
			
			elem.appendChild(img)
			return elem
		}
		bl = banners_l.length>0
		bl1 = banners_l.length>1
		ba = banners_a.length>0
		ba1 = banners_a.length>1
		bb = banners_b.length>0
		bb1 = banners_b.length>1
		bab = ba && bb
		bab1 = bab && (ba1 || ba1)
		will_next = (bl1||bab1)||(bl&&bab)
		
		var next_frequency = frequency
		if(will_next)
			this.timeout = setTimeout("this.next()", next_frequency)
		
	}
