/*******************************************************************************
 * sort of var_dump() for JS
 * requires JQuery
 ******************************************************************************/
var debug = function(elem){
    if (window.console) {
        console.debug(elem);
    }
} //Ende debug
/*******************************************************************************
 * all the things that have to be done on document load
 * requires JQuery 1.3 !!!!!!
 *
 * @return void
 ******************************************************************************/
var duration = 20;
$(function(){
    init();
}); // ende $(document).ready();
/****************************************
 * GOOGLE MAP laden
 ****************************************/
function init(){
    try {
        $("#contentarea .cm_elem").hide();
        $("#contentarea .cm_elem").first().fadeIn("slow").addClass("active");
        $("#horbach-next").click(function(){
            var nextDiv = $("#contentarea .active + .cm_elem");
            if (nextDiv.html()) {
                $("#contentarea .active").fadeOut().removeClass("active");
                nextDiv.fadeIn().addClass("active");
                return false;
            }
            else {
                location.href = $(this).attr("href");
            }
        });
    } 
    catch (e) {
    }
    try {
        $("#horbach-prev").click(function(){
            var prevDiv = $("#contentarea .active").prev();
            if (prevDiv.html()) {
                $("#contentarea .active").fadeOut().removeClass("active");
                prevDiv.fadeIn().addClass("active");
                return false;
            }
            else {
                location.href = $(this).attr("href");
            }
        });
    } 
    catch (e) {
    }
    try {
        $(".opener").click(function(){
            var id = $(this).attr("href").split("#");
            id = id[1];
            $("#contentarea .cm_elem").hide().removeClass("active");
            if ($("#" + id).html()) {
                $("#" + id).fadeIn("slow").addClass("active");
            }
            return false;
        });
    } 
		catch (e) {
    }
    try {
        $("#password2").keyup(function(){
            var pw1 = $("#password").val();
            var pw2 = $(this).val();
            if (pw1.length > 5) {
                $(".hidden").hide();
                if (pw1 != pw2) {
                    $("#password-dismatch-message").show();
                }
            }
            else {
                $(".hidden").hide();
                $("#password-length-message").show();
            }
        });
    } 
    catch (e) {
    }
    try {
        $(".prj-mouse-in").hide();
        $(".prj-mouse-out").mouseover(function(){
            var _idArr = $(this).attr("id").split("-");
            var _id = _idArr[_idArr.length - 1];
            if ($("#prj-mouse-in-" + _id).html()) {
                $(this).fadeOut();
                $("#prj-mouse-in-" + _id).fadeIn();
            }
        });
        $(".prj-mouse-in").mouseout(function(){
            var _idArr = $(this).attr("id").split("-");
            var _id = _idArr[_idArr.length - 1];
            if ($("#prj-mouse-out-" + _id).html()) {
                $(this).fadeOut();
                $("#prj-mouse-out-" + _id).fadeIn();
            }
        });
        var positionInterval = 0;
        $("#projects-right").mouseover(function(eventObject){
            positionInterval = setInterval('moveProjects("right")', duration);
        }).mouseout(function(){
            clearInterval(positionInterval);
        });
        $("#projects-left").mouseover(function(eventObject){
            positionInterval = setInterval('moveProjects("left")', duration);
        }).mouseout(function(){
            clearInterval(positionInterval);
        })
    } 
    catch (e) {
    }
}

/****** Springt gleich auf dsa Projekt (Sino Boeckmann) ******/
  function goToProject(id) {   
    $("#contentarea .cm_elem").hide().removeClass("active");
		id = "detail-"+id;
    if ($("#" + id).html()) {
      $("#" + id).fadeIn("slow").addClass("active");
    }
		else { alert("Leider wurde das Projekt nicht gefunden"); }
	}

var moveProjects = function(direction){
    var position = $("#projects-content").position();
    switch (direction) {
        case "left":
            if (position.left < 0) {
                $("#projects-content").css({
                    left: (position.left + 5) + "px"
                });
            }
            break;
        default:
            if (position.left > -600) {
                $("#projects-content").css({
                    left: (position.left - 5) + "px"
                });
            }
            break;
    }
}

