/* Top Main Navigation
--------------------------------------------------------------*/
jQuery("#main-nav li ul.sub-main-nav").hide();
jQuery("#main-nav li").mouseover(function(){
      jQuery(this).children('ul').show();
    }).mouseout(function(){
      jQuery(this).children('ul').hide();
    });


/* briefing point comments
--------------------------------------------------------------*/

// hide/show comments on points within briefings
jQuery('.comments').hide();

jQuery('.point-comment-menu').remove();
jQuery('.user-comments').hide();

// add the user/expert comment menu at the top
jQuery('.comments').prepend('<ul class="point-comment-menu"><li class="point-comment-menu-expert">expert comments<\/li><li class="point-comment-menu-user">user comments<\/li><\/ul>');

// grey out the user comment menu
jQuery('.point-comment-menu-user').css('color','#cdcbcb');

// add the comment "see comment" icon
jQuery('.comments').before('<ul class="briefing-related"><li class="briefing-related-content"><a href=""><span class="hidden">See comments</span></a><\/li><\/ul>');

// on "see comment" icon click, toggle the comments for this point and hide all others
jQuery('.briefing-related a').click( function () {
   var currentComment = jQuery(this).parent('li').parent('ul').next('.comments');
   jQuery('.comments').not(currentComment).slideUp('slow');
   jQuery(this).parent('li').parent('ul').parent('li').children('.comments').slideToggle('slow');
   return false;
});

//on "expert comment" click, show expert comments and hide user comments
jQuery('.point-comment-menu-expert').click( function() {
	jQuery(this).next('li.point-comment-menu-user').css('color','#cdcbcb');
	jQuery(this).css('color','#282828');
	jQuery(this).parent('ul').next('ul').children('.user-comments').slideUp();
	jQuery(this).parent('ul').next('ul').children('.expert-comments').slideDown();
    return false;
});

//on "user comment" click, show user comments and hide expert comments
jQuery('.point-comment-menu-user').click( function() {
	jQuery(this).prev('li.point-comment-menu-expert').css('color','#cdcbcb');
	jQuery(this).css('color','#282828');
	jQuery(this).parent('ul').next('ul').children('.expert-comments').slideUp();
	jQuery(this).parent('ul').next('ul').children('.user-comments').slideDown();
    return false;
});




/* proposition related content within briefings
--------------------------------------------------------------*/

/* change the classes of the proposition related content elements */ 
jQuery('.related-Videos').removeClass('related-Videos').addClass('related-Videos-js');
jQuery('.related-Briefings').removeClass('related-Briefings').addClass('related-Briefings-js');
jQuery('.related-Audio').removeClass('related-Audio').addClass('related-Audio-js');
jQuery('.related-Books').removeClass('related-Books').addClass('related-Books-js');
jQuery('.proposition-related').removeClass('proposition-related').addClass('proposition-related-js');


/* white box */

jQuery("div.event-section-box ul li a.whitebox-article").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=whitebox&SQ_PAINT_LAYOUT_NAME=printer_friendly';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

/* white box */

jQuery("ul.magazine-section-items li a.whitebox-article").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=whitebox&SQ_PAINT_LAYOUT_NAME=printer_friendly';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

/*  color box 
------------------------------------------------------------------------*/

jQuery("ul.magazine-section-items li a.colorbox-video").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=colorbox_iframe';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

// add a special design for event video contents
jQuery("ul.event-section-items li a.colorbox-video").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=colorbox_iframe';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

jQuery("#sub-menu ul li a.colorbox-people-1").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=colorbox&SQ_PAINT_LAYOUT_NAME=colorbox';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

jQuery("#sub-menu ul li a.colorbox-people-2").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=colorbox&SQ_PAINT_LAYOUT_NAME=colorbox';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

// add a special design for video related contents
jQuery(".related-Videos-js ul li a.related-video").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '?SQ_DESIGN_NAME=colorbox';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

// add a special design for chapter related contents
jQuery(".related-Videos-js ul li a.related-chapter").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&SQ_DESIGN_NAME=chapter';
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

