// JavaScript Document

// JavaScript Document

/***** EASING *****/

jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeInOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInExpo:function(e,f,a,h,g){return(f===0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f===0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInRegular:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutRegular:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutRegular:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a}});


navWidth = function(){
	totalWidth = 937;
	itemWidth = 0;
	$('#topNav > li:first').addClass('first');
	$('#topNav > li:last').addClass('last');
	$('#topNav > li > ul').find('li:last').addClass('curve');
	$('#topNav > li > a').css('padding-left', '0px').css('padding-right', '0px');
	$('#topNav > li').each(function(){
		itemWidth += $(this).width();
	});
	spaceLeft = (totalWidth - itemWidth);
	padding = Math.floor((spaceLeft / $('#topNav > li').size()) / 2);
	$('#topNav > li > a').css('padding-left', padding + 'px').css('padding-right', padding + 'px');
	remainder = (totalWidth - $('#topNav').width());
	$('#topNav > li:last > a').css('padding-right', padding + Math.ceil(remainder/2) + 'px');
	$('#topNav > li:first > a').css('padding-left', padding + Math.floor(remainder/2) + 'px');
}

function removeLast(){
	$dup = $('#mainnav li:last a');
	$('#mainnav li:last').empty();
	$($dup).appendTo('#mainnav li:last');
}

function leftNav(){
	$('#subleftnav a:first').addClass('top');
	$('#subleftnav a:last').addClass('bottom');
}

$(document).ready(function(){
	navWidth();
	removeLast();
	leftNav();
	$('#seminar2').hide();
	$('#tab1 a').addClass('on');
	$('.seminar').each(function(){
		$(this).find('.semIndex a:first').addClass('on');
		$(this).find('.semContent .semList').not(':first').hide();
		$(this).find('.semContent > a').not(':first').hide();
		$(this).find('.semList li:even').addClass('even');
	});
	
	
	
	//  Tab changing for each day
	$('#semTabs a').click(function(){
		$('#semTabs a').removeClass('on');
		$(this).addClass('on');
		$('.seminar:visible').hide();
		$($(this).attr('href')).show();
		return false;
	});
	
//*
	//  Seminars within each tabbed section, changes are synchronised (old version below)
	
	var $seminars = $('#seminars .seminar');
	
	$('.semIndex a').click(function(){
	
		var index = $( this ).parent().index();
		
		$seminars.each( function( i, el ) {

			var $div   = $( el );

			$div.find( 'ul.semIndex li a' ).removeClass( 'on' ).eq( index ).addClass( 'on' );
			$div.find( 'div.semContent' ).children().hide();					//  Cannot use ":visible" as non-showing seminars won't be affected
			$div.find( 'div.semContent:eq(' + index + ')' ).children().show();

		});

		return false;
	});
//*/	
	/*
	//
	//  OLD VERSION
	//
	
	$('.semIndex a').click(function(){
		$('.seminar:visible .semIndex a.on').removeClass('on');
		$(this).addClass('on');
		$('.semContent:visible > a').hide();
		$('.semContent:visible .semList:visible').hide();
		$('a[name=' + $(this).attr('href').replace('#', '') + ']').show().next('.semList').show();
		return false;
	});
	//*/

	if ( $('#hometweets').length > 0 ) {

		$('#hometweets').cycle({
			delay: 2000,
			fx: 'scrollRight',
			timeout: 5000
		});

	}

});

$(document).ready(function() {
 
    //rotation speed and timer
    var speed = 5000;
    var run = setInterval('rotate()', speed);  
     
    //grab the width and calculate left value
    var item_width = $('#slides li').outerWidth();
    var left_value = item_width * (-1);
         
    //move the last item before first item, just in case user click prev button
    $('#slides li:first').before($('#slides li:last'));
     
    //set the default item to the correct position
    $('#slides ul').css({'left' : left_value});
 
    //if user clicked on prev button
    $('#prev').click(function() {
 
        //get the right position           
        var left_indent = parseInt($('#slides ul').css('left')) + item_width;
 
        //slide the item           
        $('#slides ul').animate({'left' : left_indent}, 2000,function(){   
 
            //move the last item and put it as first item              
            $('#slides li:first').before($('#slides li:last'));          
 
            //set the default item to correct position
            $('#slides ul').css({'left' : left_value});
         
        });
 
        //cancel the link behavior           
        return false;
             
    });
 
  
    //if user clicked on next button
    $('#next').click(function() {
         
        //get the right position
        var left_indent = parseInt($('#slides ul').css('left')) - item_width;
         
        //slide the item
        $('#slides ul').animate({'left' : left_indent}, 2000, function () {
             
            //move the first item and put it as last item
            $('#slides li:last').after($('#slides li:first'));                 
             
            //set the default item to correct position
            $('#slides ul').css({'left' : left_value});
         
        });
                  
        //cancel the link behavior
        return false;
         
    });       
     
    //if mouse hover, pause the auto rotation, otherwise rotate it
    $('#slides').hover(
         
        function() {
            clearInterval(run);
        },
        function() {
            run = setInterval('rotate()', speed);  
        }
    );
         
});
 
//a simple function to click next link
//a timer will call this function, and the rotation will begin :) 
function rotate() {
    $('#next').click();
}

