// JavaScript Document

$( document ).ready(function() {
	
	var PATH_ROOT=$('#PATH_ROOT').val();
	var LANG=$('#LANG').val();
	
	// resize
	$(window).load(function(e) {
    	resize();
	});	
	resize();
	$(window).resize(resize);
	function resize(){
		var screen_width=$(window).width();
		var adver_main_height=$('#adver_main').height();
		if(adver_main_height>0){
			$('#adver_video').height(adver_main_height);
		}
	}	
	//resize
	
	//scrollTop
	$(window).scroll(function(){ 
		if($(window).scrollTop() > 500) {
			$('#uiScrollTop').show();
		} else {
			$('#uiScrollTop').hide();
		}
	});
	$('#uiScrollTop').click(function(){
		$('html').animate({scrollTop:0}, 'slow');//IE, FF
    	$('body').animate({scrollTop:0}, 'slow');//chrome, don't know if Safari works
	});
	//scrollTop
	
	//popUp
	$('#uiPop').click(function(){
		$(this).hide();
	});
	//popUp
	
	//lightbox
	$(document).delegate('*[data-toggle="lightbox"]:not([data-gallery="navigateTo"])', 'click', function(event) {
		event.preventDefault();
		return $(this).ekkoLightbox({
			onShown: function() {
				if (window.console) {
					return console.log('');
				}
			},
			onNavigate: function(direction, itemIndex) {
				if (window.console) {
					return console.log('Navigating '+direction+'. Current item: '+itemIndex);
				}
			}
		});
	});
	
	
	//calendar	
	$('#calendar').fullCalendar({
		header: {
			left: 'prev,next today',
			center: 'title',
			right: 'month,agendaWeek,agendaDay',			
		},
		displayEventTime : false,
		/*eventLimit: true,*/
		events: PATH_ROOT + 'exe/json_calendar.php',
		loading: function(bool) {
		  if (bool){
			 //alert('I am populating the calendar with events');
		  }
		  else{
			var html="";
			$('#calendar').fullCalendar('clientEvents', function(ev) {
			 	html+='<h4 class="margin-none">'+ev.title+'</h4><p class="margin-none">'+ev.text+'</p><hr>';				
			});
			$('#events').html(html);
		  }
	   }, 
		eventClick: function(calEvent, jsEvent, view) {
			/*
			$('#uiPop').dialog({title:calEvent.title});
			$('#uiPop').html(calEvent.text);
			$('#uiPop').dialog("open");
			*/
        	//alert('Event: ' + calEvent.title);
		},
		
		eventMouseover: function(event, jsEvent, view) {
    		$('.fc-content', this).append('<div id="'+event.id+'" class="hover-end">'+event.text+'</div>');
		},
		eventMouseout: function(event, jsEvent, view) {
    		$('#'+event.id).remove();
		},
		
	});
	
});