$(document).ready(function() {
	$("input[type=text]:first").focus();
	$("input").focus(function() {
		$(this).css("border","1px solid #7497f0");
	});
	$("input").blur(function() {
		$("input").css("border","1px solid #CCCCCC");
	});
});

function checkAvailable(str) {
	$("#wishwordError").hide('slow');
	if(str.length > 2){
		$.post(apiPath+"check-available.php", {code:str, type:"data"}, handle_checkAvailable);
	}else{
		txt = "wishword should be longer than 3 characters!";
		cls="inputError";
		$("#wishwordError").html(txt);
		$("#wishwordError").attr("class",cls);
		$("#wishwordError").show('slow');
		$("#wishword").focus();
	}
}

function handle_checkAvailable(available) {
	var txt =" ";
	if(available == 0) {
		txt+= "Not available, please try another!";
		cls="inputError";
	}else{
		txt+= "Available!";
		cls="inputSuccess";
	}
	$("#wishwordError").html(txt);
	$("#wishwordError").attr("class",cls);
	$("#wishwordError").show('slow');
	$("#wishword").focus();
}

function addToFavorites(url, title){
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
	}
}

function shareToggle(i, hide) {
	if(hide == 1) i="";
	$("#addto").html(i);
}

function toggleBlock(blockid) {
	$("#"+blockid).toggle("slow");
	$("#"+blockid+"mini").toggle();
	$("#"+blockid+"maxi").toggle();
	return false;
}

function toggleDetails(blockid) {
	var curr = $("#"+blockid).html();
	if(curr=="+ more"){
		$("#"+blockid).html("- more");
		$("#real-"+blockid).toggle();		
		$("#short-"+blockid).toggle();
	}else{
		$("#"+blockid).html("+ more");
		$("#short-"+blockid).toggle();
		$("#real-"+blockid).toggle();		
	}
		
	return false;
}

function showAll(a) {
	var i=0;
	for(i=0;i < a.length; i++){
		$("#"+a[i]).show("slow");
		$("#"+a[i]+"mini").hide();
		$("#"+a[i]+"maxi").show();
	}
	return false;
}

function hideAll(a) {
	var i=0;
	for(i=0;i < a.length; i++){
		$("#"+a[i]).hide("slow");
		$("#"+a[i]+"mini").show();
		$("#"+a[i]+"maxi").hide();
	}
	return false;
}
