function startDinamicBanners(){
	entidadesCheckWidth();
	parceirosCheckWidth();
}

function entidadesCheckWidth(){
	var pathpics="views/client/home/img/";
	var pic_toleft_active="scrolltoleft_y.gif";
	var pic_toleft_inative="scrolltoleft_n.gif";
	var pic_toright_active="scrolltoright_y.gif";
	var pic_toright_inative="scrolltoright_n.gif";
	var pic_obj_toleft=document.getElementById('home_entidades_pictoleft');
	var pic_obj_toright=document.getElementById('home_entidades_pictoright');
	var mainObj=document.getElementById('home_entidade_majorbox_content');
	var litleObj=document.getElementById('home_entidade_contentbox');
	
	if(litleObj.offsetWidth>mainObj.offsetWidth){
		pic_obj_toright.src=pathpics+pic_toright_active;
		
		pic_obj_toright.onmouseover=function(){
			scrollDivLeft('home_entidade_majorbox_content');
		}
		pic_obj_toright.onmouseout=function(){
			stopMe();
			if(mainObj.scrollLeft==litleObj.offsetWidth-mainObj.offsetWidth){
				pic_obj_toright.src=pathpics+pic_toright_inative;
				pic_obj_toright.onmouseover=function(){ return false; }
				pic_obj_toright.onmouseout=function(){ return false; }						
			}
			window.entidadesToLeft=function(){
				if(mainObj.scrollLeft>0){
				    pic_obj_toleft.src=pathpics+pic_toleft_active;
				    pic_obj_toleft.onmouseover=function(){
				    	scrollDivRight('home_entidade_majorbox_content');
				    }
				    pic_obj_toleft.onmouseout=function(){
				    	stopMe();
				    	if(mainObj.scrollLeft==0){
				    		pic_obj_toleft.src=pathpics+pic_toleft_inative;
				    		pic_obj_toleft.onmouseover=function(){ return false; }
				    		pic_obj_toleft.onmouseout=function(){ return false; }						
				    	}
				    	if(mainObj.scrollLeft<litleObj.offsetWidth-mainObj.offsetWidth){
				    		pic_obj_toright.src=pathpics+pic_toright_active;
				
				    		pic_obj_toright.onmouseover=function(){
				    			scrollDivLeft('home_entidade_majorbox_content');
				    		}
				    		pic_obj_toright.onmouseout=function(){
				    			stopMe();
				    			entidadesToLeft();
				    			entidadesCheckWidth();	
				    		}						
				    	}
				    }				
				}
			}
			entidadesToLeft();				
		}			
			
	}
}

function parceirosCheckWidth(){
	var pathpics="views/client/home/img/";
	var pic_toleft_active="scrolltoleft_y.gif";
	var pic_toleft_inative="scrolltoleft_n.gif";
	var pic_toright_active="scrolltoright_y.gif";
	var pic_toright_inative="scrolltoright_n.gif";
	
	var pic_obj_toleft=document.getElementById('home_parceiros_pictoleft');
	var pic_obj_toright=document.getElementById('home_parceiros_pictoright');
	var mainObj=document.getElementById('home_parceiro_majorbox_content');
	var litleObj=document.getElementById('home_parceiro_contentbox');
	
	if(!litleObj) return false;
	
	if(litleObj.offsetWidth>mainObj.offsetWidth){
		pic_obj_toright.src=pathpics+pic_toright_active;
		
		pic_obj_toright.onmouseover=function(){
			scrollDivLeft('home_parceiro_majorbox_content');
		}
		pic_obj_toright.onmouseout=function(){
			stopMe();
			if(mainObj.scrollLeft==litleObj.offsetWidth-mainObj.offsetWidth){
				pic_obj_toright.src=pathpics+pic_toright_inative;
				pic_obj_toright.onmouseover=function(){ return false; }
				pic_obj_toright.onmouseout=function(){ return false; }						
			}
			window.entidadesToLeft=function(){
				if(mainObj.scrollLeft>0){
				    pic_obj_toleft.src=pathpics+pic_toleft_active;
				    pic_obj_toleft.onmouseover=function(){
				    	scrollDivRight('home_parceiro_majorbox_content');
				    }
				    pic_obj_toleft.onmouseout=function(){
				    	stopMe();
				    	if(mainObj.scrollLeft==0){
				    		pic_obj_toleft.src=pathpics+pic_toleft_inative;
				    		pic_obj_toleft.onmouseover=function(){ return false; }
				    		pic_obj_toleft.onmouseout=function(){ return false; }						
				    	}
				    	if(mainObj.scrollLeft<litleObj.offsetWidth-mainObj.offsetWidth){
				    		pic_obj_toright.src=pathpics+pic_toright_active;
				
				    		pic_obj_toright.onmouseover=function(){
				    			scrollDivLeft('home_parceiro_majorbox_content');
				    		}
				    		pic_obj_toright.onmouseout=function(){
				    			stopMe();
				    			entidadesToLeft();
				    			entidadesCheckWidth();	
				    		}						
				    	}
				    }				
				}
			}
			entidadesToLeft();				
		}			
			
	}
}

