function slideshow(){
		//$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
		
		$('ul.gallery_demo').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
			
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
        thumb_number = $('ul.gallery_demo > li').index(thumb.parent());
        margin_left = ((thumb_number * 104) - 220); //120);
        //if (margin_left > 220) margin_left += 220;
        completely_right = $('ul.gallery_demo > li').index($('ul.gallery_demo > li:last')) * 104;
        if (margin_left < 0){
          margin_left = '0px';
        } else if(completely_right - 440 < margin_left) {
          margin_left = '-'+(completely_right - 460)+'px';
        } else {
          margin_left = '-'+margin_left+'px';
        }
				//$('ul.gallery_demo').animate({"margin-left": "100px"},'slow');
        $('ul.gallery_demo').animate({'marginLeft':margin_left});
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.6';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
        
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.6); } // don't fade out if the parent is active
				)
			}
		});
}
timeout = '';

function start_slideshow(link){
  show_next_slide();
  $(link).text('stop slideshow');
  $(link).unbind('click');
  
  $(link).click(function(event){
    stop_slideshow(this);
  });
}

function stop_slideshow(link){
  $(link).text('start slideshow');
  $(link).unbind('click');

  $(link).click(function(event){
    start_slideshow(link);
  });
  clearTimeout(timeout);
}

function show_next_slide(){
  timeout = setTimeout(function(){
    $.galleria.next();
    show_next_slide(); 
  },3000);
}

function slideshow_scroll_right(){
  $gallery = $('ul.gallery_demo');
  margin_left = $gallery.css('margin-left');
  margin_left = parseInt(margin_left.substring(0,margin_left.indexOf("px")));
  completely_left = $('ul.gallery_demo > li').index($('ul.gallery_demo > li:last')) * -104 + 460;
  distance_togo = (completely_left - margin_left) * -1;
  time = distance_togo / 500 * 1000
  $('ul.gallery_demo').animate({'marginLeft':completely_left},time,false);
}

function slideshow_scroll_left(){
  $gallery = $('ul.gallery_demo');
  completely_right = 220;
  margin_left = $gallery.css('margin-left');
  margin_left = parseInt(margin_left.substring(0,margin_left.indexOf("px")));
  distance_togo = (completely_right + margin_left * -1);
  time = distance_togo / 500 * 1000
  $('ul.gallery_demo').animate({'marginLeft':0},time,false);
  
}

$(document).ready(
  function () {
    $("a[rel~=external]").attr({target:"_blank"});
    // #flashTest1 is the selector
    $('#radioButton').flash({   // test.swf is the flash document   
      swf: '/assets/swf/radioButton.swf',
      height: 270,
      width: 160,
      params: {wmode: 'transparent'}
    });

		load_twitter(0);
		
		window.fbAsyncInit = function() {
			FB.init({appId: '3134616c2ac26b872bcf1ddde1e4739f', status: true, cookie: true,
							 xfbml: true});
		};
		(function() {
			var e = document.createElement('script'); e.async = true;
			e.src = document.location.protocol +
				'//connect.facebook.net/en_US/all.js';
			document.getElementById('fb-root').appendChild(e);
		}());
  }

);

function load_twitter(last_id){
	$.getJSON('/twitter/index/'+last_id,function(data){
		if (data){
			$('.tweets > p').remove();
			last_id = data.last_id[0];
			$('.twitter_table').prepend(data.data);
		}
		setTimeout(function(){load_twitter(last_id);},20000);
	});
}

var currentBanner = 0;

function bannerCycle(banners){
  var obj = jQuery.parseJSON(banners);
  currentBanner = Math.floor(Math.random()*obj.length)
  showNextBanner(obj)
}

function showNextBanner(banners){
  if (banners[currentBanner]){
    newTimeout = banners[currentBanner].banner_duration * 1000;
    showBanner(banners[currentBanner]);
    currentBanner++;
    if (currentBanner == banners.length) currentBanner = 0;
    setTimeout(function(){
      showNextBanner(banners);
    },newTimeout);
  }
}

function showBanner(banner){
  $('#bannerContainer > div').empty();
  $('#bannerContainer > div').flash({   // test.swf is the flash document   
    swf: banner.url,
    width:486,
    height:69,
    params: {wmode: 'transparent'}
  });
}
current_agenda_banner = 0;
agenda_banners = [];
function show_agenda_banners(banners){
	if(banners){
		agenda_banners = jQuery.parseJSON(banners);
	}
	agenda_banner = agenda_banners[current_agenda_banner];
	current_agenda_banner++;
	if (current_agenda_banner == agenda_banners.length) current_agenda_banner = 0;
	show_agenda_banner(agenda_banner);
	setTimeout(function(){
		show_agenda_banners();
	},agenda_banner.banner_duration * 1000);
	
}

function show_agenda_banner(banner){
	/*
  $('#agenda_banner_container').flash({   // Works but cant find controls for the swf. It seems like you need to activate it.
    swf: '/assets/swf/banner_holder.swf',
    width:590,
    height:200,
    flashvars: {height: 320,width:480}
    //params: {wmode: 'transparent'}
  });
	*/
	
	$('#agenda_banner_container').empty();
	//flowplayer("agenda_banner_container", "/assets/swf/flowplayer-3.1.5.swf");
	
	$('#agenda_banner_container').flash({   // test.swf is the flash document   
		swf: banner.filename,
		width:590,
		height:200,
		flashvars: {height: 320,width:480}
	});
	
}

function tuneIn()
{
	//alert("tune in!");
	
	var popup = window.open('/radio/player/','MohRadio','width=470,height=300,scrollbars=no,toolbar=no,location=no');
	if (window.focus) {popup.focus()}
		
}

