$(document).ready(function(){
$('#facebook').html('<script type="text/javascript" src="http://static.ak.connect.facebook.com/connect.php/en_GB"></script><script type="text/javascript">FB.init("72ff40343a560f4c715feb158a1ff661");</script><fb:fan profile_id="7331786317" stream="0" connections="10" logobar="1" width="300"></fb:fan><div style="font-size:8px; padding-left:10px"><a href="http://www.facebook.com/nationalunionofstudents">National Union of Students</a> on Facebook</div>');

var mypref = $("#eventcalcontrol div.calendarview:contains('listview')")
if(mypref.length){
	$("#eventlistswitch").show();
	$("#eventcalswitch").hide();
}else{
	$("#eventcalswitch").show();
	$("#eventlistswitch").hide();};

var mypreflist = $("#eventcalcontrol.openaccess");

if(mypreflist.length){
   
   $("#eventcalcontrol.openaccess a").click(function(){
        
	if($(this).text() == "listview"){
		$("#eventlistswitch").show();
		$("#eventcalswitch").hide();
		return false;
	}else{
		$("#eventcalswitch").show();
		$("#eventlistswitch").hide();
		return false;
	};
   });
};
$("#displaynewsfilter").click(function() {
		$("#newsfilter").slideToggle("fast");
		return false;
	});

$("#displaycampaignsfilter").click(function() {
		$("#campaignsfilter").slideToggle("fast");
		return false;
	});
$("#jobspanel a").attr("target","_blank");

//banner controls

    $('#banner').children('.killfloat').remove();
    $('#banner').children('.news_all').remove();

// Removes nbsp between the last two words in the headline
    $('#banner h5').each(function() {
        var headline = $(this).find('a').text().replace(/\u00a0/g,' ');
        $(this).find('a').text(headline);
    });
    $('#banner .news_item').show();
    $('.nav').show();
    $('#banner').cycle({
   	 fx:     'scrollHorz',
    	prev:   '#prev',
   	 next:   '#next',
    	after:  onAfter,
    	speed:400,
	pager: '#pager',
    	timeout:6000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...  
    });

// Conference News List - appends skin preview parameter to the articles
    preview = "?skin=su2011&template=su2011-news";
    $('#conference-news a').each(function(){
        link = $(this).attr('href');
        $(this).attr('href', link + preview);
    });

});

function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('#prev')[index == 0 ? 'hide' : 'show']();
    $('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}