var global_home_banslider_pos = 0;
var global_home_banslider_time = 10000;
var global_home_banslider_thetime;

var global_home_banslider_time = Array();
var global_home_banslider_picture = Array();
var global_home_banslider_title = Array();
var global_home_banslider_description = Array();
var global_home_banslider_url = Array();
var global_home_banslider_target = Array();

function homeGetBannersSlider(){
	var bans_prev = document.getElementById('bannerslider_previous');
	var bans_next = document.getElementById('bannerslider_next');	
	XMLaddress = '?,serv=xml_bannerslider';
 	//loading(1);
 	var xmlhttp=ajax();
    xmlhttp.onreadystatechange = function() { 
          if (xmlhttp.readyState==4) {
               if (xmlhttp.status==200) {
					var tags = xmlhttp.responseXML;
					var dataTag = tags.getElementsByTagName('data');
					var datareadTag = dataTag[0].getElementsByTagName('dataread');
					
					var datareadTag_sure = datareadTag[0].getAttribute('sure');
					if(datareadTag_sure!="1"){
						//loading(0);
						alert(datareadTag[0].childNodes[0].data);
						return false;
					}
					
					var bannersTag = dataTag[0].getElementsByTagName('banners');
					var banTag = bannersTag[0].getElementsByTagName('ban');
					if(banTag.length<=1) return false;
					
					for(var i=0; i<banTag.length; i++){
						
						var pictureTag = banTag[i].getElementsByTagName('picture');
						global_home_banslider_picture[i] = pictureTag[0].childNodes[0].data;
						global_home_banslider_time[i] = pictureTag[0].getAttribute('time');
						global_home_banslider_time[i] = global_home_banslider_time[i] * 1000;

						var titleTag = banTag[i].getElementsByTagName('title');
						global_home_banslider_title[i] = titleTag[0].childNodes[0].data;
						
						var descriptionTag = banTag[i].getElementsByTagName('description');
						global_home_banslider_description[i] = descriptionTag[0].childNodes[0].data;
						
						var urlTag = banTag[i].getElementsByTagName('url');
						global_home_banslider_url[i] = urlTag[0].childNodes[0].data;
						global_home_banslider_target[i] = urlTag[0].getAttribute('target');	
						
					}
					bans_prev.className = "enabled";
					bans_next.className = "enabled";
					homeGoToBanner();					
					//loading(0);
               } 
          }
     };
     xmlhttp.open("GET", XMLaddress);
     xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     xmlhttp.send(null);		
}

function homeGoToBanner(){
	var last_position = global_home_banslider_pos;
	var path_pics = "views/client/home/img/banners/slider/";
	var bans_picture = document.getElementById('bannerslider_picture');
	var bans_title = document.getElementById('bannerslider_title');
	var bans_description = document.getElementById('bannerslider_description');
	
	var bans_prev = document.getElementById('bannerslider_previous');
	var bans_next = document.getElementById('bannerslider_next');
	
	var boxonban = document.getElementById('homeboxonpicbannerslider');
	
	var imagefile = path_pics+global_home_banslider_picture[global_home_banslider_pos];
	blendimage('homeboxonpicbannerslider', 'bannerslider_picture', imagefile, 700);
	bans_title.innerHTML = global_home_banslider_title[global_home_banslider_pos];
	bans_description.innerHTML = global_home_banslider_description[global_home_banslider_pos];
	
	bans_picture.alt = global_home_banslider_title[global_home_banslider_pos];
	bans_picture.title = global_home_banslider_title[global_home_banslider_pos];
	
	if(
		global_home_banslider_url[global_home_banslider_pos] != ""
		&& global_home_banslider_url[global_home_banslider_pos] != "0"
	){
		bans_picture.onclick = function(){
			window.open(global_home_banslider_url[last_position], global_home_banslider_target[last_position]);
		};
		bans_picture.className = "banner_wourl";
	} else {
		bans_picture.onclick = function(){ return false; };
		bans_picture.className = "banner_nourl";
	}
	
	var posarr_time;
	if(global_home_banslider_pos == (global_home_banslider_picture.length-1)){
		global_home_banslider_pos = 0;
		posarr_time = global_home_banslider_picture.length-1;
	} else {
		global_home_banslider_pos++;
		posarr_time = global_home_banslider_pos-1;
	}
	global_home_banslider_thetime = setTimeout("homeGoToBanner();", global_home_banslider_time[posarr_time]);
}

function homeNextBanner(){
	if(global_home_banslider_picture.length == 0) return false;
	clearTimeout(global_home_banslider_thetime);
	homeGoToBanner();
}

function homePreviousBanner(){
	if(global_home_banslider_picture.length == 0) return false;
	clearTimeout(global_home_banslider_thetime);
	if(global_home_banslider_pos == 1){
		global_home_banslider_pos = global_home_banslider_picture.length-1;
	} else if(global_home_banslider_pos == 0){
		global_home_banslider_pos = global_home_banslider_picture.length-2;
	} else {
		global_home_banslider_pos-=2;
	}
	homeGoToBanner();	
}