
YAHOO.namespace("example.calendar");

    YAHOO.example.calendar.init = function( schedule ) {
		
		
		
		
		
		
		
		//---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
        var navConfig = {
            strings : {
                month: "Escolha um mês",
                year: "Insira um ano",
                submit: "OK",
                cancel: "Cancelar",
                invalidYear: "Por favor insira um ano válido"
            },
            monthFormat: YAHOO.widget.Calendar.LONG,
            initialFocus: "ano"
        };
		//---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
        YAHOO.example.calendar.cal2 = new YAHOO.widget.Calendar("cal2Container", {
        	navigator: navConfig,
        	start_weekday: 1,
        	LOCALE_WEEKDAYS:"medium"
        });
        
		//---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
		// Correct formats for Brazil: dd/mm/yyyy
		YAHOO.example.calendar.cal2.cfg.setProperty("DATE_FIELD_DELIMITER", "/");  
		YAHOO.example.calendar.cal2.cfg.setProperty("MDY_DAY_POSITION", 1); 
		YAHOO.example.calendar.cal2.cfg.setProperty("MDY_MONTH_POSITION", 2); 
		YAHOO.example.calendar.cal2.cfg.setProperty("MDY_YEAR_POSITION", 3); 			 
		YAHOO.example.calendar.cal2.cfg.setProperty("MD_DAY_POSITION", 1); 
		YAHOO.example.calendar.cal2.cfg.setProperty("MD_MONTH_POSITION", 2); 
		YAHOO.example.calendar.cal2.cfg.setProperty("MONTHS_SHORT",   ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]); 
		YAHOO.example.calendar.cal2.cfg.setProperty("MONTHS_LONG",    ["Janeiro", "Fevereiro", "Mar&ccedil;o", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]); 
		YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_1CHAR", ["D", "S", "T", "Q", "Q", "S", "S"]); 
		YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_SHORT", ["Do", "Se", "Te", "Qu", "Qu", "Se", "Sa"]); 
		YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_MEDIUM",["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"]); 
		YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_LONG",  ["Domingo", "Segunda", "Ter&ccedil;a", "Quarta", "Quinta", "Sexta", "Sabado"]); 
		//---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
		//---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
        YAHOO.example.calendar.events = function(workingDate, cell) {
			YAHOO.util.Dom.addClass(cell, "event");			
			cell.innerHTML = '<div class="selector">'+this.buildDayLabel(workingDate)+'<div class="foo"></div></div>';				
			return YAHOO.widget.Calendar.STOP_RENDER;
		}
		
		var yahooSchedule = "";
		$.each( schedule , function( key , value ){
			 yahooSchedule += value+',';	 
		});
		
		
		var myChangePageHandler = function(type,args,obj) {
			scheduleFeatures( schedule );
		};
		
		
		//YAHOO.example.calendar.cal2.changePageEvent.subscribe(myChangePageHandler, YAHOO.example.calendar.cal2, true);
		YAHOO.example.calendar.cal2.renderEvent.subscribe(myChangePageHandler, YAHOO.example.calendar.cal2, true);
		
		YAHOO.example.calendar.cal2.addRenderer(yahooSchedule, YAHOO.example.calendar.events);
		
		YAHOO.example.calendar.cal2.render();
		
		scheduleFeatures( schedule );
		
		//---------------------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------------------
		function scheduleFeatures ( schedule ) {
			
			
			$.each( schedule , function( key , value ){				
				var date = value.split("/");				
				var dateClass = ".y"+date[2]+" .m"+date[1]+" .d"+date[0];
				
				$('.foo',dateClass).append("<span class='bar click-"+key+"'></span>");
				
				$(".click-"+key).bind("click",function(){
					abrirAgenda(key);
				});
				
				//$('.bar',dateClass).eq(0).css('display','none');

			});

			// adicionando a busca	
			$('#cal2Container').css('position','relative');
			if (_IS_FILTER_SEARCH_CALENDAR_SELECTED == "feiras"){
				$('#cal2Container').append("<div class='calnavbusca'><p>Buscar</p> <select name='busca' onchange='window.location=_SECTION_URL+\"&filtro=\"+this.value'><option value='feiras' selected='selected'>Feiras</option><option value='cursos'>Cursos</option></select><a href='#'><img src='"+ACTIVE_TEMPLATE_VIRTUAL_PATH+"image/buttons/bt_ok.gif' border='0' /></a></div>");
			} 
			else{
				if (_IS_FILTER_SEARCH_CALENDAR_SELECTED == "cursos"){
					$('#cal2Container').append("<div class='calnavbusca'><p>Buscar</p> <select name='busca' onchange='window.location=_SECTION_URL+\"&filtro=\"+this.value'></option><option value='feiras'>Feiras</option><option value='cursos' selected='selected'>Cursos</option></select><a href='#'><img src='"+ACTIVE_TEMPLATE_VIRTUAL_PATH+"image/buttons/bt_ok.gif' border='0' /></a></div>");
				}
				else{
					$('#cal2Container').append("<div class='calnavbusca'><p>Buscar</p> <select name='busca' onchange='window.location=_SECTION_URL+\"&filtro=\"+this.value'><option value=''></option><option value='feiras'>Feiras</option><option value='cursos'>Cursos</option></select><a href='#'><img src='"+ACTIVE_TEMPLATE_VIRTUAL_PATH+"image/buttons/bt_ok.gif' border='0' /></a></div>");
				}
			}
			
		}
    }