// add a special design for related content audio 
jQuery(".related-Audio-js ul li a.colorBox").each(function () {
    var colorBoxHrefAttrAudio = jQuery(this).attr('href');
    var colorBoxNewHrefAttrAudio = colorBoxHrefAttrAudio + '?SQ_DESIGN_NAME=audio';
    jQuery(this).attr("href", colorBoxNewHrefAttrAudio);
});


jQuery("ul.magazine-section-items li a").each(function () {
    var colorBoxHrefAttr = jQuery(this).attr('href');
    var colorBoxNewHrefAttr = colorBoxHrefAttr + '&posturl='+posturl;
    jQuery(this).attr("href", colorBoxNewHrefAttr);
});

// add a special design for related books content 

/*jQuery(".related-Books-js ul li a.colorBox").each(function () {
    var colorBoxHrefAttrBooks = jQuery(this).attr('href');
    var colorBoxNewHrefAttrBooks = colorBoxHrefAttrBooks + '?SQ_DESIGN_NAME=books';
    jQuery(this).attr("href", colorBoxNewHrefAttrBooks);
});*/


// make each group of related content individual for breifings
jQuery(".proposition-related-colorbox a[rel='related-videos']").attr('rel','related-videos-1');
jQuery(".proposition-related-colorbox a[rel='related-audio']").attr('rel','related-audio-1');
jQuery(".proposition-related-colorbox a[rel='related-books']").attr('rel','related-books-1');

jQuery("#briefing-pointAgree a[rel='related-videos'], #briefing-pointFor a[rel='related-books']").attr('rel','related-videos-2');
jQuery("#briefing-pointAgree a[rel='related-audio'], #briefing-pointFor a[rel='related-audio']").attr('rel','related-audio-2');
jQuery("#briefing-pointAgree a[rel='related-books'], #briefing-pointFor a[rel='related-videos']").attr('rel','related-books-2');

jQuery("#briefing-pointDisagree a[rel='related-videos'], #briefing-pointAgainst a[rel='related-videos']").attr('rel','related-videos-3');
jQuery("#briefing-pointDisagree a[rel='related-audio'], #briefing-pointAgainst a[rel='related-audio']").attr('rel','related-audio-3');
jQuery("#briefing-pointDisagree a[rel='related-books'], #briefing-pointAgainst a[rel='related-books']").attr('rel','related-books-3');

// launch the colorbox plugin for video related content with a flowplayer callback
jQuery("a[rel='colorbox-video-iframe-1']").colorbox( {
        height: 600,
        width: 820,
        iframe: true
    }, function(){
});

jQuery("a[rel='colorbox-video-iframe-2']").colorbox( {
        height: 600,
        width: 820,
        iframe: true
    }, function(){
});

jQuery("a[rel='colorbox-video-iframe-3']").colorbox( {
        height: 600,
        width: 820,
        iframe: true
    }, function(){
});


jQuery("a[rel='magazine-1']").colorbox( {
        height: 600,
        width: 820,
        iframe: true
    }, function(){
});

jQuery("a[rel='magazine-2']").colorbox( {
        height: 600,
        width: 820,
        iframe: true
    }, function(){
});

jQuery("a[rel='magazine-3']").colorbox( {
        height: 600,
        width: 820,
        iframe: true
    }, function(){
});



jQuery("a[rel='colorbox-video']").colorbox( {
        height: 600,
        width: 820
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='colorbox-video-0']").colorbox( {
        height: 600,
        width: 820
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='related-videos-1']").colorbox( {
        height: 600,
        width: 550
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='related-videos-2']").colorbox( {
        height: 600,
        width: 550
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='related-videos-3']").colorbox( {
        height: 600,
        width: 550
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='colorbox']").colorbox();


// launch the colorbox plugin for audio related content with a flowplayer callback
jQuery("a[rel='related-audio-2']").colorbox( {
        width: 550
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='related-audio-3']").colorbox( {
        width: 550
    }, function(){
        launchFlowPlayer();
});


jQuery("a[rel='related-audio-1']").colorbox( {
        width: 550
    }, function(){
        launchFlowPlayer();
});

jQuery("a[rel='whitebox-article-0']").colorbox( {
        width: 820
    }, function(){
    	$('#colorbox').addClass('whitebox');
});

