$(document).ready(function(){
	sc.menu();

	sc.app.academico.init();

});


var sc = {
	menu:function(){
		$('#submenu-produto').css({'height':0,'opacity':0});
		if(currentArea == '5' || currentArea == '26' || currentArea == '10' || currentArea == '27' || currentArea == '11' || currentAreaSup == '10' || currentAreaSup == '11'|| currentAreaSup == '26' || currentAreaSup == '27'){
			setTimeout(subProdutos,500);
		}
		$('#fonte_menos').css('cursor','pointer').bind('click',function(){
			var txt_min = 8, txt_size = parseFloat($("div[class='txtCinza']").css('font-size').replace('px',''));
			var tit_min = 10, tit_size = parseFloat($('#titAreas').css('font-size').replace('px',''));
			
			txt_size -= 1;
			tit_size -= 1;
			if( txt_size < txt_min ){txt_size = txt_min}
			if( tit_size < tit_min ){tit_size = tit_min}
						
			$('#titAreas').css('font-size',tit_size);
			$("div[class='txtCinza']").css('font-size',txt_size);
			$("a[class='linkAzul']").css('font-size',txt_size);
		});
		$('#fonte_mais').css('cursor','pointer').bind('click',function(){		    
			var txt_max = 14, txt_size = parseFloat($("div[class='txtCinza']").css('font-size').replace('px',''));
			var tit_max = 16, tit_size = parseFloat($('#titAreas').css('font-size').replace('px',''));
			
			txt_size += 1;
			tit_size += 1;
			if( txt_size > txt_max ){txt_size = txt_max}
			if( tit_size > tit_max ){tit_size = tit_max}
						
			$('#titAreas').css('font-size',tit_size);
			$("div[class='txtCinza']").css('font-size',txt_size);
			$("a[class='linkAzul']").css('font-size',txt_size);
		});		
	},
	app:{
		init:function(app){
			if($('#app-overlay').size() == 0){
				$('<div id="app-overlay">').css({'opacity':0.8}).appendTo($('body'));
			}else{
				$('#app-overlay').show();
			}
			if(sc.app.window == undefined){
				sc.app.window = $('<div id="app-window">').appendTo($('body'));
				
				var h = $('<div>').addClass('header').appendTo(sc.app.window);
				sc.app.title = $('<div>').html('SCAC').addClass('title').appendTo(h);
				sc.app.close = $('<div>').html('X fechar').addClass('close').bind('click',sc.app.cancel).appendTo(h);
				
				sc.app.content = $('<div>').html('SE VOCE ESTA LENDO ESTE TEXTO, ALGO ESTA ERRADO').addClass('content').appendTo(sc.app.window);
				
				var f = $('<div>').addClass('footer').appendTo(sc.app.window);
				sc.app.prev = $('<div>').addClass('prev').appendTo(f);
				sc.app.next = $('<div>').addClass('next').appendTo(f);
			}else{
				sc.app.window.show();
			}
			sc.app.content.empty();
			
			sc.app[app].init();
		},
		cancel:function(){
			$('#app-window, #app-overlay').hide();
		},
		alert:{
			container:null,
			show:function(title,html,actions){
				var btn = null;
				if(sc.app.alert.container == undefined){
					sc.app.alert.container = $('<div>').addClass('app-alert').appendTo($('body'));
					$('<div>').addClass('app-alert-title').appendTo(sc.app.alert.container);
					$('<div>').addClass('app-alert-content').appendTo(sc.app.alert.container);
					$('<div>').addClass('app-alert-actions').appendTo(sc.app.alert.container);
				}
				sc.app.alert.container.find('.app-alert-title').html(title);
				sc.app.alert.container.find('.app-alert-content').html(html);
				sc.app.alert.container.find('.app-alert-actions').empty();
				$(actions).each(function(){
					btn = $('<input type="button" value="'+ this.label +'">').appendTo(sc.app.alert.container.find('.app-alert-actions'));
					if(typeof this.action == 'function'){
						btn.bind('click',this.action);
					}
				});
				sc.app.alert.container.show();
			},
			hide:function(){
				$('.app-alert').hide();
			}
		},
		getLoading:function(){
			return $.fw.utils.flashEmbed({movie:'/app/img/loading.swf',width:48,height:58,params:{wmode:'transparent'}});
		},
		addMenu:function(mn){
			var ul = $('<ul>').appendTo($('<div>').addClass('app-menu').appendTo(sc.app.content));
			if($.isArray(mn)){
				$(mn).each(function(){
					var li = $('<li>').html(this.label).appendTo(ul);
					if(typeof this.action == 'function'){
						li.bind('click',function(){$(this).parent().find('li.active').removeClass('active'),$(this).addClass('active')}).bind('click',this.action)
					}
					if(this.active){
						li.addClass('active');
					}
				});
			}else if(typeof mn == 'object'){
				$('<li>').addClass('active').html(mn.label).bind('click',mn.action).appendTo(ul);
			}
		},
		addNumMenu:function(mn,target){
			var ul = $('<ul>').appendTo($('<div>').addClass('app-num-menu').appendTo(target));
			if($.isArray(mn)){
				var i = 1;
				$(mn).each(function(){
					var li = $('<li>').css({'background':'url(/app/img/num-'+ i +'.png) no-repeat left center'}).html(this.label).appendTo(ul);
					if(typeof this.action == 'function'){
						li.bind('click',function(){$(this).parent().find('li.active').removeClass('active'),$(this).addClass('active')}).bind('click',this.action)
					}
					if(this.active){
						li.addClass('active');
					}
					i++;
				});
			}else if(typeof mn == 'object'){
				$('<li>').addClass('active').html(mn.label).bind('click',mn.action).appendTo(ul);
			}
		},
		academico:{
			links:[{id:'carga',title:'c&aacute;lculo de carga'}],
			init:function(){
				$('<ul>').appendTo($('#toolbox_4'));
				$(sc.app.academico.links).each(function(){
					$('<li id="app_'+ this.id +'">').html(this.title).bind('click',sc.app.academico.load).appendTo($('#toolbox_4>ul'));
				});
			},
			load:function(){
				app = this.id.replace('app_','');
				$.getScript('/app/'+ app +'/?acao=getScript',function(){
					sc.app.init(app);
				});
			}
		}
	}
}
