// nav dropdown fix for IE6
$('li.nav-more, li.ms-nav-more').hover(function() { $('div', this).css('display', 'block'); }, function() { $('div', this).css('display', 'none'); });


		$('div.team-select').hover(function(){
			$(this).click(function(){
				$(this).find('ul:first').show();})},function(){
					$(this).find('ul:first').hide()
			}
		);



// tab box
tabs=function(p){
		
			$(p+" .anchors li:first").addClass('tabs-selected');
			$(p+" .anchors li").click(function(){
				$(this).parents('.anchors').find('li').removeClass('tabs-selected');
				$(this).addClass('tabs-selected');
				var tablink=$(this).find('a').attr('href');
				tablink=tablink.split('#')[1];
				$(this).parents('.tt-tabs').find("div[id^='"+tablink.slice(0,3)+"']").hide();
				$(this).parents('.tt-tabs').find("#"+tablink).show();
				$(this).parents('.tt-clip-tabs').find("div[id^='"+tablink.slice(0,3)+"']").hide();
				$(this).parents('.tt-clip-tabs').find("#"+tablink).show();				
				return false;
			})
		
}


tabs("#tt-tabs");
tabs("#tt-clip-tabs");


// TEAMTALK ROTATING TOP STORY

rotateTopStory = function(){
	clearInterval(window.ttinterval)

			var p=1;													   
			var pos = $('#story-container .story-nav li').index($('#story-container .story-nav li.story-on')[0]);
		
			if(pos==4){pos=-1;}
			
			$('#story-container .story-nav li').eq(pos+1).trigger('click','x');
			$('.TStimer').css('width',"1px");
			window.ttinterval = setInterval("rotateTopStory()",7000);
	}

topStory = function(){
	$('.count').html("1 of 5");
	
	var first = $('#story-container li.story-content:eq(4)').clone();

	$('#story-container .story-scroll').prepend(first).css({marginLeft:-496});
	
	rotateTopStory();
	$('#story-container .story-nav li').click(function(click,p){

		var pos = $('#story-container .story-nav li').index($(this))
		pos=pos;
		$('.count').html((pos+1) +" of 5"); 
	
		if(pos==4 && p=='x'){
			
			$('#story-container .story-scroll').animate({marginLeft:((496*pos)*-1)-496},800,function(){
				
				$('#story-container .story-scroll').css({'marginLeft':0})
			});
		}
		
		else{
			$('#story-container .story-scroll').animate({marginLeft:((496*pos)*-1)-496},{duration:800,queue:false});
		
		}
		
		
		$('#story-container .story-nav li').removeClass('story-on');
		$(this).addClass('story-on');
		if(p!='x'){
			clearInterval(window.ttinterval)
			//$('.TStimer').css('width',1);
		}
		return false;
													   
})

}

topStory();