jQuery("a[rel='whitebox-article-1']").colorbox( {
        width: 820
    }, function(){
    	$('#colorbox').addClass('whitebox');
});
jQuery("a[rel='whitebox-article-2']").colorbox( {
        width: 820
    }, function(){
    	$('#colorbox').addClass('whitebox');
});
jQuery("a[rel='whitebox-article-3']").colorbox( {
        width: 820
    }, function(){
    	$('#colorbox').addClass('whitebox');
});

// launch the colorbox plugin for books related content without a flow player callback
jQuery("a[rel='colorbox-people-1']").colorbox( {
	    height: 600,
        width: 555,
        iframe: true
    }
);

jQuery("a[rel='colorbox-people-2']").colorbox( {
	    height: 600,
        width: 555,
        iframe: true
    }
);

jQuery("a[rel='related-books-1']").colorbox( {
        width: 526
    }
);

jQuery("a[rel='related-books-2']").colorbox( {
        width: 526
    }
);

jQuery("a[rel='related-books-3']").colorbox( {
        width: 526
    }
);



// launch colorbox for briefings and video premium content if the current user does not have the right to view the item
jQuery("a.get-membership").colorbox({width: 600, height: 400, iframe: true, rel: "nofollow", overlayClose: true});

jQuery("a.blackbox").colorbox({
	width: 600,
	height: 400,
	iframe: true,
	rel: "nofollow",
	overlayClose: true,
	onOpen:function() {
      $('#colorbox').addClass('blackbox');
   }
});

jQuery("a.get-login").colorbox({width: 400, height: 350, iframe: true, rel: "nofollow", overlayClose: true });

jQuery("a[rel='get-membership']").colorbox({width: 600, height: 400, iframe: true, rel: "nofollow", overlayClose: true});

/*jQuery("a[rel='nofollow']").colorbox({width: 600, height: 400, iframe: true, rel: "nofollow", overlayClose: true });

jQuery("a[rel='nofollow-1']").colorbox({width: 600, height: 400, iframe: true, rel: "nofollow", overlayClose: true });
*/

// Add to basket external colorbox
jQuery("a[rel='add-to-basket']").colorbox( {
        height: 470,
        width: 750
    }, function(){
});



function refresh(){
   jQuery().bind('cbox_closed', function(){ 
        window.location.reload(); 
}); 
}

/* People Page - alphabetical list
--------------------------------------------------------------*/
/*var page = jQuery("#current-page").val();
var page = jQuery("#current-page").val().toLowerCase();
jQuery("#people-alpha li a#" + page).css("color","white");*/

/* individual video associated content
--------------------------------------------------------------*/

jQuery('#video-speaker, #video-expert-comments, #video-comments, #page_asset_builder_2632_type_comment, #page_asset_builder_34295_type_comment').hide();

jQuery('#video-menu-1 a').click(function () {
	jQuery('#video-speaker, #video-expert-comments, #video-comments').slideUp();
	jQuery('#video-summary').slideDown();
    jQuery('#page_asset_builder_2632_type_comment').hide();
    jQuery('#page_asset_builder_34295_type_comment').hide();
	jQuery('#video-menu-2 a, #video-menu-3 a, #video-menu-4 a').removeClass('video-menu-selected');
    jQuery('#video-menu-1 a').addClass('video-menu-selected');
    return false;
});

jQuery('#video-menu-2 a').click(function () {
	jQuery('#video-summary, #video-expert-comments, #video-comments').slideUp();
	jQuery('#video-speaker').slideDown();
    jQuery('#page_asset_builder_2632_type_comment').hide();
    jQuery('#page_asset_builder_34295_type_comment').hide();
	jQuery('#video-menu-1 a, #video-menu-3 a, #video-menu-4 a').removeClass('video-menu-selected');
    jQuery('#video-menu-2 a').addClass('video-menu-selected');
    return false;
});

jQuery('#video-menu-3 a').click(function () {
	jQuery('#video-summary, #video-speaker, #video-comments').slideUp();
	jQuery('#video-expert-comments').slideDown();
    jQuery('#page_asset_builder_2632_type_comment').show();
    jQuery('#page_asset_builder_34295_type_comment').show();
	jQuery('#video-menu-1 a, #video-menu-2 a, #video-menu-4 a').removeClass('video-menu-selected');
    jQuery('#video-menu-3 a').addClass('video-menu-selected');
    return false;
});

