// GOLF ROTATING TOP STORY

rotateTopStory = function(){
	clearInterval(window.golfinterval)

			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.golfinterval = setInterval("rotateTopStory()",7000);
																			   
																				   
																				   

	
	}

topStory = function(){
	$('.count').html("1 of 5");
	$('#story-container').prepend("<div class='TStimer'> </div>");
	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.golfinterval)
			//$('.TStimer').css('width',1);
		}
		return false;
													   
})

}

topStory();

// GOLF OPTIONAL OPEN / CLOSE PROMO PANEL

/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * jFlow
 * Version: 1.2 (July 7, 2008)
 * Requires: jQuery 1.2+
 */
(function(A){A.fn.jFlow=function(K){var B=A.extend({},A.fn.jFlow.defaults,K);var G=Math.floor(Math.random()*11);var I=B.controller;var C=B.slideWrapper;var H=B.selectedWrapper;var J=0;var E=A(I).length;var F=function(M,L){A(B.slides).children().css({overflow:"hidden"});A(B.slides+" iframe").hide().addClass("temp_hide");A(B.slides).animate({marginLeft:"-"+(L*A(B.slides).find(":first-child").width()+"px")},B.duration*(M),B.easing,function(){A(B.slides).children().css({overflow:"auto"});A(".temp_hide").show()})};A(this).find(I).each(function(L){A(this).click(function(){if(A(B.slides).is(":not(:animated)")){A(I).removeClass(H);A(this).addClass(H);var M=Math.abs(J-L);F(M,L);J=L}})});A(B.slides).before('<div id="'+C.substring(1,C.length)+'"></div>').appendTo(C);A(B.slides).find("div").each(function(){A(this).before('<div class="jFlowSlideContainer"></div>').appendTo(A(this).prev())});A(I).eq(J).addClass(H);var D=function(L){A(C).css({position:"relative",width:B.width,height:B.height,overflow:"hidden"});A(B.slides).css({position:"relative",width:A(C).width()*A(I).length+"px",height:A(C).height()+"px",overflow:"hidden"});A(B.slides).children().css({position:"relative",width:A(C).width()+"px",height:A(C).height()+"px","float":"left",overflow:"auto"});A(B.slides).css({marginLeft:"-"+(J*A(B.slides).find(":eq(0)").width()+"px")})};D();A(window).resize(function(){D()});A(B.prev).click(function(){if(A(B.slides).is(":not(:animated)")){var L=1;if(J>0){J--}else{J=E-1;L=J}A(I).removeClass(H);F(L,J);A(I).eq(J).addClass(H)}});A(B.next).click(function(){if(A(B.slides).is(":not(:animated)")){var L=1;if(J<E-1){J++}else{J=0;L=E-1}A(I).removeClass(H);F(L,J);A(I).eq(J).addClass(H)}})};A.fn.jFlow.defaults={controller:".jFlowControl",slideWrapper:"#jFlowSlide",selectedWrapper:"jFlowSelected",easing:"swing",duration:400,width:"100%",prev:".jFlowPrev",next:".jFlowNext"}})(jQuery);

$(document).ready(function(){
						   
	$(".promo-panel .delete").click(function(){
		$(this).parents(".promo-panel").animate({ opacity: 'hide' }, "slow");
	});

});

$(document).ready(function(){

	$("#myController").jFlow({
		slides: "#mySlides",
		controller: ".jFlowControl", // must be class, use . sign
		slideWrapper : "#jFlowSlide", // must be id, use # sign
		selectedWrapper: "jFlowSelected",  // just pure text, no sign
		width: "918px",
		height: "192px",
		duration: 400,
		prev: ".jFlowPrev", // must be class, use . sign
		next: ".jFlowNext" // must be class, use . sign
	});
	
});

function tabs(p){

			$(p+" ul.ms-tabs-tablinks li:first").addClass('ms-tabs-on');
	
			$(p+" .ms-tabs-tablinks li").click(function(){
									   
				$(this).parents('.ms-tabs-tablinks').find('li').removeClass('ms-tabs-on');
				$(this).addClass('ms-tabs-on');
				
				var tablink=$(this).find('a').attr('href');
			
				var tablink2=tablink.split('#')[1];
				tablink2=tablink2.slice(0,9);
				
				
				$(".ms-tabs-con div[id*='"+tablink2+"']").hide();
				$(".ms-tabs-con div"+tablink).show()
				return false;
			})
		

	}

tabs("#ms-tabs-box1");
tabs("#ms-tabs-box2");
tabs("#ms-tabs-box-fun");


//TOOLTIP CORE
/*
 * Copyright (c) 2006 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */
