function calculate(a,b,c) {
	d = (a+b)*c;
	return d;
}
$(document).ready(function(){
	$('body').css('visibility','visible');
	var first = 0;
	var speed = 700;
	var pause = 3500;
	
		function removeFirst(){
			first = $('ul#listticker li:first').html();
			$('ul#listticker li:first')
			.animate({opacity: 0}, speed)
			.fadeOut('slow', function() {$(this).remove();});
			addLast(first);
		}
		
		function addLast(first){
			last = '<li style="display:none">'+first+'</li>';
			$('ul#listticker').append(last)
			$('ul#listticker li:last')
			.animate({opacity: 1}, speed)
			.fadeIn('slow')
		}
	
	interval = setInterval(removeFirst, pause);	
	var adcarousel = {
		'default1' : {
			0 : {'altImage' : 'img/Brooks.jpg', 'height' : '100', 'width' : '230'},
			1 : {'altImage' : 'img/casio.jpg', 'height' : '48', 'width' : '230'},
			2 : {'altImage' : 'img/mizuno.jpg', 'height' : '100', 'width' : '230'},
			3 : {'altImage' : 'img/challenge.png', 'height' : '39', 'width' : '230'},
			4 : {'altImage' : 'img/shotz.jpg', 'height' : '96', 'width' : '230'},
			5 : {'altImage' : 'img/Asics 2006.jpg', 'height' : '73', 'width' : '230'},
			6 : {'altImage' : 'img/polar.jpg', 'height' : '64', 'width' : '230'},
			7 : {'altImage' : 'img/parmelia.jpg', 'height' : '61', 'width' : '230'},
			8 : {'altImage' : 'img/runnersworld.jpg', 'height' : '42', 'width' : '230'},
			9 : {'altImage' : 'img/Kids2009logo.jpg','height' : '100', 'width' : '230'}
		}
	};
	var pos = 0;
	var maxpos = 9;
	$(".adrotate img").eq(1).everyTime(5000, 'mitimer1', function() {
		$(this).slideToggle("slow");
		this.setAttribute('src',adcarousel['default1'][pos]['altImage']);
		this.setAttribute('height',adcarousel['default1'][pos]['height']);
		this.setAttribute('width',adcarousel['default1'][pos]['width']);
		$(this).slideToggle("slow");
		if(pos < maxpos)
			pos++;
		else
			pos = 0;
	});
	var pos = 0;
	var maxpos = 9;
	$(".adrotate img").eq(3).everyTime(5000, 'mitimer1', function() {
		$(this).slideToggle("slow");
		this.setAttribute('src',adcarousel['default1'][pos]['altImage']);
		this.setAttribute('height',adcarousel['default1'][pos]['height']);
		this.setAttribute('width',adcarousel['default1'][pos]['width']);
		$(this).slideToggle("slow");
		if(pos < maxpos)
			pos++;
		else
			pos = 0;
	});	
	$("ul#ticker01").liScroll(); 	
	$("#container > ul").tabs({ fx: { opacity: 'toggle', duration: 'fast'}, selected: 4});
	$("#resultscontainer > ul").tabs({ fx: { opacity: 'toggle', duration: 'fast'}});
	$("#programmecontainer > ul").tabs({ fx: { opacity: 'toggle', duration: 'fast'}});
	$("#previewscontainer > ul").tabs({ fx: { opacity: 'toggle', duration: 'fast'}});
	$("#FunRunsContainer > ul").tabs({ fx: { opacity: 'toggle', duration: 'fast'}});
	$("#photoscontainer > ul").tabs({ fx: { opacity: 'toggle', duration: 'fast'}});
	$(".accordion2 h2").eq(0).addClass("active");
	$(".accordion2 p").eq(0).show();
	$(".accordion2 h2").eq(2).addClass("active");
	$(".accordion2 p").eq(2).show();
	$(".accordion2 h2").eq(15).addClass("active");
	$(".accordion2 p").eq(15).show();
	$(".accordion2 h2").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h2").removeClass("active");
	});
	$(".tickertapelink").click(function(){
		var mainTabs = $("#container > ul");
		var subTabs = $("#FunRunsContainer > ul");
		var hrefattr = this['href'];
		var tabtoget = 0;
		var acctoget = 0;
		if(hrefattr.match("Marathon$")=="Marathon")
		{
			tabtoget = 2;
			acctoget = 16;
		}
		if(hrefattr.match("Challenge$")=="Challenge")
		{
			tabtoget = 0;
			acctoget = 12;
		}
		if(hrefattr.match("HalfMarathon$")=="HalfMarathon")
		{
			tabtoget = 1;
			acctoget = 13;
		}
		var accordionh2 = $(".accordion2 h2").eq(acctoget);
		mainTabs.tabs('select',11);
		subTabs.tabs('select',tabtoget);
		if(!accordionh2.hasClass('active'))
		{
			accordionh2.next("p").slideToggle("slow")
			.siblings("p:visible").slideUp("slow");
			accordionh2.toggleClass("active");
			accordionh2.siblings("h2").removeClass("active");
		}
		return false;
	})
	var viewport = {
		o: function() {
			if (self.innerHeight) {
				this.pageYOffset = self.pageYOffset;
				this.pageXOffset = self.pageXOffset;
				this.innerHeight = self.innerHeight;
				this.innerWidth = self.innerWidth;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				this.pageYOffset = document.documentElement.scrollTop;
				this.pageXOffset = document.documentElement.scrollLeft;
				this.innerHeight = document.documentElement.clientHeight;
				this.innerWidth = document.documentElement.clientWidth;
			} else if (document.body) {
				this.pageYOffset = document.body.scrollTop;
				this.pageXOffset = document.body.scrollLeft;
				this.innerHeight = document.body.clientHeight;
				this.innerWidth = document.body.clientWidth;
			}
			return this;
		},
		init: function(el) {
			$(el).css("left",50);
			$(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round($(el).height()/2)+ 10);
		}
	};
	var lastHeight;
	var lastWidth;
	$("img.floatoverimage").hover(
		function() {
			$(".simple_popup_div").remove();
			var strSimple = "<div class='simple_popup_div'><div class='simple_popup_inner'>";
			strSimple += "<img src='" + this.getAttribute('src') + "' alt='" + this.getAttribute('alt') + "'></img>";
			strSimple += "</div></div>";
			$("body").append(strSimple);
			viewport.init(".simple_popup_div");
			return false;
		},
		function() {
			$(".simple_popup_div").remove();
		}
	);
	var firstphoto = true; 
	$('li > a[href="#Photos"]').click(function() {
		/*if(firstphoto) {
			FOTO.Slider.reload('Christchurch2009');
			FOTO.Slider.preloadImages('Christchurch2009');
			FOTO.Slider.enableSlideshow('Christchurch2009');
			firstphoto=false;
		} */
		if(firstphoto)
		{
			var container = $('#BoldPark2010Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='BoldPark2010.html' ></iframe>");
			firstphoto=false;
		}
		return true;
	});
	var firstFriendship2009 = true;
	$('li > a[href="#Friendship2009Pane"]').click(function() {
		if(firstFriendship2009)
		{
			var container = $('#Friendship2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='Friendship2009.html' ></iframe>");
			firstFriendship2009=false;
		}
		return true;
	});
	var firstMatildaBay2009 = true;
	$('li > a[href="#MatildaBay2009Pane"]').click(function() {
		if(firstMatildaBay2009)
		{
			var container = $('#MatildaBay2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='MatildaBay2009.html' ></iframe>");
			firstMatildaBay2009=false;
		}
		return true;
	});
	var firstNewYearsEveRace = true;
	$('li > a[href="#NewYearsEveRacePane"]').click(function() {
		if(firstNewYearsEveRace)
		{
			var container = $('#NewYearsEveRacePane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='NewYearsEveRace.html' ></iframe>");
			firstNewYearsEveRace=false;
		}
		return true;
	});
	var firstPointWalter2009 = true;
	$('li > a[href="#PointWalter2009Pane"]').click(function() {
		if(firstPointWalter2009)
		{
			var container = $('#PointWalter2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='PointWalter2009.html' ></iframe>");
			firstPointWalter2009=false;
		}
		return true;
	});	
	var firstSwanTwilight2009 = true;
	$('li > a[href="#SwanTwilight2009Pane"]').click(function() {
		if(firstSwanTwilight2009)
		{
			var container = $('#SwanTwilight2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='SwanTwilight2009.html' ></iframe>");
			firstSwanTwilight2009=false;
		}
		return true;
	});
	var firstNeilHawkins2009 = true;
	$('li > a[href="#NeilHawkins2009Pane"]').click(function() {
		if(firstNeilHawkins2009)
		{
			var container = $('#NeilHawkins2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='NeilHawkins2009.html' ></iframe>");
			firstNeilHawkins2009=false;
		}
		return true;
	});	
	var firstDarlingtonHalf2009 = true;
	$('li > a[href="#DarlingtonHalf2009Pane"]').click(function() {
		if(firstDarlingtonHalf2009)
		{
			var container = $('#DarlingtonHalf2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='DarlingtonHalf2009.html' ></iframe>");
			firstDarlingtonHalf2009=false;
		}
		return true;
	});	
	var firstKingOfTheMountain2009 = true;
	$('li > a[href="#KingOfTheMountain2009Pane"]').click(function() {
		if(firstKingOfTheMountain2009)
		{
			var container = $('#KingOfTheMountain2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='KingOfTheMountain2009.html' ></iframe>");
			firstKingOfTheMountain2009=false;
		}
		return true;
	});	
	var firstPancakeRun2009 = true;
	$('li > a[href="#PancakeRun2009Pane"]').click(function() {
		if(firstPancakeRun2009)
		{
			var container = $('#PancakeRun2009Pane');
			container.append("<iframe align='middle' border='0' height='600' width='100%' src='PancakeRun2009.html' ></iframe>");
			firstPancakeRun2009=false;
		}
		return true;
});
var firstChristchurch2010 = true;
$('li > a[href="#Christchurch2010Pane"]').click(function() {
    if (firstChristchurch2010) {
        var container = $('#Christchurch2010Pane');
        container.append("<iframe align='middle' border='0' height='600' width='100%' src='Christchurch2010.html' ></iframe>");
        firstChristchurch2010 = false;
    }
    return true;
});    
    var firstChristchurch2009 = true;
    $('li > a[href="#Christchurch2009Pane"]').click(function() {
    if (firstChristchurch2009) {
        var container = $('#Christchurch2009Pane');
        container.append("<iframe align='middle' border='0' height='600' width='100%' src='Christchurch2009.html' ></iframe>");
        firstChristchurch2009 = false;
        }
        return true;
    });
    	
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {

        //Cancel the link behavior   
        e.preventDefault();   
        //Get the A tag   
        var id = $(this).attr('href');   
       
        //Get the screen height and width   
        var maskHeight = $(document).height();   
        var maskWidth = $(window).width();   
       
        //Set heigth and width to mask to fill up the whole screen   
        $('#mask').css({'width':maskWidth,'height':maskHeight});   
           
        //transition effect        
        $('#mask').fadeIn(1000);       
        $('#mask').fadeTo("slow",0.8);     
       
        //Get the window height and width   
        var winH = $(window).height();   
        var winW = $(window).width();   
                 
        //Set the popup window to center   
        $(id).css('top',  winH/2-$(id).height()/2);   
        $(id).css('left', winW/2-$(id).width()/2);   
       
        //transition effect   
        $(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		e.preventDefault();   
        $('#mask, .window').hide(); 
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});
	$('body').css('visibility','visible');
	$('body').fadeIn(2000);
});