jQuery('#video-menu-4 a').click(function () {
	jQuery('#video-summary, #video-speaker, #video-expert-comments').slideUp();
	jQuery('#video-comments').slideDown();
    jQuery('#page_asset_builder_2632_type_comment').show();
    jQuery('#page_asset_builder_34295_type_comment').show();
	jQuery('#video-menu-1 a, #video-menu-2 a, #video-menu-3 a').removeClass('video-menu-selected');
    jQuery('#video-menu-4 a').addClass('video-menu-selected');
    return false;
});


/* briefing preview associated content
--------------------------------------------------------------*/

jQuery('.comment-preview-, .comment-preview-expert, .comment-preview-user, .comment-preview- h3, .comment-preview-expert h3, .comment-preview-user h3').hide();
jQuery('#layout-briefing-preview h2').after('<ul class="ver2" id="briefing-menu"><li id="briefing-menu-1"><a href="#briefing-summary" class="briefing-menu-selected">summary<\/a><\/li><li id="briefing-menu-2"><a href="#briefing-expert-comments">expert comments<\/a><\/li><li id="briefing-menu-3"><a href="#briefing-comments">user comments<\/a><\/li><\/ul>');

jQuery('#briefing-menu-1 a').click( function() {
    jQuery('.comment-preview-, .comment-preview-expert, .comment-preview-user').slideUp();
    jQuery('#briefing-summary').slideDown();
	jQuery('#briefing-menu-2 a, #briefing-menu-3 a').removeClass('briefing-menu-selected');
    jQuery('#briefing-menu-1 a').addClass('briefing-menu-selected');
    return false;
});

jQuery('#briefing-menu-2 a').click( function() {
    jQuery('#briefing-summary, .comment-preview-user').slideUp();
    jQuery('.comment-preview-expert').slideDown();
	jQuery('#briefing-menu-1 a, #briefing-menu-3 a').removeClass('briefing-menu-selected');
    jQuery('#briefing-menu-2 a').addClass('briefing-menu-selected');
    return false;
});

jQuery('#briefing-menu-3 a').click( function() {
    jQuery('#briefing-summary, .comment-preview-expert').slideUp();
    jQuery('.comment-preview-user').slideDown();
	jQuery('#briefing-menu-1 a, #briefing-menu-2 a').removeClass('briefing-menu-selected');
    jQuery('#briefing-menu-3 a').addClass('briefing-menu-selected');
    return false;
});


/* upcoming events,  venue toggle
----------------------------------------*/

jQuery('.venue-info .more').hide();
jQuery('.venue-info .map').show();
jQuery('.venue-info').removeClass('venue-more');

jQuery('.venue-info .map img').click( function(){
	jQuery('.venue-info .map').slideUp('slow',function(){
			jQuery('.venue-info .more').slideDown('slow');	
	});
	jQuery('.venue-info').addClass('venue-more');
});

jQuery('.venue-info span.less').click(function(){
	jQuery('.venue-info .more').slideUp('slow',function(){
		jQuery('.venue-info .map').slideDown('slow');
	});
	jQuery('.venue-info').removeClass('venue-more');
});

jQuery('.venue-name-link a').toggle(function() {
	jQuery('.venue-info .map').slideUp('slow',function(){
	    jQuery('.venue-info .more').slideDown('slow');	
	});
	jQuery('.venue-info').addClass('venue-more');
        return false;
}, function() {
	jQuery('.venue-info .more').slideUp('slow',function(){
            jQuery('.venue-info .map').slideDown('slow');
	});
	jQuery('.venue-info').removeClass('venue-more');
        return false;
});
/* end upcoming events,  venue toggle */



/* User Registration Form Validation
--------------------------------------------------------------*/
jQuery("form#page_account_manager_1168").removeAttr("onsubmit");
jQuery("input#user_0_721").attr("class",jQuery("input#user_0_721").attr("class")+" required");
jQuery("input#user_0_722").attr("class",jQuery("input#user_0_722").attr("class")+" required");
jQuery("input#user_0_723").attr("class",jQuery("input#user_0_723").attr("class")+" required email");
jQuery("input#user_0_719").attr("class",jQuery("input#user_0_719").attr("class")+" required");
jQuery("input#user_0_720_one").attr("class",jQuery("input#user_0_720_one").attr("class")+" required");
jQuery("input#user_0_720_two").attr("class",jQuery("input#user_0_720_two").attr("class")+" required");