$.fn.ToolTip = function(bgcolour, fgcolour)
{
	this.mouseover(
		function(e)
		{
			if((!this.title && !this.alt) && !this.tooltipset) return;
			// get mouse coordinates
			// based on code from http://www.quirksmode.org/js/events_properties.html
			var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
			var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
			mouseX += 10;
			mouseY += 10;
			bgcolour = bgcolour || "#eee";
			fgcolour = fgcolour || "#ddd";
			// if there is no div containing the tooltip
			if(!this.tooltipdiv)
			{
				// create a div and style it
				var div = document.createElement("div");
				this.tooltipdiv = div;
				$(div).css(
				{
					border: "1px outset #ddd",
					padding: "5px 8px",
					backgroundColor: bgcolour,
					color: fgcolour,
					position: "absolute",
					opacity:"0.9",
					filter:"alpha(opacity=90)"
				})
				// add the title/alt attribute to it
				.html((this.title || this.alt));
				this.title = "";
				this.alt = "";
				$("body").append(div);
				this.tooltipset = true;
			}
			$(this.tooltipdiv).show().css({left: mouseX + "px", top: mouseY + 3 + "px"});
		}
	).mouseout(
		function()
		{
			if(this.tooltipdiv)
			{
				$(this.tooltipdiv).hide();
			}
		}
	);
	return this;
}

//ACCORDIAN
msAccordian = function(a){

	if($('#'+a).find('h2.ms-acc-open')[0]){
		$('#'+a).find('h2.ms-acc-open').addClass('ms-acc-on');
		$('#'+a).find('h2.ms-acc-open').next('div.ms-acc-con').show();
	}
	else{
		$('#'+a).find('h2:first').addClass('ms-acc-on');
		$('#'+a).find('h2:first').next('div.ms-acc-con').show();
	}
	
	$('#'+a).find('h2').click(function(){
	
		$('#'+a).find('h2').removeClass('ms-acc-on');
		$(this).addClass('ms-acc-on');
		if($(this).next('div.ms-acc-con').css('display')=="block"){return false};
		var b = $(this).next('div.ms-acc-con');
		$('div.ms-acc-con:visible').slideUp(450,function(){b.slideDown(450)});
	})
}

$().ready(function() {

	msAccordian('ms-accordian-1');

 });

pop = function() {
		$("a[rel^='pop']").click(function(){
			var pA = $(this).attr('rel');
			pA=pA.split('|');
			switch(pA[0]){
				case 'popUp':
					var pW = pA[1];
					var pH = pA[2];
					var pR = pA[3];
					var pS = pA[4];
				break;
			}
			
			var pL = Math.floor((screen.width-pW)/2);
			var pT = Math.floor((screen.height-pH)/2);
			window.open($(this).attr('href'),pA[0],'width='+pW+',height='+pH+',top='+pT+',left='+pL+' ,resizable='+pR+' ,scrollbars='+pS+'');
			return false;
		})
	},

pop();


//INITIATE TOOLTIP
$(document).ready(function(){$(".ms-course-more img, .profiles img").ToolTip("#fff", "#000");});

// nav dropdown fix for IE6
$('li.nav-more, li.ms-nav-more').hover(function() { $('ul', this).css('display', 'block'); }, function() { $('ul', this).css('display', 'none'); });
// gallery promo
$(".gallery-thumbs img").mouseover(function () {$('.current').removeClass("current");$(this).addClass("current");return false;});
$(".gal-info2, .gal-info3").hide();$(".gallery-thumbs img.first").mouseover(function () {	$(".gal-info2, .gal-info3").hide();$(".gal-info1").show();});
$(".gallery-thumbs img.second").mouseover(function () {$(".gal-info1, .gal-info3").hide();$(".gal-info2").show();});
$(".gallery-thumbs img.third").mouseover(function () {$(".gal-info1, .gal-info2").hide();$(".gal-info3").show();});

// top (dark) promo area open/close
$(".btn-slide").click(function(){$("#panel").slideToggle("slow");$(this).toggleClass("active"); return false;});

// 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;
});

/* article bookmark ul */
htmlStuff = function(){
$('.art-bookmark').prepend("<a class='art-saveto' href='#'>Share it:</a>");
		$(".art-bookmark").hover(
			function(){
				$(this).find("ul").show().css('z-index','4');
				$(this).find('a').addClass('pr-bookmarks')},
				
			function(){
				$(this).find("ul").hide();
				$(this).find('a').removeClass('pr-bookmarks')
			});
};
htmlStuff();

// write in js styles 
document.write ("<style type='text/css'>.js-hdn{display:none;} </style>")// JavaScript Document
