Cufon.replace('h4.spotlight, p.footer_address, .orange_460 h4, p.booking, div.topics h3, div.address_box h3, .about_box h3 span', { fontFamily: 'filosophia'});

$(document).ready(function(){
	
	// lazyload 
	
	$('div.speakers_content ul img').lazyload({
	     placeholder : "/img/grey.gif",       
	     effect      : "fadeIn",
   		 failurelimit : 8
	 });
	
	/*$('.topic_content img').lazyload({
	     placeholder : "/img/grey.gif",       
	     effect      : "fadeIn", 
		 threshold : -100, 
		 //container: $(".jcarousel-clip-horizontal"),
 		 failurelimit : 20
	 });*/
	
	//cycle
	
	$('#home_cycle').cycle({ 
		    timeout: 6000, 
			//cleartypeNoBg: true, 
			prev:   '#cycle_prev', 
	    	next:   '#cycle_next'
		});
	
	$('#cycle_pause').toggle(function() {
		$(this).addClass('active');  
	    $('#home_cycle').cycle('pause'); 
	}, function() { 
		$(this).removeClass('active'); 
		$('#home_cycle').cycle('resume'); 
	});
	
	$('#testimonials').cycle({ 
	    timeout: 0, 
		fx: 'scrollHorz',
		speed: 'fast', 
		cleartypeNoBg: true, 
		prev:   '#cycle_test_prev', 
    	next:   '#cycle_test_next'
	});	
	
	var testnum = $("ul#testimonials > li").length;
	if(testnum < 2) { 
		$('#test_cycle').hide(); 
	}
	
	//a.link_a
	
	$('a.link_a').wrap('<div class="link_shell" />')
	
	$('div.link_shell').each(function() { 
		var bordercolor = $(this).children('a.link_a').css('background-color'); 
		return $(this).css('border-color', bordercolor); 
	}); 
	
	$('a.link_a').hover(
	  function () {
		var bghover = $(this).css('background-color'); 
	    $(this).parent('div.link_shell').css('border-color', bghover);
	  }, 
	  function () {
		var bgcolor = $(this).css('background-color'); 
	    $(this).parent('div.link_shell').css('border-color', bgcolor);
	  }
	);
	
	//newsletter slideDown
	
	/*$('div.email_box a.signup').toggle(function() { 
		$(this).addClass('active'); 
		$('div.newsletter_signup').slideDown('slow', function() {
					    // Animation complete.
					  });
	}, function() { 
		$(this).removeClass('active'); 
		$('div.newsletter_signup').slideUp('slow', function() { 
						// Animation complete.
			}); 
	}); 
	
	$('#mce-EMAIL').focus(function() { 
		$(this).val(''); 
		$(this).css('outline', '0px'); 
	}); */
	
	//margin-right
	
	$('ul.ul_featured li:nth-child(4n)').css('margin-right', '0px'); 
	$('ul.ul_events li:nth-child(3n)').css('margin-right', '0px'); 
	$('.topic_photo_list ul li:nth-child(4n)').css('margin-right', '0px');
	$('.addthis_toolbox a:nth-child(4n)').css('margin-right', '0px');
	
	//featured hover 
	
	$('ul.ul_featured li a').hover(function() { 
		$(this).children('div.featured_desc').css('background-color', '#EB5307'); 
	}, function() { 
		$(this).children('div.featured_desc').css('background-color', '#FA662D'); 
	}); 
	
	//yay for tabs!
	
	$('div.tabcontent').hide(); 
	
	$("ul#speaker_tabs li:first").addClass("active").show(); //Activate first tab
	$(".tabcontent:first").fadeIn(200); //Show first tab content

	$("ul#speaker_tabs li").click(function() {
		$("ul#speaker_tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tabcontent").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(200); //show the active ID content
		
		return false;
	});
	
	//carousels
	
	$('ul.jcarousel-skin-tango').jcarousel({
	    	wrap: 'last', 
			scroll: 4
	});
	
	$('.jcarousel-list').each(function() { 
		var linum = $(this).children('li').length; 
		if(linum < 5) { 
			$(this).parent('div.jcarousel-clip').parent('div.jcarousel-container').children('div.jcarousel-prev').hide(); 
			$(this).parent('div.jcarousel-clip').parent('div.jcarousel-container').children('div.jcarousel-next').hide(); 
		}
	});
	
	// list view
	
	$('.topics #topic_toggle .by_name').click(function() { 
		$('div.jcarousel-container').addClass('list-view');
		$('div.jcarousel-skin-tango').parent('div').addClass('list-view-shell'); 
		$('div.jcarousel-skin-tango').removeClass('jcarousel-skin-tango').addClass('carousel-blank'); 
		$('a.viewall').hide(); 
		$('a.by_photo').parent('li').removeClass('active'); 
		$(this).parent('li').addClass('active'); 
		
		$('.topic_photo_list ul').addClass('list-view'); 
	}); 
	
	$('.list-view ul li:nth-child(4n)').css('margin-right', '0px');
	
	$('.topics #topic_toggle .by_photo').click(function() { 
		if($('.by_name').parent('li').hasClass('active')) { 
			$('div.jcarousel-container').removeClass('list-view');
			$('div.carousel-blank').removeClass('carousel-blank').addClass('jcarousel-skin-tango'); 
			$('a.viewall').show(); 
			$('a.by_name').parent('li').removeClass('active');
			$(this).parent('li').addClass('active'); 
			
			$('.topic_photo_list ul').removeClass('list-view'); 
			$('div.list-view-shell').removeClass('list-view-shell'); 
		}
	});
	
	$('.speakers #topic_toggle .by_name').click(function() { 
		$('ul.speaker_grid').addClass('speaker-list-view');
		$('a.by_photo').parent('li').removeClass('active'); 
		$(this).parent('li').addClass('active'); 
	}); 
	
	$('.speakers #topic_toggle .by_photo').click(function() { 
		if($('.by_name').parent('li').hasClass('active')) { 
				$('ul.speaker_grid').removeClass('speaker-list-view');
				$('a.by_name').parent('li').removeClass('active'); 
				$(this).parent('li').addClass('active');
		}
	});
	
	// FAQ
	
	$('div.faq-question').toggle(function() { 
		$(this).addClass('open'); 
		$(this).parent('div').children('div.faq-answer').slideDown('slow', function() {
					    // Animation complete.
					  });
	}, function() { 
		$(this).removeClass('open'); 
		$(this).parent('div').children('div.faq-answer').slideUp('slow', function() {
					    // Animation complete.
					  });
	});
	
	// modals 
	
	$('div#topics_ext').jqm({trigger: 'a#trigger_topics_ext'});
	
		$('a#trigger_topics_ext').click(function(){
			$('html,body').animate({scrollTop: 0}, 300);
			$('div#topics_ext').hide(); 
			$('div#topics_ext').fadeIn(500); 
		});
	
	$('div#modal-news').jqm({trigger: 'a.modal_join_form'}); 
	$('a.modal_join_form').click(function(){
		$('div#modal-news').css('top', $(window).scrollTop() + 65);
		$('div#modal-news').hide(); 
		$('div#modal-news').fadeIn(500); 
	});
	
	// letter
	
	$(".biglist li .lastname").each(function() {
	      var text = $(this).html();
	      var first = text.charAt(0);
		  $(this).parent('a').parent('li').addClass(first); 
	   });
	$(".speakers_content ul li .lastname").each(function() {
	      var text = $(this).html();
	      var first = text.charAt(0);
		  $(this).parent('li').addClass(first); 
	   });
	
	// letter sort 

	$('div.letter_sort li:not(.all) a').click(function() { 
			$('div.speakers_content ul li').hide(); 
			var letter = $(this).parent('li').attr('class');
			$('div.speakers_content ul li').each(function() { 
				if($(this).hasClass(letter)) { 
					$(this).fadeIn(500); 
					$(this).children('img').lazyload({
					     placeholder : "/img/grey.gif",       
					     effect      : "fadeIn",
				   		 failurelimit : 10
					 });
				}
			}); 
			$('div.letter_sort ul').find('li.active').removeClass('active'); 
			$(this).parent('li').addClass('active');	
		}); 
		
	$('div.letter_sort li.all a').click(function() { 
			$('div.speakers_content ul li').hide(); 
			$('div.speakers_content ul li').fadeIn(500); 
			$(this).children('img').lazyload({
			     placeholder : "/img/grey.gif",       
			     effect      : "fadeIn",
		   		 failurelimit : 10
			 });
			$('div.letter_sort ul').find('li.active').removeClass('active'); 
			$(this).parent('li').addClass('active');
	}); 
	
	// connect 
	
	$('a.button_connect').click(function() { 
		if($(this).hasClass('active')) { 
			$('div.div_connect').slideUp(300); 
			$(this).removeClass('active');
		}
		else { 
			$('div.div_connect').slideDown(300); 
			$(this).addClass('active'); 
		}
	}); 
	
	//other 
	
	$('input.gsc-input').focus(function() { 
		$(this).val(""); 
	}); 
	$('input.find_field').focus(function() { 
		$(this).val(""); 
	});
	
	$('.jotform-form').validate();
	
	// newsletter form
	
	$('#news-form').submit(function () {
				var day = $('#birthDay').val();
				var month = $('#birthMonth').val();
				var year = $('#birthYear').val();
				var age = 13;
				var mydate = new Date();
				mydate.setFullYear(year, month, day);
				var currdate = new Date();
				currdate.setFullYear(currdate.getFullYear() - age);
				if ((currdate - mydate) < 0){
					$('div.agealert').show(); 
					return false;
				}
				else { 
					$('div.agealert').hide(); 
					if($(this).valid()) {
				    	$('#news-form').hide(); 
						$('#news-form-success').fadeIn(500); 
					}
					else { 
						return false;
					}
				}
			});
		
	$('#news-form').validate();
	
	function getUrlVars() {
	    var vars = {};
		var string = unescape(window.location.href);
	    var parts = string.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
	        vars[key] = value;
	    });
	    return vars;
	}	
	
	$('input#input_17').each(function() { 
		var topic = getUrlVars()["topic"];
		$(this).val(topic); 
	});
	
}); 
