jQuery(document).ready(function(){
	Slideshow.autoPlay();
});

jQuery.noConflict();
// jQuery(document).ready(function($){
		var Slideshow = {
	
		currentID: 1,
		autoplayInterval: 5000,
		intervalID: null,
	
		slide: function(newID, userClick){
			if(newID!=this.currentID){
				this.fadeImages(newID);
				this.toggleNavigation(newID);
			}
			if (userClick) { clearTimeout(this.intervalID); }
		},
	
		fadeImages: function(newID){
			var currentSlide = jQuery("#slide-"+this.currentID);
			var newSlide = jQuery("#slide-"+newID);
			newSlide.show();
			currentSlide.fadeOut(500, function(){
				newSlide.css("z-index", 10);
				currentSlide.css("z-index", 8);
				Slideshow.currentID = newID;
			});
		},
	
		toggleNavigation: function(newID){
			jQuery("#slideshownav li").each(function(){
				var element = jQuery(this);
				if (element.attr("id")=="slidenav-"+newID) {
					element.addClass("current");
				} else {
					element.removeClass("current");
				}
			});
		},
	
		autoPlay: function(){
			this.intervalID = setTimeout(function(){
				Slideshow.nextSlide()
			}, this.autoplayInterval);
		},
	
		nextSlide: function(){
			var possibleNewID = this.currentID + 1;
			var newID;
			if (jQuery("#slide-"+possibleNewID).length!=1) {
				newID = 1;
			} else {
				newID = possibleNewID;
			}
			this.slide(newID);
			this.autoPlay();
		}
	};
// });


// function send_form(form, url){
// 	
// 	var form_name = form;
// 	var form = jQuery("form#"+form);
// 	
// 	if(form.size()==1){
// 		
// 		console.log("1");
// 		jQuery.ajax({
// 			cache:false,
// 			data:jQuery(form).serialize(),
// 			dataType:"json",
// 			complete:function(){
// 			},
// 			error:function(xhr, status, error){
// 				console.log("6","xhr:"+xhr+",status:"+status+"error:"+error);
// 				alert("Error sending the form: '"+status+"'");
// 			},
// 			success:function(data, status){
// 				console.log("2");
// 				if(data.status=="success"){
// 					alert(data.message);
// 					enable_form(form, true);
// 				} else {
// 					console.log("3");
// 					alert(data.message);
// 					enable_form(form, false);
// 				}
// 				if(data.fields){ 
// 					console.log("4");
// 					mark_fields(form_name, data.fields);
// 				}
// 			},
// 			url:url
// 		});
// 		
// 			console.log("5");
// 		disable_form(form, "Sending...");
// 		
// 	} else {
// 		alert("Form not found");
// 	}
// 	
// 	return false;
// 	
// }
// 
// function disable_form(form, message){
// 	jQuery(form).find("input, textarea").each(function(){
// 		jQuery(this).attr("disabled", "disabled");
// 	});
// 	if(message){
// 		var revert = jQuery(form).find("input[type='submit']").val();
// 		jQuery(form).find("input[type='submit']").val(message).attr("revert", revert);
// 	}
// }
// 
// function enable_form(form, reset){
// 	jQuery(form).find("input, textarea").each(function(){
// 		// $(this).attr("disabled", "");
// 		jQuery(this).removeAttr("disabled");
// 		if(reset){ jQuery(this).val(""); }
// 		if(jQuery(this).attr("type")=="submit"){
// 			var revert = jQuery(this).attr("revert");
// 			if(revert){
// 				jQuery(this).val(revert);
// 				jQuery(this).attr("revert", "");
// 			}
// 		}
// 	});
// }
// 
// function mark_fields(form, fields){
// 	jQuery("#"+form+" .mark").each(function(){
// 		jQuery(this).removeClass("mark");
// 	});
// 	for(var i=0; i<fields.length; i++){
// 		// console.log(fields[i]);
// 		jQuery("#"+fields[i]).addClass("mark");
// 		jQuery("label[for='"+fields[i]+"']").addClass("mark");
// 	}
// }

