// JavaScript Document
function setContest(id){document.forms.form_participation.contest[id].checked = true;} 

 var ctrl={};
 var ctrl={
	 anim:{
		 lastFade:"",
		 fadein: function(options){
			$("#fade_wrapper")
			 	.css({display:"block",visibility:"visible",filter: "alpha(opacity=0)"})//alpha ->ie* animstart opacity 
			 	.animate( {opacity: 0.85 }, { queue:false, duration:800} );
			$("#overlay_container").css({display:"block", visibility:"visible"});			
			setTimeout(function(){ $("#" + options.secLayer).animate({height: options.height}, 850).css({visibility:"visible"})}, 800);			 
		 },
		 fadeout: function(options){
			$("#" + ctrl.anim.lastFade)
				  	.animate( { height:"0px" },850 ); 
			setTimeout(function(){
					$("#fade_wrapper")
					.animate( {opacity: 0 }, { queue:false, duration:800, callback: ctrl.anim.clearfade() } )
			}, 800);
		 },
		 clearfade: function(options){
			$("#" + ctrl.anim.lastFade).css({display:"none",visibility:"hidden"});
			ctrl.anim.lastFade = "";
			setTimeout(function(){
				$("#overlay_container").css({display:"none",visibility:"hidden"}),
				$("#fade_wrapper").css({display:"none",visibility:"hidden"});
			},750);
		 }
	
	 },
	 formSubmit:{
		 showResponse: function(options){
			 $("#sendSuccess").show('slow');

			 },
		 showEmail: function(options){
			 $("#successEmail").append("<p>You are added to the newsletter list.</p>").show('slow');

			 }
		}		 
 }

 
 $(document).ready(function() {
	jQuery.each($("a.fadeitem"), function(i,val) {
		$("#_" + i ).click(function() {
		     setContest(i);
			 ctrl.anim.fadein({secLayer: "participation",height:"500px"});
			 ctrl.anim.lastFade = "participation";
		});
	});
 	
	jQuery.each($("#container a.fadeitem"), function(i,val) {
		$("#item_" + i ).click(function() {
		     setContest(i);
		});
	});
	
	$("div#clicker").click(function (){ctrl.anim.fadeout()});
	
	$("#content_left a.poster").click(function (){
		ctrl.anim.fadein({secLayer: "poster",height:"600px"});
        ctrl.anim.lastFade = "poster";						  
	});

	$("#content_left a.maps").click(function (){
		ctrl.anim.fadein({secLayer: "maps",height:"500px"});
        ctrl.anim.lastFade = "maps";						  
	});
	
	$("#form_email").validate({							  
		rules: { 
            email: { 
                required: true, 
                email: true 
            } 
        }, 
        messages: { 
            email: { 
                required: "Please enter a valid email address", 
                minlength: "Please enter a valid email address" 
            } 

        }, 
        errorPlacement: function(error, element) { 
            if ( element.is(":text") ) 
                error.appendTo( "#emailres" ); 
        }, 
        // specifying a submitHandler prevents the default submit, good for the demo 
        submitHandler: function(form) { 
			//alert("fireemail");
			$("#form_email").submit(function() { 
				//alert("startsubmit");							 
				$(this).ajaxSubmit({url: "postemail.php", type: "POST", success: ctrl.formSubmit.showEmail()});
				return false; 
			});
 
        }, 
        success: function(label) { 
            // set   as text for IE 
            label.html("Valid email adresse - plz press send").addClass("checked"); 
        } 
    }); 
									  
	$("#form_participation").validate({ 
        rules: { 
            fullname: "required", 
            artistname: "required", 
            crewname: "required", 
            email: { 
                required: true, 
                email: true 
            }, 
			phone: "required",
			city: "required",
			country: "required"

        }, 
        messages: { 
            fullname: "Enter your full name", 
            artistname: "Enter your artist name",
			crewname: "Enter your crew name",
            email: { 
                required: "Please enter a valid email address", 
                minlength: "Please enter a valid email address" 
            } 

        }, 
        // the errorPlacement has to take the table layout into account 
        errorPlacement: function(error, element) { 
            if ( element.is(":radio") ) 
                error.appendTo( element.parent().next().next() ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo ( element.next() ); 
            else 
                error.appendTo( element.parent().next() ); 
        }, 
        // specifying a submitHandler prevents the default submit, good for the demo 
        submitHandler: function(form) { 
			//alert("fire");
			$(form).submit(function() { 
				//alert("startsubmit");							 
				$(this).ajaxSubmit({url: "postpart.php", type: "POST", success: ctrl.formSubmit.showResponse()});
				return false; 
			});
 
        }, 
        // set this class to error-labels to indicate valid fields 
        success: function(label) { 
            // set   as text for IE 
            label.html("OK").addClass("checked"); 
        } 
    }); 
 });
  
  
 
 
 
  