function ApplicationController() {

	this.cachealbum = "";
	this.carousel = false;

	this.showModalInstitucional = function(url) {
	
		this.lockScreen({width:"644px",height:"451px"});
		
		$.get(url, function(data){
			$("#ajaxresponse").html(data);
		  	App.prepareShow('644px','451px');
		});
		
	}
	
	this.showModalAlbum = function(url) {
	
		this.lockScreen({width:"644px",height:"451px"});
		
		this.carousel = true;
		
		$.get(url, function(data){
			$("#ajaxresponse").html(data);
		  	App.prepareShow('644px','451px');			
		});
		
	}
	
	this.showModalFotos = function(url) {
	
		this.cachealbum = $("#modal_content").html();
		
		$.get(url, function(data){
			$("#modal_content").html(data);
			$("#mycarousel").jcarousel();
			$('a.closelink').bind("click",function() {
				$("#modal_content").fadeOut("slow",function() {
					
					$("#modal_content").html(App.cachealbum);
					$("#modal_content").fadeIn("slow",function() {
						
						$('a.closelink').bind("click",function() {
							App._finish();									
						});
					
					});
				
				});
			});
		});
		
	}
	
	this.animateAmpliar = function(e) {
		
		if (e.type == "mouseover") {
		
			$(".ampliar a span").animate({
				width: '15px',
				height: '15px'
			},300,function() {
							
				$(".ampliar a span").bind("mouseout",function() {
					
					$(".ampliar a span").animate({
							width: '9px',
							height: '9px'
						},300,function() {
							
							$(".ampliar a span").unbind("mouseout");
						
						});
							
					});
			
			});
		
		} 
	
	}
	
	this.viewFoto = function(src,id)  {
	
		$("#linkimg").attr("href","ampliar.asp?codalb="+id);
		
		$("#zoom_img").removeAttr("src");
		$("#zoom_img").attr("src","imgs/loading_image.gif");
		
		$("#zoom_img").attr("src",src);
	
	}
		
	this.lockScreen = function(options) {
	
		$('body').append($('<div id="modal_screen"></div>')).append($('<div id="modal_container"></div>').append('<div id="modal_content"></div>'));
		
		var arrPageSizes = this.___getPageSize();
		// Style overlay and show it
		$('#modal_screen').css({
			backgroundColor:	"#000",
			display:			"none",
			opacity:			".7",
			filter:				"alpha(opacity=70)",
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).fadeIn();
		
		var arrPageScroll = this.___getPageScroll();
		// Calculate top and left offset for the jquery-lightbox div object and show it
		$('#modal_container').css({
			top:				arrPageScroll[1] + (arrPageSizes[3] / 10),
			left:				arrPageScroll[0]						
		}).show();
		
		$('#modal_screen').click(function() {
			App._finish();									
		});
		
		$('#modal_content').css({backgroundColor:"#FFF"});
		$('#modal_content').html('<strong class="loading"><img src="imgs/loading.gif" alt="Carregando... Aguarde!" /></strong>');
			
					
	}
	
	this.___getPageSize = function() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	}
	
	this.___getPageScroll = function() {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	}
	
	this.prepareShow = function(w,h) {
		
		$('#modal_content').fadeOut("slow",function() {
		
			$('#modal_content').css({
				width:				w,
				height:				h,
				backgroundColor:	"transparent"
			});
			
			$('#modal_content').html("");
			$('#modal_content').append($('#ajaxresponse').html());
			$('#ajaxresponse').html("");
			
			$('#mycarousel').hide();
			
			$('#modal_content').fadeIn("slow", function() {
						
				if (App.carousel) {				
					
					$('#mycarousel').show();
					$('#mycarousel').jcarousel();
					
					App.carousel = false;
					
				}
				
			});			
						
			$('a.closelink').bind("click",function() {
				App._finish();									
			});
			
		});
	
	}
	
	this._finish = function() {
	
		$('#modal_content').remove();
		$('#modal_screen').fadeOut(function() { $('#modal_screen').remove(); });
		$('#modal_container').remove();
		$('embed, object, select').css({ 'visibility' : 'visible' });
	}
	

}

var App = new ApplicationController();