// TEAMTALK ACCORDIONS - stats (tables/fixtures/results) & features (your say/paper talk/rumour room)

	$(".tt-accordion h3:first").addClass("active");
	$(".tt-accordion div:not(:first)").hide();

	$(".tt-accordion h3").click(function(){
		$(this).next("div").show()
		.siblings("div:visible").hide();
		$(this).addClass("active");
		$(this).siblings("h3").removeClass("active");
	});
	
	
	$(".tt-accordion2 h3:first").addClass("active");
	$(".tt-accordion2 div:not(:first)").hide();
	/*$(".tt-accordion2 div.papertalk").show();*/
	

	$(".tt-accordion2 h3").click(function(){
		$(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
		$(this).addClass("active");
		$(this).siblings("h3").removeClass("active");
	});	

	$(".tt-accordion3 h3:first").addClass("active");
	$(".tt-accordion3 div:not(:first)").hide();

	$(".tt-accordion3 h3").click(function(){
		$(this).next("div").show()
		.siblings("div:visible").hide();
		$(this).addClass("active");
		$(this).siblings("h3").removeClass("active");
	});
	
	

// bookmark hover
$(".share-links a").hover(function() {
	$(this).next("em").show(); /*.animate({opacity: "show", top: "-75"}, "slow");*/
}, function() {
	$(this).next("em").hide(); /*.animate({opacity: "hide", top: "-85"}, "fast");*/
});

// generic tooltip
this.tooltip = function() {    
    this.xOffset = 10; // x distance from mouse
    this.yOffset = 20; // y distance from mouse       
    
    $(".tooltip").unbind('hover','mousemove').hover(
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            $('body').append( '<p id="tooltip">' + this.t + '</p>' );
            $('p#tooltip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
        },
        function() {
            this.title = this.t;
            $("p#tooltip").fadeOut("slow").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $("p#tooltip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
    
};

tooltip(); 


	
// article pic switcher
$(".article-pic-caption span").append('<em></em>')
$(".thumbs a").click(function(){
	var largePath = $(this).attr("href");
	var largeAlt = $(this).attr("title");
	$("#largeImg").attr({ src: largePath, alt: largeAlt });
	$(".article-pic-caption span").html("" + largeAlt + ""); return false;
});	

// comment reply form function
$(".comment-reply").click(function(){
	$(this).parents('.comment').find('.reply-form').toggle();
	return false;
});

$('.tt-menu .tt-menuul > li').hover(function(){
	var offset = $('.tt-wrap').offset().left;
	
	var overlay = $(this).find('.tt-menu-overlay');
	if(overlay[0]){
		$(this).find('a').addClass('overlayhover')
		overlay.css('left',offset+5);
		overlay.show();
	}


},function(){
	
$(this).find('.tt-menu-overlay').hide();
$(this).find('a').removeClass('overlayhover');
})

// photo-component function
configGallery=function(el, galXML) {
		var newHTML = "";
		$.ajax({
		    url: galXML,
		    dataType: 'xml',
		    timeout: 2000,
		    success: function(xml){
				
				$(xml).find("ARTICLE").each(function(i) {
				
					if (i < 4) {
						newHTML += "<li><a href='" + $(this).attr("link") + "'><img src='" + $(this).attr("galPicThumb") + "' width='68' height='60'><h4>" + $(this).find("HLHEAD").text() + "</h4><p>" + $(this).find("LLSNIPPET").text() + "</p></a></li>";
					}
					
					if(i==0){
						galh4 = $(this).find("HLHEAD").text();
						galp = $(this).find("LLSNIPPET").text();
					}
				
				});
				
				$("#tt-photo-box1 .tt-photo-gallery").html(newHTML);
				
				$(el).find('li:first a').addClass('highlight');
				$(el).find('.tt-photo-box-thumbs span').html("<h4>"+galh4+"</h4><p>"+galp+"</p>");
				
				$(el+ ' ul.tt-photo-gallery li a').mouseover(function(){
					$(el+ ' ul.tt-photo-gallery li a').removeClass('highlight');
					$(this).addClass('highlight');		
					var h4 = $(this).find('h4').html();
					var p = $(this).find('p').html();
					$(el).find('.tt-photo-box-thumbs span').html("<h4>"+h4+"</h4><p>"+p+"</p>");
					
				})
		    }
		})
		
	}
	





$(".tt-home-promo").hover(function(){
$(this).find('p.anim').animate({top:90},{queue:false})
},function(){
$(this).find('p.anim').animate({top:184},{queue:false})
})

$("ul.tt-news-tabs-tablinks li:first").addClass('tt-news-tabs-on');

$(".tt-news-tabs-tablinks li").click(function(){
				   
$(this).parents('.tt-news-tabs-tablinks').find('li').removeClass('tt-news-tabs-on');
$(this).addClass('tt-news-tabs-on');

var tablink=$(this).find('a').attr('href');

var tablink2=tablink.split('#')[1];
tablink2=tablink2.slice(0,9);


$(".tt-news-tabs-con div[id*='"+tablink2+"']").hide();
$(".tt-news-tabs-con div"+tablink).show()
return false;
})

tabs("#tt-news-tabs-box1");
