jQuery(document).ready(function(){
    
      // LATEST NEWS SLIDER
      jQuery("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 6000, true);
      
      // STADIUM PLAN LIGHTBOX
      jQuery("a[rel^='prettyPhoto']").prettyPhoto();
      
      // BIOGS TABLE COLGROUPS
      jQuery('<colgroup class="firstCol"></colgroup><colgroup class="thin"></colgroup></colgroup><colgroup class="thin"></colgroup></colgroup><colgroup class="thin"></colgroup></colgroup><colgroup class="thin"></colgroup></colgroup><colgroup class="thin"></colgroup></colgroup><colgroup class="thin"></colgroup>').prependTo("#c4417 .players_listing .full_details table");
      
      // AUTO CLEAR FOR SUBSCRIBE TEXTFIELD
      jQuery('#mce-EMAIL').autofill({ value: 'ENTER EMAIL ADDRESS...', defaultTextColor: '#999999', activeTextColor: '#000' });
      

	// Mail chimp scripts

    // delete this script tag and use a "div.mce_inline_error{ XXX !important}" selector
    // or fill this in and it will be inlined when errors are generated
    var mc_custom_error_style = '';

	try {
		var jqueryLoaded=jQuery;
		jqueryLoaded=true;
	} catch(err) {
		var jqueryLoaded=false;
	}
	if (!jqueryLoaded) {
		var head = document.getElementsByTagName('head')[0];
		var script= document.createElement('script');
		script.type= 'text/javascript';
		script.src= 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js';
		head.appendChild(script);    
	}
	
                  var fnames = new Array();var ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='MMERGE2';ftypes[2]='text';var err_style = '';
                  try{
                      err_style = mc_custom_error_style;
                  } catch(e){
                      err_style = 'margin: 1em 0 0 0; padding: 1em 0.5em 0.5em 0.5em; background: ERROR_BGCOLOR none repeat scroll 0% 0%; font-weight: bold; float: left; z-index: 1; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: ERROR_COLOR;';
                  }
                  var head = document.getElementsByTagName('head')[0];
                  var style = document.createElement('style');
                  style.type= 'text/css';
                  if (style.styleSheet) {
                    style.styleSheet.cssText = '.mce_inline_error {' + err_style + '}';
                  } else {
                    style.appendChild(document.createTextNode('.mce_inline_error {' + err_style + '}'));
                  }
                  head.appendChild(style);
                  jQuery(document).ready( function(jQuery) {
                    var options = { errorClass: 'mce_inline_error', errorElement: 'div', onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
                    var mce_validator = jQuery("#mc-embedded-subscribe-form").validate(options);
                    options = { url: 'http://bristolrugby.us2.list-manage.com/subscribe/post-json?u=0415f07f81efd03c43387e066&id=0f7888fb67&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
                                  beforeSubmit: function(){
                                      jQuery('#mce_tmp_error_msg').remove();
                                      jQuery('.datefield','#mc_embed_signup').each(
                                          function(){
                                              var txt = 'filled';
                                              var fields = new Array();
                                              var i = 0;
                                              jQuery(':text', this).each(
                                                  function(){
                                                      fields[i] = this;
                                                      i++;
                                                  });
                                              jQuery(':hidden', this).each(
                                                  function(){
                                                      if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
                                                            this.value = '';
                                                                        } else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
                                                            this.value = '';
                                                                        } else {
                                                            this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
                                                        }
                                                  });
                                          });
                                      return mce_validator.form();
                                  }, 
                                  success: mce_success_cb
                              };
                    jQuery('#mc-embedded-subscribe-form').ajaxForm(options);
                  
                  });

        
//         
//         // TWITTER FEED
//         jQuery(".tweet").tweet({
//             join_text: null,
//             username: "Bristol_RFC",
//             avatar_size: 48,
//             count: 1,
//             loading_text: "loading tweets..."
//         });
              
			 jQuery('.tweet').jtwt({
				 count : 1, // The number of displayed tweets. Default is 5.
				 username : 'Bristol_RFC', // Your username on Twitter
				 image_size : 48, // The size of your avatar. 0 means "no avatar". Default is 48.
				 loader_text : 'loading tweets', // The text which be displayed by loading the tweets.
				 convert_links : 1 // Choose if the links and replies in your tweets to be converted in clickable links. 0 means no, 1 means yes.
			 });

        
        
        
        // LEAGUE TABLE
        jQuery('#c4854 .home-fixtures table').wrap('<div class="leagueTableWrap"/>');
        jQuery('#c4854 .home-fixtures table').before('<h3 class="leagueTitle"></h3>');
        jQuery('#c4854 .home-fixtures table').after('<a href="http://news.bbc.co.uk/sport1/hi/rugby_union/tables/4777167.stm" class="leagueLink" target="_blank">See full table</a>');
        jQuery('#c4854 .home-fixtures table').prepend('<colgroup class="wideCol"></colgroup><colgroup class="thinCol"></colgroup><colgroup class="thinCol"></colgroup><colgroup class="thinCol"></colgroup><colgroup class="thinCol"></colgroup><colgroup class="thinCol"></colgroup>');
        //jQuery('#c4854 .home-fixtures table tr:nth-child(2)').css({ 'font-weight' : 'bold' });
    
    
    /*    
        The code for this has been placed within the news details template /assets/templates/modules/news/news_blog/news_blog_details.twig.html
    
        // ADDING BACK BTN TO NEWS ARTICLE
        jQuery('<a href="#" id="pageBack">Back</a>').appendTo('.news .details .article');    
        
        jQuery('#pageBack').click(function(){       
        
            parent.history.back();
            return false;
                  
        });            
    */
	
});
