var htmlEnquete = "";

var itemVideo = 1;
var intervalVideo = "";

function ApplicationManager() {

	this.loadCidades = function(objSource,objTarget,selectedItem,setDisabled) {		
		parans = "";
		uf = objSource.options[objSource.selectedIndex].value;	
			
		if (uf!="") {
			jQuery("#"+objTarget)[0].options[0].text = "Carregando...";
			jQuery("#"+objTarget)[0].disabled = true;	
			
			jQuery.ajax({
				url:"/ajax/ajaxRequest.php",
				type:"GET",
				data:"uf=" + uf + "&page=cidades&objTgt="+objTarget,				
				dataType:"html",
				success:function(response) {
					
					jQuery("#container_"+objTarget).html(response);
					
					if (selectedItem!=undefined) {
						jQuery("#"+objTarget).val(selectedItem);
					}
					
					if (setDisabled) {
					
						jQuery("#"+objTarget).attr("disabled","disabled");
					
					} else {
					
						jQuery("#"+objTarget).focus();
						
					}
										
				}
				
			});
					
		}	
	}

	this.passador = {	
		length:0,
		indice:1,
		interval:"",
		delay:8000,
		next:function() {
		
			clearInterval(this.interval);
		
			jQuery("#dest"+this.indice).hide();
		
			this.indice++;
			
			if (this.indice > this.size) {
			
				this.indice = 1;
				
			}
			
			jQuery("#dest"+this.indice).show();
			
			this.interval = setInterval("App.passador.next()",this.delay);
			
			$("#bt-pause").attr("class","pause");
			$("#bt-pause").attr("title","Pausar");			
								
		},
		prev:function() {
		
			clearInterval(this.interval);
		
			jQuery("#dest"+this.indice).hide();
		
			this.indice--;
			
			if (this.indice < 1) {
			
				this.indice = 5;
				
			}
			
			jQuery("#dest"+this.indice).show();
			
			this.interval = setInterval("App.passador.next()",this.delay);
			
			$("#bt-pause").attr("class","pause");
			$("#bt-pause").attr("title","Pausar");
			
								
		},
		start:function() {
		
			if (this.size > 1) {
				this.interval = setInterval("App.passador.next()",this.delay);
			}
		
		},
		pause:function() {
		
			if ($("#bt-pause").attr("class") == "pause") {
		
				clearInterval(this.interval);
				$("#bt-pause").attr("class","paused");
				$("#bt-pause").attr("title","Clique para continuar");
			
			} else {
				
				$("#bt-pause").attr("class","pause");
				$("#bt-pause").attr("title","Pausar");
				this.interval = setInterval("App.passador.next()",this.delay);
			
			}
		
		}
	}
	
	this.passadorBanner = {	
		length:0,
		indice:1,
		interval:"",
		delay:8000,
		next:function() {
		
			clearInterval(this.interval);
		
			jQuery("#banner-"+this.indice).hide();
		
			this.indice++;
			
			if (this.indice > this.size) {
			
				this.indice = 1;
				
			}
			
			this.selectDestaque();
								
		},
		prev:function() {
		
			clearInterval(this.interval);
		
			jQuery("#banner-"+this.indice).hide();
		
			this.indice--;
			
			if (this.indice < 1) {
			
				this.indice = this.size;
				
			}
			
			this.selectDestaque();
								
		},
		pause : function() {
			
			clearInterval(this.interval);
			
		},	
		start:function() {
		
			if (this.size > 1) {
				this.interval = setInterval("App.passadorBanner.next()",this.delay);
			}
		
		},
		selectDestaque:function() {
			
			clearInterval(this.interval);
			
			$("#container_banner_rotativo .section").hide();
			$("#banner-"+this.indice).show();
			
			this.start();
			
		},
		showOptions : function(option) {
			
			if (option) {
				$("#fotooptions").show();
			} else {
				$("#fotooptions").hide();
			}
		
		}
	}
	
	this.selectVideo = function(obj) {
		
		clearInterval(intervalVideo);
		
		itemVideo = $(obj).text();
		
		$(".passador-video a").removeClass("selected");
		$(obj).addClass("selected");
		
		$(".vidcont").hide();
		$("#video_"+$(obj).text()).show();
		
		App.playVideoList();
		
	
	}
	
	this.playVideoList = function() {
	
		itemVideo++;
		
		if (itemVideo > 5) {
			
			itemVideo = 1;
		
		}
	
		intervalVideo = setInterval(function() {
			
			App.selectVideo($(".passador-video a")[itemVideo-1]);
		
		},5000);
	
	}
	
	this.postComent = function() {
	
		jQuery('#comentform').ajaxSubmit({
			url:"/ajax/ajaxRequest.php",				
			type:"POST",				
			success: function(response) {	
				
				eval(response);
				
			}
		}); 	
		
	}
	
	this.postContato = function() {
	
		jQuery('#contatoform').ajaxSubmit({
			url:"/ajax/ajaxRequest.php",				
			type:"POST",				
			success: function(response) {	
				
				eval(response);
				
			}
		}); 	
		
	}
	
	this.votar = function() {
	
		if (jQuery('#enqueteform input[@type=radio]:checked').length == 0) {
		
			alert("Por favor! Selecione uma opção deste enquete!"); return false;
		
		}
	
		jQuery('#enqueteform').ajaxSubmit({
			url:"/ajax/ajaxRequest.php",				
			type:"POST",				
			success: function(response) {	
				
				eval(response);
				
			}
		}); 	
		
	}
	
	this.resultado = function() {
		
		htmlEnquete = $("#enquete-container").html();
		
		jQuery('#enqueteform').ajaxSubmit({
			url:"/ajax/ajaxRequest.php",				
			type:"POST",				
			success: function(response) {	
				
				eval(response);
				
			}
		}); 	
		
	}
	
	this.getMoreNews = function(item,type) {
	
		jQuery('#aba-more-news a').removeClass("selected");
		jQuery(item).addClass("selected");
		
		othertype = (type == "acessadas") ? "comentadas":"acessadas";
		
		jQuery("#listing-mais-"+othertype).hide();
		jQuery("#listing-mais-"+type).show();			
	
	}
	
	this.getFoto = function(obj,f,leg)  {
		
		jQuery("#listing-fotos a").removeClass("selected");
		
		var im = new Image();
		im.src = "/images/480x360/"+f;
		
		jQuery("#container-foto img")[0].src = img.src;
		jQuery("#container-foto img")[0].src = im.src;
		jQuery("#container-foto p").html(leg);
		
		jQuery("#"+obj).addClass("selected");
	
	}
	
	this.addToFavorite = function() {
		
		var url = "http://www.noticiasdeurucui.com.br";
		var title = "Portal Notícias de Uruçui";
		
		if (window.sidebar)
		{
			window.sidebar.addPanel(title, url , "");

		} else if (window.opera && window.print)
		{
			mbm = document.createElement('a');
			mbm.setAttribute('rel', 'sidebar');
			mbm.setAttribute('href', url);
			mbm.setAttribute('title', title);
			mbm.click();

		} else if (document.all)
		{
			window.external.AddFavorite(url, title);
		}

	
	}
	

}

var App = new ApplicationManager();