skatic.appliedAjaxMethods.getSmallCalendar = function(monthNumber, year) {
	$.ajax({
		'url':'/gigs/smallCalendar/'+monthNumber+'/'+year+'/?locationChanged=false',
		'type':'GET',
		'success':function(response){
			$('#smallcalendar').html(response);
		},
		'cache':true
	});
	
	return false;
};

skatic.appliedAjaxMethods.getBigCalendar = function(monthNumber, year) {
	$.ajax({
		'url':'/gigs/bigCalendar/'+monthNumber+'/'+year+'/?locationChanged=false',
		'type':'GET',
		'success':function(response){
			$('div.widen').html(response);
		},
		'cache':true
	});

	return false;
};

skatic.appliedAjaxMethods.getRecentlyAddedSongs = function(link) {
	$.ajax({
		'url':'/songs/recentlyAdded/?locationChanged=false',
		'type':'GET',
		'cache':false,
		'success':function(response){
			var li1 = $(link).parents('li');
			var li2 = li1.prev('li')

			$(link).addClass('on');
			li2.find('a').removeClass('on');

			var divOnIcon = li2.find('div');
			li1.append(divOnIcon.clone());
			divOnIcon.remove();

			$('div.topten').eq(0).find('div.toplist').html(response);
		}
	});

	return false;
};

skatic.appliedAjaxMethods.getRecentlyAddedUsersWithSongs = function(link) {
	$.ajax({
		'url':'/users/recentlyAddedWithSongs/?locationChanged=false',
		'type':'GET',
		'cache':false,
		'success':function(response){
			var li1 = $(link).parents('li');
			var li2 = li1.next('li')
			
			$(link).addClass('on');
			li2.find('a').removeClass('on');
			
			var divOnIcon = li2.find('div');
			li1.append(divOnIcon.clone());
			divOnIcon.remove();
			
			$('div.topten').eq(0).find('div.toplist').html(response);
		}
	});
	
	return false;
};

skatic.appliedAjaxMethods.getTopArtists = function(link) {
	$.ajax({
		'url':'/users/homepageTop/?locationChanged=false',
		'type':'GET',
		'cache':false,
		'success':function(response){
			var li1 = $(link).parents('li');
			var li2 = li1.next('li')
			
			$(link).addClass('on');
			li2.find('a').removeClass('on');
			
			var divOnIcon = li2.find('div');
			li1.append(divOnIcon.clone());
			divOnIcon.remove();
			
			$('div.topten').eq(1).find('div.toplist').html(response);
		}
	});
	
	return false;
};

skatic.appliedAjaxMethods.getTopSongs = function(link) {
	$.ajax({
		'url':'/songs/homepageTop/?locationChanged=false',
		'type':'GET',
		'cache':false,
		'success':function(response){
			var li1 = $(link).parents('li');
			var li2 = li1.prev('li')
			
			$(link).addClass('on');
			li2.find('a').removeClass('on');
			
			var divOnIcon = li2.find('div');
			li1.append(divOnIcon.clone());
			divOnIcon.remove();
			
			$('div.topten').eq(1).find('div.toplist').html(response);
		}
	});
	
	return false;
};

skatic.appliedAjaxMethods.thumbUpDown = function(direction, link) {
	//1 - direction
	var contentType = link.id.split('_')[2];
	var parentId = link.id.split('_')[3];
	
	$.ajax({
		'url':'/thumbups/'+direction+'/'+contentType+'/'+parentId+'/?locationChanged=false',
		'type':'POST',
		'cache':false,
		'success':function(response){
			if (typeof response.result != 'undefined' && response.result == 'success') {
				var tuCountSpan = $('#thumbups_'+direction+'_'+contentType+'_'+parentId);
				var count = parseInt(tuCountSpan.html());
				tuCountSpan.html(count + 1);
			}
			
			skatic.ajaxResponse(response);
//			$(link).replaceWith('thumbed');
		},
		'dataType':'json'
	});
	
	return false;
};

skatic.appliedAjaxMethods.thumbUp = function(link) {
	return skatic.appliedAjaxMethods.thumbUpDown('up', link);
};
skatic.appliedAjaxMethods.thumbDown = function(link) {
	return skatic.appliedAjaxMethods.thumbUpDown('down', link);
};

skatic.appliedAjaxMethods.musicFilterByArtist = function(selectedArtist) {
	getMusicPage({'type':'artist', 'value':selectedArtist.label, 'label':selectedArtist.value});
};
skatic.appliedAjaxMethods.musicFilterByTrack = function(selectedSong) {
	getMusicPage({'type':'song', 'value':selectedSong.label, 'label':selectedSong.value});
};
skatic.appliedAjaxMethods.musicFilterByAlbum = function(selectedAlbum) {
	getMusicPage({'type':'album', 'value':selectedAlbum.label, 'label':selectedAlbum.value});
};

skatic.appliedAjaxMethods.getUnreadPmCount = function(needTimeout){
	if (!skatic.user.isLoggedIn()) {
		return false;
	}
	
	//default true
	if (typeof needTimeout == 'undefined') {
		var needTimeout = true;
	}
	
	

	$.ajax({
		'url':'/messages/getUnreadPmCount/?locationChanged=false',
		'type':'GET',
		'success':function(response){
			if (parseInt(response.count) > 0) {
				$('#profilemenu_expanded .messages:first a:first').html(_('Messages (%d)').replace('%d', parseInt(response.count)));
				$('#profilemenu .newmail').show();
			} else {
				$('#profilemenu_expanded .messages:first a:first').html(_('Messages'));
				$('#profilemenu .newmail').hide();
			}
			if (needTimeout) {
				setTimeout(skatic.appliedAjaxMethods.getUnreadPmCount, 120000); //2 mins
			}
		},
		'cache':false,
		'dataType':'json',
		'global':false
	});
};

skatic.appliedAjaxMethods.equipmentExpandList = function(url, link) {
	if ($(link).next().is('ul')) {
		if ($(link).next().is(':visible')) {
			$(link).next().hide();
		} else {
			$(link).next().show();
		}
		return false;
	}
	
	//var url = $(link).attr('href').replace('#', '');
	if (url.charAt(url.length - 1) != '/') {
		url += '/';
	}
	url += 'render:list/?locationChanged=false';
	
	$.ajax({
		'url':url,
		'type':'GET',
		'cache':true,
		'success':function(response) {
			$(link).after(response);
		}
	});
	
	return false;	
};

skatic.appliedAjaxMethods.getPlaylistRecords = function(link) {
	var playlistId = link.id.split('_')[1];
	
	$.ajax({
		'type':'GET',
		'url':'/playlists/playlistRecords/'+playlistId+'/?locationChanged=false',
		'success':function(response){
			$('#playlist_dd_'+playlistId).html(response).show();
			setTimeout(function(){
				skatic.playlists.doOpenClosePlaylist(link);
			}, 150);
		}
	});
		
	return false;
};


skatic.appliedAjaxMethods.setLocale = function(select) {
	//?to='+skatic.url.removeGetParams(skatic.ajax.current)
	skatic.ajax.loadPage('/profiles/saveLocale/'+$(select).val()+'/');
};



