$(function(){
	//SEARCH TAB SELECTED
	$(".winnersSearchNav li a").click(function () {
		var panel = $(this).attr('class') 
		$(".winnersSearchNav li").removeClass('selected');
		$(".twoColumnSmall .slide").hide();
		$(this).parent('li').addClass('selected');
		$('.'+ panel +'SearchHolder').show();
		return false;
	});
	

	//REGION SEARCH POP-UPS
	$("#m_map area").click(function () {
		var areaName = $(this).attr('class');
		$(".mapSearchHolder div").fadeOut();	
		$(".mapSearchHolder div." + areaName).fadeIn();		
		$("img.backgroundMap").attr('src', 'images/maps/map-' + areaName + '.gif');	
		return false;
	});


	//REGION POP-UPS CLOSE BTN
	$("div.mapPopUp .close").click(function () {
		$(".mapSearchHolder div").fadeOut();
		$("img.backgroundMap").attr('src', 'images/maps/map.gif');			
		return false;
	});
});

function confirmation() {
	var answer = confirm("Are you sure?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}

function wpBlog(url,action,id) {
	$.get(url, function(response){
		console.log(response);
		var data = eval('(' + response + ')');
		console.log(data);
		if (action =='create') {
			if (data.errors == ''){
				$("#createBlogLnk_" + id).hide();
				$("#visitBlogLnk_" + id).show();
				$("#deleteBlogLnk_" + id).show();
			} else {
				alert(data.errors);
			}	
		} else if (action =='disable') {
			if (data.errors == ''){
				$("#createBlogLnk_" + id).show();
				$("#visitBlogLnk_" + id).hide();
				$("#deleteBlogLnk_" + id).hide();
			} else {
				alert(data.errors);
			}
		}
	});
}

function showAll(el){
	$("#categorySearch li").each(function(){
		if ($(this).attr('class') == 'selected'){
			group = $(this).attr('id').replace("_li","");
		}
	});
	i=0;
	$("#checkboxes-categories #fieldset-" + group + " input[type='checkbox']").each(function(){
		$(this).attr('checked', el.checked);
		i++;
	});
	updateCategoryMax (group,i);
}
function show(id,liClicked,aClicked) {
	for (var i=0;i<subForms.length;i++) {
		if(subForms[i] + '-element' != id) {
			$('#' + subForms[i] + '-element').hide();
			$('#' + subForms[i] + '_li').removeClass('selected');
		}
	}
	for (var i=0;i<letters.length;i++) {
		if (letters[i] +'_letter_lnk' != aClicked){
			$("#" + letters[i] +'_letter_lnk').removeClass('selected');
		}
	}
	if (aClicked !='') {
		$("#" + aClicked).addClass('selected');	
	}
	$("#" + id).show();
	if (liClicked !='') {
		$("#" + liClicked).addClass('selected');
	}
	
}

function toggleSearch(show,hide){
	$("#"+show).show();
	$("#"+hide).hide();
	$("#searchedWhat").val(show);
	$("#" + show + "Lnk").addClass('show');
	$("#" + hide + "Lnk").removeClass('show');
}

function updateCategoryMax(category,number) {
	current = $("a." + category + " span").html();
	if (current =='' || current =='&nbsp;') {
		$("a." + category + " span").html('(' + number + ')');
	} else {
		$("a." + category + " span").html('');
	}
}
function updateCategoryNumber(category,el){
	current = $("a." + category + " span").html();
	if (current =='') {
		if (el.checked === true) {
			$("a." + category + " span").html('(1)');
		}
	} else if (current !='') {
		current = current.replace('(','');
		current = current.replace(')','');
		if (el.checked === true) {
			current++;
			newNumber = '(' + current + ')';
		} else {
			current--;
			newNumber = '(' + current + ')';
			if (current ==0) {
				newNumber = '';
			}
		}
		$("a." + category + " span").html(newNumber);
	}
}