// JavaScript Document

/**
 * Slide pics within a tabs() container 
 *
 * @params string direction
 * @return none
 */
var fotoSliderOffset = 0;
var fotoSliderSteps = 462;
var fotoSliderString = "";
function slidePic(direction) {
	var max = $("#foto_Inner").width();
	if (direction == "next" && ((fotoSliderOffset*-1)+fotoSliderSteps) < max){
		fotoSliderOffset = fotoSliderOffset - fotoSliderSteps;
	} 
	else if (direction == "prev" && fotoSliderOffset < 0) {
		fotoSliderOffset = fotoSliderOffset + fotoSliderSteps;
	}
	fotoSliderString = fotoSliderOffset + " 1";
	$("#foto_Inner").position({
		my: "left",
		at: "left",
		of: "#foto_Outer",
		offset: fotoSliderString,
		using: function(to) {$(this).animate(to);},
		collision: "none"
	});
	// Toggle buttons
	if (direction == "next" && fotoSliderOffset < 0) {
		$("#foto_Prev").switchClass("slider_hidden", "slider_show", 300);
	}
	else if (direction == "prev" && fotoSliderOffset >= 0) {
		$("#foto_Prev").switchClass("slider_show", "slider_hidden", 300);
	}
	if (direction == "next" && ((fotoSliderOffset*-1)+fotoSliderSteps) >= max) {
		$("#foto_Next").switchClass("slider_show", "slider_hidden", 300);
	}
	else if (direction == "prev" && ((fotoSliderOffset*-1)+fotoSliderSteps) < max) {
		$("#foto_Next").switchClass("slider_hidden", "slider_show", 300);
	}
}

/**
 * Submit a comment form thru AJAX 
 *
 * @params none
 * @return bool false (prevents form submission)
 */
function ajax_submit_comment() {
	var id = $(this).attr("id");
	//alert ($("#" + id).find('input[name="comment_email"]').val());
	var reply = $(this).serialize();  
	var loading = '<img src="/shared/images/loading.gif" width="20" height="20" style="margin-left:48%;margin-top:130px;margin-bottom:150px" />';
	$.ajax({
		type: "POST",
		url: "/shared/files/ajax_comments.php",
		dataType: "html",
		data: reply,
		timeout: 10000,
		beforeSend: function(){
			$("#show_" + id).html(loading);
		},
		success: function(response){
			$("#show_" + id).html(response);
		},
		error: function(){
			$("#show_" + id).html("Fehler!");
		}
	}); // end ajax
	return false;
}

/**
 * Submit rating form thru AJAX 
 *
 * @params none
 * @return none
 */
function ajax_submit_rating(){
	var id = $(this).attr("id");
	var rate = "id=" + id + "&val=" + $(this).val();
	var loading = '<img src="/shared/images/loading.gif" width="20" height="20" />';
	$.ajax({
		type: "GET",
		url: "/shared/files/ajax_rating.php",
		dataType: "json",
		data: rate,
		timeout: 10000,
		beforeSend: function(){
			$("#rating_value_" + id).html(loading);
		},
		success: function(response){
			$("#rating_value_" + id).html(response.average + " Punkte");
		},
		error: function(){
			$("#rating_value_" + id).html("Fehler!");
		}
	}); // end ajax        
}

// CUT FROM DOC READY IN HEADER
/*
$("#comment_subscription").parent().hide();
$("#comment_email").bind("change", function(){
	$("#comment_subscription").parent().show();
});
*/
