jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function


	/*******************************************/
	// auto reflections with jQuery. Sweet...
	
	/*	Loop through all images to call the reflect function, prevents
		the otherwise glitchy loading that plagues this plugin */
	$('img.reflect').each(function(){
		$(this).load( 
			function(){ 
				$(this).reflect({height: 0.2, opacity: 0.3} );
			} 
		);
	});

	/*	Doesn't seem to do any harm to call this function twice
		and this makes sure shadows are appended to images which
		are hidden by CSS on load - they're not caught by the loop above */
	$('img.reflect').reflect({height: 0.2, opacity: 0.3});

	/*******************************************/
	// agenda item open/close buttons

	$('a.agenda-button').click(function(){
		$(this).parent().parent().find('div.agenda-item-details').toggle();
		if ( $(this).hasClass('agenda-button-active') )	{
			$(this).removeClass('agenda-button-active');
		} else {
			$(this).addClass('agenda-button-active');		
		}
		return false;	
	});
	
	$('#agenda-view-all').toggle(
		function(){
		$('div.agenda-item-details').show();
		$('a.agenda-button').addClass('agenda-button-active');
		return false;
		},
		function(){
		$('div.agenda-item-details').hide();
		$('a.agenda-button').removeClass('agenda-button-active');
		return false;
		}
	);


	/*******************************************/
	// hover state boxes for sidebar speaker panels

	$("div.speaker-list-item div.details, div.speaker-list-item div.thumbnail").hover(function() {
	  $("div.speaker-details").hide();
	  $(this).parent().next("div.speaker-details").fadeIn('fast');
	  $('div.details-active').removeClass('details-active');
	  $(this).parent().find('div.details').addClass('details-active');
	}, function() {
	});
	
	$('div.speaker-details').hover(function() {
	}, function () {
		$(this).fadeOut('fast');
	    $(this).parent().find('div.details').removeClass('details-active');
	});
	
	$('a.orange-arrow').hover(function(){
		$("div.speaker-details").hide();
	});

	/*******************************************/
	// read more links for speakers

	$('div.readmore-content p').hide();
	$('div.readmore-content p:first-child').show();
	
	$('div.readmore-content').each(function(){
		var paras = $(this).children().length;
		if ( paras <= 1 )	{
			$(this).parent().find('a.readmore').remove();
		}
	})

	$('a.readmore').click(function(){
	
		if ($(this).parent().hasClass('readmore-active'))	{
			$('div.readmore-active').removeClass('readmore-active');
			$('div.readmore-content p').hide();
			$('div.readmore-content p:first-child').show();
			$(this).parent().find('a.readmore').html('Read More');
			return false;
		} else	{
			$('div.readmore-active').removeClass('readmore-active');
			$('div.readmore-content p').hide();
			$('div.readmore-content p:first-child').show();
			$(this).parent().addClass('readmore-active');
			$(this).parent().find('div.readmore-content p').fadeIn('fast');			
			$(this).parent().find('a.readmore').html('Close');
			return false;							
		}	
	});
	
	
/*	// auto-open the readmore link if anchor tag present
	// not finished yet
	var url = document.location.toString();
	if (url.match('#')) { // the URL contains an anchor
	var anchor = '#' + url.split('#')[1];
	$(anchor).find('div.readmore-content p').fadeIn('fast');	
	} else {
	}
*/ 

	/*******************************************/
	// participating companies

	var s_groups = $('div.sponsor_logo').length; // 
	if (s_groups > 1) {
		var s_i = 1;
		
		$('div.sponsor_logo').hide();
		$('#sponsor_section_'+s_i).show(); // show first group
	
		var aniCar = setInterval(function() // rotate through groups in a loop
		{
			$('#sponsor_section_'+s_i).hide();
			s_i += 1;
			if ( s_i > s_groups ) s_i = 1;
			$('#sponsor_section_'+s_i).fadeIn('slow');		
		}, 7500);	
	}



	/*******************************************/
	// media partners rotation script

	var m_groups = $('div.media_logo').length; // how many media partners sections do we have? Only do animation if more than one
	if (m_groups > 1) {
		var i = 1;
		
		$('div.media_logo').hide();
		$('#media_section_'+i).show(); // show first group
	
		var aniCar = setInterval(function() // rotate through groups in a loop
		{
			$('#media_section_'+i).hide();
			i += 1;
			if ( i > m_groups ) i = 1;
			$('#media_section_'+i).fadeIn('slow');		
		}, 7500);	
	}


});








