
jQuery(document).ready(function(){

	jQuery("#textfield").focus();
	//jQuery('#textfield').val('z.B. Bäcker Dresden');

	jQuery("A.toggleBusinesses").click(function(){
        if (jQuery("#branchen").is(":hidden")){
			jQuery("#branchen").slideDown("slow");
		}else{
			jQuery("#branchen").slideUp("slow");
		}
	});

	jQuery("A#toggleReportLink").click(function(){
		if(jQuery("DIV#report").is(":hidden")){
			jQuery("DIV#report").slideDown("slow");
		}else{
			jQuery("DIV#report").slideUp("slow");
		}
	});

    jQuery.ajax({
		type: "POST",
		dataType: 'html',
		global: 'false',
		url: "index.php?eID=nb_leaflet",
		success: function(msg){
			jQuery('#leafletTeaser').html(msg);
		}
	});

	// get rating function
	function getRating(id){
		jQuery.ajax({
			type: "GET",
			url: "/voting.inc.php",
			data: "do=getrate&uid=" + id,
			cache: false,
			async: false,
			success: function(result){
				// apply star rating to element
				jQuery("#current-rating").css({ width: "" + result + "%" });
			},
			error: function(result) {
				alert("some error occured, please try again later");
			}
		});
	}

	// link handler
	jQuery('#ratelinks li a').click(function(){
		jQuery.ajax({
			type: "GET",
			url: "/voting.inc.php",
			data: "rating="+jQuery(this).text()+"&do=rate&uid=854",
			cache: false,
			async: false,
			success: function(result){
				jQuery("#ratelinks").remove();
				getRating(854);
			},
			error: function(result){
				alert("some error occured, please try again later");
			}
		});
	});

});
