$(document).ready(function(){
	/* Round corner */
	$('#left-inside').corner();
	$('.info').corner();
	$('.programme_bio').corner();
	$('#mybox').corner();
	$("#right-inside").corner();

	/* Rollover */
	$('.rollover').hover(function() {
       var currentImg = $(this).attr('src');
       $(this).attr('src', $(this).attr('alt'));
       $(this).attr('alt', currentImg);
	}, function() {
       var currentImg = $(this).attr('src');
       $(this).attr('src', $(this).attr('alt'));
        $(this).attr('alt', currentImg);
    });
							
	$(".name").click(function(){
		$(this).next(".info").slideToggle(50);
		$(".info").hide();
		if($(this).hasClass("active") ){
			$(this).removeClass("active");
		}else{
			$("div").removeClass("active");
			$(this).addClass("active");
		}
		return false;
	});
	
	$(".programme_name").click(function(){
		$(this).next(".programme").slideToggle(50);
			$(".programme").hide();
		if($(this).hasClass("programme_active") ){
			$(this).removeClass("programme_active");
		}else{
			$("div").removeClass("programme_active");
			$(this).addClass("programme_active");
		}
		return false;
	});

	$('#speakerlist li').click( function() {
		$('div.speakerbox').hide();
		$('div.speakerbox2').hide();
		$(this).children('div.speakerbox').show();
		$(this).children('div.speakerbox2').show();
	});
		
	$('#programmelist li').click( function() {
		$(this).children('div.programmebox').toggle();
		$(this).children('div.programmebox2').toggle();
		$(this).children('div.programmebox3').toggle();
	});


// prepare the form when the DOM is ready 
 //   var options = { 
 //       beforeSubmit:  validate,  // pre-submit callback 
 //       success:       showResponse,  // post-submit callback 
 //		resetForm: true 
 //    }; 
 
 	$( "#event-details .accomodation" ).click(function(){
		$( "#event-details" ).css( "background-position", "0 551px" );
		$( ".maps-content" ).css( "display", "none" );
		$( ".accomodation-content" ).css( "display", "block" );
	});
	
	$( "#event-details .maps" ).click(function(){
		$( "#event-details" ).css( "background-position", "0 0" );
		$( ".accomodation-content" ).css( "display", "none" );
		$( ".maps-content" ).css( "display", "block" );
	});
 
    // bind to the form's submit event 
    $('input#submit').unbind().click(function(event) { 
 //         $(this).ajaxSubmit(options); 	
		//  	data: datastring,	
		
		fname = $( "#fname" ).val();
		surname = $( "#surname" ).val();
		company = $( "#company" ).val();
		mobile = $( "#mobile" ).val();

		if ( fname == "" || surname == "" || company == "" || mobile == "" ){
			console.log( "Please complete all fields." );
			$( "#error-message" ).css( "display", "block" );
		}
		else{
			datastring = "fname="+fname+"&surname="+surname+"&company="+company+"&mobile="+mobile;
			$.ajax({
			  	dataType: "jsonp",
				data: datastring,
			  	jsonp: "jsonp_callback",
			  	url: "http://jiminyc.com/lumley/youredge2011/rsvp-mailer.php",
			  	success: function (data) {
					window.location = "rsvp.html";
			  	}
			});
		}
		return false; 
    }); 

  	$('#gallery-left').cycle({ 
	    fx:    'scrollHorz', 
	    speed:'fast',
	    prev:    '#prev-gal',
		next:    '#next-gal',
		timeout:  0,
		after: function(curr, next, opts) {  
	    	$("#counter").html("pg&nbsp;"+(opts.currSlide + 1) + " of " + opts.slideCount); 
	    } 
	});

		/* Rollover for register,programme and event div */
		$("#accommodation_info").hide();
		$("#registerbox").mouseover(function(){						 
			$("#registerbox").css({'background':'url(images/registerbox_on.png)','cursor':'pointer'});
			}).mouseout(function(){
			$("#registerbox").css({'background':'url(images/registerbox.png)'});

		});
		
		$("#programebox").mouseover(function(){						 
			$("#programebox").css({'background':'url(images/programebox_on.png) no-repeat','cursor':'pointer'});
			}).mouseout(function(){
			$("#programebox").css({'background':'url(images/programebox.png) no-repeat'});
		});
			
		$("#eventbox").mouseover(function(){						 
			$("#eventbox").css({'background':'url(images/eventbox_on.png)','cursor':'pointer'});
			}).mouseout(function(){
			$("#eventbox").css({'background':'url(images/eventbox.png)'});
		});

	$("#mapbox").mouseover(function(){						 
		$("#mapbox").css({'background':'url(images/mapbox_on.png)','cursor':'pointer'});
	}).mouseout(function(){
		$("#mapbox").css({'background':'url(images/mapbox.png)'});
	});


	$('img#parking').click(function(){
			 
	});
		
	$('li#accommodation').click(function(){
		$("#tab").css('background-image', 'url(images/accommodation.jpg)');
		$("#parking_info").hide();
		$("#accommodation_info").show();		 
	});
		
	$('li#parking').click(function(){
	    $("#tab").css('background-image', 'url(images/parking-map.jpg)');
		$("#accommodation_info").hide();
		$("#parking_info").show(); 
	});

	// Mac issue
	version = navigator.appVersion;
	if (version.toLowerCase().indexOf("mac")!=-1){
		$("#registerbox p").css( "padding-right", "10px" );
	    $("#programebox p").css( "padding-right", "10px" );
	 }
		
});

/* FORM */
function closethankyou(){
  	//$("#mybox").hide();
	tb_remove();
}

// post-submit callback 
/*function showResponse(responseText, statusText)  { 
	if(responseText=="success"){
		document.location.href="thankyou.html";
	}else{
		alert(responseText);
	}
}*/

function validate() { 
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(!emailReg.test($("input#email").val())){
		$("#error").html("Email address is invalid");
		 $("input#email").focus();
	 	return false; 
	}
	
	$("input#fname").focus();
	
	// loop through all fields
    for (var i=0; i < formData.length; i++) { 
        if (!formData[i].value) { 
        	f="input#"+formData[i].name;
		 	$("#error").html("Please enter a value for each field");
            return false; 
        } 
    } 	
}

function mypopup(){
	$(document).ready(function(){
		tb_show('close','thankyoudbc6.html?modal=true','');
	});
}



	
