function hideAll() {
	$("#menu li a").removeClass("on");
	$(".section").hide();
}

function preload() {
	var href = $(this).attr("href");
	$("<img src=" + href + " alt='' />");
	//alert(href);
	return;
}

function mass_preload() {
	$(".change-photo").each(preload);
}



//not really good ... sry ;-)
function next_photo(){
	
	if(current_photo < photos.length-1) {
		current_photo++;
		$(".change-photo").removeClass("on");
		$(".change-photo[@href=" +  photos[current_photo] + "]").addClass("on");
		//$("#album-photo").fadeTo("fast", 0.7, function() {
			$("#album-photo").attr("src", photos[current_photo]);
			//$("#album-photo").fadeTo("fast", 1);
		//});
		$("#prev-photo").fadeTo("fast", 1);
		if(current_photo == photos.length-1) {
			$("#next-photo").fadeTo("fast", 0.1);
		}
	} else {
		$("#next-photo").fadeTo("fast", 0.1);
	}
	//console.log(current_photo);
	return false;
}
function prev_photo() {
	if(current_photo > 0) {
		current_photo--;
		$(".change-photo").removeClass("on");
		$(".change-photo[@href=" +  photos[current_photo] + "]").addClass("on");
		//$("#album-photo").fadeTo("fast", 0.7, function() {
			$("#album-photo").attr("src", photos[current_photo]);
			//$("#album-photo").fadeTo("fast", 1);
		//});
		$("#next-photo").fadeTo("fast", 1);
		
		if(current_photo-1 < 0) {
			$("#prev-photo").fadeTo("fast", 0.1);
		}
	} else {
		$("#prev-photo").fadeTo("fast", 0.1);
	}
	//console.log(current_photo);
	return false;
}



var photos = [];
var current_photo = 0;
$(function() {

	$(".change-photo").each(function(){
		photos.push($(this).attr("href"));
	});
	if(photos.length <= 1) {
		$("#next-photo").fadeTo("fast", 0.1);
	}
	$("#prev-photo").fadeTo("fast", 0.1);
	$("#next-photo").bind("click", next_photo);
	$("#prev-photo").bind("click", prev_photo);
	
	//after 5 seconds start to preload all pictures
	setTimeout("mass_preload()", 5000);
	
	$("#menu li a").bind("click", function() {
		switch($(this).attr("id")) {
      		case "cmt": hideAll(); $("#comments").show(); $(this).addClass("on"); break;
			case "reg": hideAll(); $("#register").show(); $(this).addClass("on"); break;
			case "ckt": hideAll(); $("#contacts").show(); $(this).addClass("on"); break;
		}
		return false;
	
	});					 
  
  $(".change-photo").bind("mouseover", preload);	
  $(".change-photo").bind("click", function() {
  
    var im = $(this).attr("href");
   
    $(".change-photo").each(function(){
      $(this).removeClass("on");
    });
    $(this).addClass("on");
    
    $("#album-photo").attr("src", im);
    current_photo = parseInt($(this).html()) - 1;
    $("#prev-photo").fadeTo("fast", 1);
    $("#next-photo").fadeTo("fast", 1);
    return false;
    
  });
  
  $("#comment-form").validate({
    rules : {
      fName : "required",
      fText : "required",
      captcha : "required"
    },
    messages: {

    },
    errorPlacement: function(error, element) {
      element.parent().parent().children("td:eq(0)").addClass("error");
      return false;
    }
  });
  
  
  $("area").bind("click", function() {
    return false;
  });
  
  $(document).arrowNavigation();
 
});
