$(document).ready(function(){
	$('#jsFallback').hide();
	$('#playSong').stop().animate({opacity:0.3});
	$('#playSong').click(function(event){
		event.preventDefault();
		$.fn.soundPlay({url:(url+'/js/bsasplaya_radiomix.mp3'),playerId:'bsasplaya_song',command:'play'});
		$('#stopSong').stop().animate({opacity:0.3});
		$(this).stop().animate({opacity:1})});
	$('#stopSong').click(function(event){
		event.preventDefault();
		$.fn.soundPlay({
			playerId:'bsasplaya_song',command:'stop'
			});
		$('#playSong').stop().animate({opacity:0.3});
		$(this).stop().animate({opacity:1});
		});
	var overlay='<div id="lBox"></div>';
	$('#beach').append(overlay);
	$('#lBox').hide();
	$('.importantPointer, #helpPages li a').click(function(){
		$('#lBox').toggle();
		});
	$('#helpPages li a').click(function(event){
		event.preventDefault();
		var getPageBubble=$(this).attr('rel');
		var getPageBubblePos=$('#'+getPageBubble).css('left');
		$('#'+getPageBubble+' .post').fadeIn('slow');
		$('.importantPointer').hide();
		});
	$('.post').hide();
	$('.infoPointer').not('.importantPointer').stop().animate({opacity:0.5});
	$('.infoPointer').not('.importantPointer').hover(function(){
		$(this).stop().animate({opacity:1},700);
		},function(){
			$(this).stop().animate({opacity:0.5},700);
			});
	$('.smallBubble .infoPointer').click(function(event){
		event.preventDefault();
		var getPointerBox=$(this).parent().attr('id');
		$('#'+getPointerBox+' .post').toggle('slow',function(){
			$('.post').not('#'+getPointerBox+' .post').fadeOut('slow');
			});
		$(this).toggleClass('activePointer');
		$('#'+getPointerBox).toggleClass('activeBubble');
		$('#lBox').hide();
		});
	$('.importantPointer').click(function(event){
		event.preventDefault();
		var getPointerBox=$(this).parent().attr('id');
		$('#'+getPointerBox+' .post').fadeIn('slow');
		$('.post').not('#'+getPointerBox+' .post').fadeOut('slow');
		$('.importantPointer').hide();
		});
	$('.closeBtn').click(function(event){
		event.preventDefault();
		$(this).parent('.post').fadeOut('slow');
		$('.importantPointer').show();
		$('#lBox').hide();
		});
	var todayDate=new Date();
	var dia=todayDate.getDate();
	var mes=todayDate.getMonth()+1;
	eventDate(dia+'/'+mes);
	$('.eventDate a').each(function(){
		$(this).click(function(event){
			var selectedDate=$(this).parent('td');
			$(selectedDate).addClass('selectedDate');
			$('.dateCalendar tbody td').not(selectedDate).removeClass('selectedDate');
			event.preventDefault();
			eventDate($(this).attr('rel'));
			});
		});
	function eventDate(daymonthvar){
		$('#mainCalendar-holder th:first').addClass('act');
		$('#mainCalendar table tbody').html('<tr><td class="noneEvent" colspan="8"><img src="'+url+'/images/icons/loading.gif" /></td></tr>');
		$.getJSON(url+"/ssi/ajax-calendar.php?",{daymonth:daymonthvar},function(data){
		/*$.ajax({url+"/ssi/ajax-calendar.php?",datatype:'json',data:{daymont:daymonthvar},success:function(data){*/
			$('#mainCalendar table tbody').html('');
			var appendString='';
			if(data!==null){
				$.each(data,function(i,item){
					appendString='';
					appendString+='<tr><td class="act activity-'+item.actividadEvento+'"></td><td>'+item.lugarEvento+'</td><td>'+item.tituloEvento+'</td><td>'+item.artistaEvento+'</td><td>'+item.fechaEventoCompCom+'</td><td>'+item.horaEventoComienzo+':'+item.minutoEventoComienzo+'</td><td>'+item.horaEventoFin+':'+item.minutoEventoFin+'</td><td class="lastTD"><div class="rememberHolder"><a class="subscribeBtn" href="#">Recordarme</a>';
					if(logd==0){appendString+='<div class="rememberBubble"><p>Debes <a href="'+urlFull+'/wp-login.php?redirect_to='+urlFull+'">ingresar</a> para utilizar los recordatorios.</p></div>';}else{appendString+='<div class="rememberBubble"><form action="" id="validate"><input type="text" class="required email" name="reminderEmail" value="Ingrese su email aquÃ�ï¿½Ã¯Â¿Â½Ã�Â¯Ã�Â¿Ã�Â½Ã�ï¿½Ã�Â¯Ã�ï¿½Ã�Â¿Ã�ï¿½Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â¯Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â¿Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�Â¯Ã�Â¿Ã�Â½Ã�ï¿½Ã�Â¯Ã�ï¿½Ã�Â¿Ã�ï¿½Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�Â¯Ã�Â¿Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â­" /><input name="reminderTime" type="radio" class="radio" value="1" checked="checked" /><span>24hs antes</span><input name="reminderTime" class="radio" type="radio" value="2" /><span>48hs antes</span><button type="submit">Aceptar</button><input type="hidden" name="reminderID" value="'+item.ID+'" /></form></div>';
					}
appendString+='</div></td></tr>';
$('#mainCalendar table tbody').append(appendString);
});
				$('.subscribeBtn').stop().animate({opacity:0.4});
				$('.subscribeBtn').hover(function(){
					$(this).stop().animate({opacity:1});
					},
					function(){
						$(this).stop().animate({opacity:0.4});
						});
				$("form").submit(function(){
					return false;
					});
				$('.subscribeBtn').click(function(){
					$(this).next('.rememberBubble').toggle();
					});
				$('.rememberBubble button').click(function(){
					procesarRecordatorio($(this).siblings('input[name=reminderID]').val(),
					$(this).siblings('input[name=reminderEmail]').val(),
					$(this).siblings('input[name=reminderTime]').val(),
					daymonthvar);
					});
				$('#mainCalendar tbody tr:odd').addClass('zebra');
				$('#mainCalendar h3 strong').html(daymonthvar+'/2012');
				}else{
					$('#mainCalendar table tbody').append('<tr><td class="noneEvent" colspan="8">No hay ninguna actividad para este dÃ�ï¿½Ã¯Â¿Â½Ã�Â¯Ã�Â¿Ã�Â½Ã�ï¿½Ã�Â¯Ã�ï¿½Ã�Â¿Ã�ï¿½Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â¯Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â¿Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�Â¯Ã�Â¿Ã�Â½Ã�ï¿½Ã�Â¯Ã�ï¿½Ã�Â¿Ã�ï¿½Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�Â¯Ã�Â¿Ã�Â½Ã�ï¿½Ã¯Â¿Â½Ã�ï¿½Ã�Â­a.</td></tr>');
					}
					});
		}
function procesarRecordatorio(id,email,tipo,diames){
	var msjBox=$('.rememberBubble button');
	$.post(url+"/ssi/save-reminder.php",{
		idRem:id,emailRem:email,tipoRem:tipo,diamesRem:diames
		},
		function(data){
			if(data.trim()=='ok'){
				msjBox.parents('.rememberBubble').addClass('reminderOk').html('<p>Se ha creado el recordatorio satisfactoriamente.</p>');
				}else{
					msjBox.parents('.rememberBubble').addClass('reminderError').html('<p>'+data+'</p>');
					}
					});
	}
	loadComments();
	setInterval(loadComments,20000);
	function loadComments(){
		$('.commentList').html('');
		$.getJSON(url+"/ssi/bubble-comment.php",
		function(data){
			if(data!==null){
				$.each(data,function(i,item){
					$('.commentList').append('<li class="'+item.classes+'" id="comment-'+item.ID+'"><div class="com-avatar">'+item.avatar+'</div><div class="com-content"><div class="com-author"><p><strong>'+item.quienDijo+'</strong> <em>dijo:</em></p></div><div class="com-info"><div class="com-text">'+item.comentario+'</div></div></div></li>').hide().fadeIn(600);
					});
				}
				});
		}
		$('#bubbleId-61 .infoPointer, #helpPages li a[rel="bubbleId-61"]').click(function(){
			$.getJSON("http://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key=ead86f86363925e0505c2be440aebaaa&user_id=45097201@N05&per_page=10&page=1&format=json&jsoncallback=?",function(json){
				$('#photoSlider ul').html('');
				$.each(json.photos.photo,function(i,item){
					$('#photoSlider ul').append('<li><img src="http://farm'+item.farm+'.static.flickr.com/'+item.server+'/'+item.id+'_'+item.secret+'_z.jpg" alt="" /></li>').hide().fadeIn(600);
					});
				$('#photoSlider ul').simpleScroller();
				});
			});
		});
