//FOR LEFT NAV BELOW in doc.ready section
  var loc = window.location.pathname;
  var leftnavhref = $("leftnav_main ul li").attr("href");

//############ doc.ready stuff ###########//
$(document).ready(function() {

//LEFT NAV
/*   Uses: for the left navigation for the following pages:
     Sports Winter
     Sport Summer
     TeamGB
     BOA
     Olympics
   How is it implemented: 
   1. The html module is added to the page in the Eos admin screen
   2. Through webdav the html markup is modified to include the html markup for the links and sublinks
   3. The code below will expand the sublinks when the main link is selected
   
   document.write(window.location.href); <- to get current url
*/
  $(".leftnav_sub").hide();
  
    $(".leftnav_main").each(function() {
      var link = $(this).attr("href");
        if(link == loc && loc != '/') {
          $(this).parents('ul').show();
          $(this).addClass("active");
        }
    });
    
    $(".leftnav_sub li a").each(function() {
      var link = $(this).attr("href");
        if(link == loc && loc != '/') {
          $(this).parents('.leftnav_sub').show();
          $(this).parents('.leftnav_ul').show();
          $(this).addClass("active");
        }
    });
  
  if($('.winter').length != 0 ) {  
  	$(".summer_menu").hide();
  }
    if($('.summer').length != 0 ) { 
       $(".winter_menu").hide();
  }
  
  $(".leftnav_main").click(function(e){
    if($(this).attr("href") == '#'){
      e.preventDefault();
    }
    $(this).next(".leftnav_sub").slideToggle(200);
    $(this).next(".leftnav_sub li a").addClass("active");
  });

  $(".leftnav").click(function(e){
    e.preventDefault();
 //   $(".leftnav_ul").hide();
    $(this).next(".leftnav_ul").slideToggle(200);
  });
  
  
//FOR "JOIN US" MODULE WITH MEMBER COUNT
//this splits up the member count and adds a span around each integer
var txt = $('.member_count').text().split('');
var output = ""
for(var x=0;x<txt.length;x++) {
    output = output + "<span>"+txt[x]+"</span>"
}
$('.member_count').html(output);

//this takes the value of each member count span and adds that to the classname
$('.member_count span').each(function(index) {
  var classname = $(this).text();
  $(this).addClass('c'+classname);
  });

//PHOTO & VIDEO GALLERY
//photo gallery - add active class on click & remove from siblings
  $('#photo_gallery .list li:first').addClass('active');
  $('#photo_gallery .list li').click( function() {
    $(this).addClass('active').siblings().removeClass('active');
  });
  $('#photo_gallery_large .list li:first').addClass('active');
  $('#photo_gallery_large .list li').click( function() {
    $(this).addClass('active').siblings().removeClass('active');
  });
//round gallery corners
  $('#photo_gallery .list .gallery_photo').corner('6px');
  $('#photo_gallery .photolist .gallery_img').corner('6px');
  $('#photo_gallery .photolist').corner('8px');
  $('#video_gallery .playlist').corner('bottom 8px');
  $('#news_blog .imgDisplay').corner('bottom 8px');

//round gallery corners - large
  $('#photo_gallery_large .list .gallery_photo').corner('6px');
  $('#photo_gallery_large .photolist .gallery_img').corner('6px');
  $('#photo_gallery_large .photolist').corner('8px');
  $('#video_gallery_large .playlist').corner('bottom 8px');
  
//activate easySlider
  $('#video_gallery .list').easySlider();
  $('#photo_gallery .list').easySlider();
  $('#video_gallery_large .list').easySlider_large();
  $('#photo_gallery_large .list').easySlider_large();

//NEWS PAGE
//blog listing img placement
function showImg( str ) {
    return '<img src="' + str + '"\/>';
  };
  $('#news_blog li.article .description').find(':not(textarea)').replaceText( /http:\/\/.+\/.+?\.(jpg|jpeg|png|tiff|gif|bmp)/gi, showImg );
  $('#news_blog li.article .description').each(function() {
    $(this).find('img:not(:first)').remove(); 
    $(this).find('img').prependTo($(this).parent());
    $(this).parent().find('img').wrap('<div class="imgDisplay"></div>');
    $("p").filter( function() {
      return $.trim($(this).html()) == '';
      }).remove();
    $(this).find("p:last").addClass("last");
    });
  $('#news_blog li.article:first').addClass("first_post");
  $('#mini_blog_list li.article:first').addClass("first_post");

//MEMBER DETAIL PAGE
  //add span to quote so end quote will follow text
  $('#q4825824 .value').wrapInner('<span />');
  //add title (name) to top of moduleContainer2
  $('#member_detail .member .txt .title').clone().appendTo('#blog_listing-4534030 .head');
//member_listing - round corners of athlete thumbnails
  $('.member_listing #athletes li .img').corner('8px');

//ROUND CORNERS (used with jquery corners plugin (see jquery.plugins.js))
$('.one #moduleContainer2').wrapInner("<div class='inner' />");
	$('.one #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.summer #moduleContainer1').wrapInner("<div class='inner' />");
	$('.summer #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round tl bl 14px");

	$('.summer #moduleContainer2').wrapInner("<div class='inner' />");
	$('.summer #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.winter #moduleContainer1').wrapInner("<div class='inner' />");
	$('.winter #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round tl bl 14px");

	$('.winter #moduleContainer2').wrapInner("<div class='inner' />");
	$('.winter #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.two_col #moduleContainer1').wrapInner("<div class='inner' />");
	$('.two_col #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");

	$('.two_col #moduleContainer2').wrapInner("<div class='inner' />");
	$('.two_col #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.photo_video #moduleContainer1').wrapInner("<div class='inner' />");
	$('.photo_video #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round tl bl 14px");

	$('.photo_video #moduleContainer2').wrapInner("<div class='inner' />");
	$('.photo_video #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.three_col #moduleContainer1').wrapInner("<div class='inner' />");
	$('.three_col #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round tl bl 14px");

	$('.three_col #moduleContainer2').wrapInner("<div class='inner' />");
	$('.three_col #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.olympics #moduleContainer1').wrapInner("<div class='inner' />");
	$('.olympics #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round tl bl 14px");

	$('.olympics #moduleContainer2').wrapInner("<div class='inner' />");
	$('.olympics #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.BOA #moduleContainer1').wrapInner("<div class='inner' />");
	$('.BOA #moduleContainer1 .inner').corner ("round 8px").parent().css('padding','8px').corner("round tl bl 14px");

	$('.BOA #moduleContainer2').wrapInner("<div class='inner' />");
	$('.BOA #moduleContainer2 .inner').corner ("round 8px").parent().css('padding','8px').corner("round 14px");
	
	$('.comments .input.textarea textarea').corner('8px');
  $('.content li.comment .img').corner('6px');
  
//FOOTER
  //link for partner flash object
  $('.foot_bot').click(function() {
    window.location.href = "/partners/";
  });
  //Site Map collapse/expand
  $('a.sitemap').click(function() {
    $('.footCollapse').slideToggle(500);
    $('a.sitemap.open').toggle();
    $('a.sitemap.close').toggle();
  });

//ABOUT AND DETAILS TABS IN SPORTS
//works with functions below (out of doc.ready section)
//add page_title class to the h3
  if($('body#home').length == 0 || $('body#blog').length == 0 || $('body#blog_detail').length == 0){
  $('#moduleContainer2 .module .head h3:first').addClass('boa_sports_title');
  }
 if($('.summer').length != 0 || $('.winter').length != 0 || $('.olympics').length != 0) { 

// code for the About and Details tab
  $("#moduleContainer4").hide();
  $('#moduleContainer2 .module .head:first').append('<div class="tab_menu"> \
   <ul> \
	<li><a href="javascript:showFeature1()">About</a></li> \
	<li><a href="javascript:showFeature2()">Details</a></li> \
   </ul> \
   </div>'); 
   }   
		
});

//ABOUT AND DETAILS TABS IN SPORTS
//works with jquery above (in doc.ready section)

function showFeature1() {
  $('#moduleContainer3').css("display", "block");
  $('#moduleContainer4').css("display", "none");
}
function showFeature2() {
  $('#moduleContainer3').css("display", "none");
  $('#moduleContainer4').css("display", "block");
}

//SIFR setup

var avantmed = { src: '../js/avantgarde.swf' };
var avantmed = { src: 'http://static.global.ciscoeos.com/1299181981/zipupload/6db/edf/fc9410521d825809fef9222dea/js/avantgarde.swf' };

var avantbold = { src: '../js/avantbold.swf' };
var avantbold = { src: 'http://static.global.ciscoeos.com/1299181148/zipupload/6db/edf/fc9410521d825809fef9222dea/js/avantbold.swf' };

var avantbook = { src: '../js/avantbook.swf' };
var avantbook = { src: 'http://static.global.ciscoeos.com/1299182484/zipupload/6db/edf/fc9410521d825809fef9222dea/js/avantbook.swf' };

  sIFR.activate(avantmed, avantbold);
  
  sIFR.replace(avantmed, {
    selector: '#moduleContainer1 .inner .module .head',
    wmode: 'transparent',
    fitExactly: true,
    tuneHeight: -5,
    forceSingleLine:true,
    sFlashVars:'underline=false',
    css: [
      '.sIFR-root {font-size:24px; color: #003f77;}'
      , 'a:hover {cursor: pointer; color: #FF0000;}'
      , 'a {text-decoration: none;color: #003f77;}'
    ]				
  });	
  
  sIFR.replace(avantbold, {
    selector: '#moduleContainer2 .inner .module .head h3.boa_sports_title',
    wmode: 'transparent',
    fitExactly: true,
    tuneHeight: -5,
    forceSingleLine:true,
    css: [
      '.sIFR-root {font-size:22px; color: #4c4c4c;}'
    ]				
  });	
  
  sIFR.replace(avantbook, {
    selector: '#moduleContainer3 .module .content .head h3',
    wmode: 'transparent',
    fitExactly: true,
    tuneHeight: -5,
    forceSingleLine:true,
    sFlashVars:'underline=false',				
    css: [
      '.sIFR-root {font-size:12px; color: #4c4c4c;}'
    ]				
  });				
			