jQuery('input#metadata_field_select_1224_yes').next("label").css("padding-right","5px");

jQuery('input#metadata_field_select_1224_yes').click(function() {
  if(jQuery(this).attr("checked")){ 
    jQuery("label#terms_checkbox").css("visibility","hidden"); 
  }
  else { jQuery("label#terms_checkbox").css("visibility","visible");  }
});

jQuery("form#page_account_manager_1168").validate({
 rules: {
    user_0_720_one: {
      minlength: 6
    },
    user_0_720_two: {
      minlength: 6,
	  equalTo: "#user_0_720_one"
    }
  },
      submitHandler: function(form) {
if(jQuery("input#metadata_field_select_1224_yes").attr("checked")) {
   submit_form(jQuery("#page_account_manager_1168"));
}
else {
   jQuery("label#terms_checkbox").show();
   jQuery("label#terms_checkbox").css("visibility","visible"); 
   jQuery('input#metadata_field_select_1224_yes').focus();
}
      }
});



/* Edit Profile Form Validation
--------------------------------------------------------------*/

jQuery("form#main_form").removeAttr("onsubmit");

jQuery("li.firstname-profile input").attr("class",jQuery("li.firstname-profile input").attr("class")+" required");
jQuery("li.lastname-profile input").attr("class",jQuery("li.firstname-profile input").attr("class")+" required");
jQuery("li.email-profile input").attr("class",jQuery("li.firstname-profile input").attr("class")+" required email");

var password_one_original_name = jQuery("li.password-profile input").eq(0).attr("name");
var password_two_original_name = jQuery("li.password-profile input").eq(1).attr("name");

jQuery("li.password-profile input").eq(0).attr("id","password_one").attr("name","password_one");
jQuery("li.password-profile input").eq(1).attr("id","password_two").attr("name","password_two");

jQuery('#main_form').validate({
 rules: {
    password_two: {
      equalTo: "#password_one"
    }
  },
      submitHandler: function(form) {
         jQuery("#password_one").eq(0).attr("name",password_one_original_name);
         jQuery("#password_two").eq(0).attr("name",password_two_original_name);

      submit_form(jQuery('form#main_form'));
 }
});



/* eCommerce Form Validation
--------------------------------------------------------------*/

jQuery("p.card_name input").attr("class",jQuery("p.card_name input").attr("class")+" required");
// jQuery("p.card_number input").attr("class",jQuery("p.card_number input").attr("class")+" required creditcard");
jQuery("p.card_expiry select").eq(0).attr("class",jQuery("p.card_expiry select").eq(0).attr("class")+" required");
jQuery("p.card_expiry select").eq(1).attr("class",jQuery("p.card_expiry select").eq(1).attr("class")+" required");
jQuery("p.card_cv2 input").attr("class",jQuery("p.card_cv2 input").attr("class")+" required digits");

jQuery("p.billing_firstname input").attr("class",jQuery("p.billing_firstname input").attr("class")+" required");
jQuery("p.billing_lastname input").attr("class",jQuery("p.billing_lastname input").attr("class")+" required");
jQuery("p.billing_address1 input").attr("class",jQuery("p.billing_address1 input").attr("class")+" required");
jQuery("p.billing_city input").attr("class",jQuery("p.billing_city input").attr("class")+" required");
jQuery("p.billing_postcode input").attr("class",jQuery("p.billing_postcode input").attr("class")+" required");

var ecommerce_form = jQuery("div#e-commerce").parent();
jQuery(ecommerce_form).removeAttr("onsubmit");

ecommerce_form.validate({
      submitHandler: function(form) {
         jQuery("table#payment_gateway_sagepay_5527_card_table").css("visibility","visible");
         submit_form(ecommerce_form);
      }
});


/* Playlist - notes
--------------------------------------------------------------*/

jQuery("form.leave-note, .comment-list").hide();
jQuery('.display-notes').css('cursor','pointer');

jQuery('.playlist-note').click(function(){
      jQuery("." + jQuery(this).attr("id")).slideToggle("slow");
}); 

jQuery('.display-notes').mouseover(function(){
      $(this).css('color','#DB2330');
    }).mouseout(function(){
      $(this).css('color','#8C8C8C');
    });

jQuery('.display-notes').click(function(){
      var comment_list = jQuery(this).parents("ul:first").nextAll("ul.comment-list");
      jQuery(comment_list).slideToggle("slow");
});

  
/* Events Banner - landing page
--------------------------------------------------------------*/

var MAIN_BANNER = function(){return MAIN_BANNER;};
(function($){				
	MAIN_BANNER.newsCarousel = function(){
		$("#navbuttons").css("visibility", "visible");
		return MAIN_BANNER.carouselControls = $("#carousel ul").newsCarousel({
			navButtons: $("#navbuttons li"),
			transition: "fade"
		 });
	};
jQuery(function(){
		if(jQuery("#carousel ul").length){
			MAIN_BANNER.newsCarousel();
		        $("#car_1").attr("class", "on_car");
		}	
});

}).call(MAIN_BANNER, jQuery);


/* Upcoming Events - hide thumbnails
--------------------------------------------------------------*/

jQuery("#sub-menu ul.events-list").each(function(){
    var item = jQuery(this).find("li:eq(2)").nextAll();
    jQuery(item).find("a.img-link").remove();
    jQuery(item).css("padding-top","7px");
});

/* Events Calendar - display months names
--------------------------------------------------------------*/
jQuery(".calendar-content h3").each(function(){
   var date = jQuery(this).text();
   var month = date.toString().split("-")[1];
   month = parseFloat(month);
   var monthArray = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
   jQuery(this).text(monthArray[month]);
});

jQuery(".calendar div").removeClass("hover");
jQuery(".calendar .description").hide();

jQuery(".calendar h4").toggle(function() {
   	jQuery(this).parent().children(".description").slideDown();
	jQuery(".calendar h4").not(this).parent().children(".description").hide();    
}, function() {
  	jQuery(this).parent().children(".description").slideUp();
});

/* Events - next/prev
--------------------------------------------------------------*/

if ( typeof(nextPreviousArray) !== "undefined" ) {
    for(var i=0;i<=nextPreviousArray.length;i++) {
       if (nextPreviousArray[i] === currentAssetUrl) {
          if (nextPreviousArray[i-1] !== '') {
             jQuery('.pagination').append('<a href="' + nextPreviousArray[i-1] + '" class="prev"><span>Previous Event</span></a>').hide().fadeIn('slow');
             jQuery('.editionsnav').append('<a href="' + nextPreviousArray[i-1] + '" class="prev"><span>Previous Edition</span></a>').hide().fadeIn('slow');
          }
          if (nextPreviousArray[i+1] !== '') {
             jQuery('.pagination').append('<a href="' + nextPreviousArray[i+1] + '" class="next"><span>Next Event</span></a>').hide().fadeIn('slow');
             jQuery('.editionsnav').append('<a href="' + nextPreviousArray[i+1] + '" class="next"><span>Next Edition</span></a>').hide().fadeIn('slow');
          }
       }
    }
}

function addtobasket(btnID, inputID) {
            var tgt = "http://tickets.intelligencesquared.com/addtocart.aspx?productid=";
            tgt = tgt + document.getElementById(inputID).getAttribute("productid");
            tgt = tgt + "&amp;variantid=";
            tgt = tgt + document.getElementById(inputID).getAttribute("variantid");
            tgt = tgt + "&amp;quantity="
            tgt = tgt + document.getElementById(inputID).value;
            tgt = tgt + "&amp;TB_iframe=true&amp;height=450&amp;width=700"
            document.getElementById(btnID).href = tgt;
}

/* override default browser scrollBar 
--------------------------------------------------------------*/

jQuery('ul.related-content-listing').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});
jQuery('div.calendar-content').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});
jQuery('p.quick-debate-sumpara').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});
jQuery('p.quick-debate-speaker-bio').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});

jQuery('div.event-section-box ul').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});
jQuery('div.event-section-box-odd ul').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});
jQuery('div.event-section-box-even ul').jScrollPane({scrollbarWidth:7,topCapHeight:5,bottomCapHeight:5,dragMaxHeight:100});


