
$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
	});	
var isdoingit = 0;
var clicked = 0;
var mouseisover = 0;
function hidewidget(x){
	if(!window.isdoingit){
	window.isdoingit = 1;
	var windowWidth = $(window).width();
	if(!x){
	$(".widget").animate({ width: '105%' }, 500, "easeInOutSine", function() {
          $(".widget").animate({ left: '-=' + windowWidth}, 600, function() {
			$(this).slideToggle(500);
			$('.data').fadeIn();
			window.isdoingit = 0;
		  });
	   });} else {
		   /*
          $(".widget").animate({ left: '-=' + windowWidth}, 600, function() {
			$(this).slideToggle(500);
			$('.data').fadeIn();
			window.isdoingit = 0;
		  });*/
		  $(".widget").hide();
		  $(".widget").animate({ left: '-=' + windowWidth}, 600, function() {
			//$(this).slideToggle(500);
			$('.data').fadeIn();
			//bouncetwit();
			window.isdoingit = 0;
		  });
		  
		   }
	}
	twit(0);
};
function showwidget(){
	twit(1);
	$('.data').fadeOut()
	$(".widget").css('width', '100%');
    $(".widget").slideDown(500, function() {
        $(".widget").animate({ left: "0px" }, 800, "easeInOutSine");
    });
};
function loadwidge(){
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 10,
  interval: 30000,
  width: '768',
  height: 400,
  id: 'twtr-widget',
  theme: {
    shell: {
      background: '#6a8fbb',
      color: '#ffffff'
    },
    tweets: {
      background: '#dae4fa',
      color: '#000000',
      links: '#2b88b3'
    }
  },
  features: {
    scrollbar: true,
    loop: false,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    behavior: 'all'
  }
}).render().setUser('BrunelEntrepren').start();
};
function movemenu(x){
	if (!window.isdoingit){
	setclasses('men'+x);
	switch(x){
		case "About":
			$('#current').animate({left: "171px"},300,"easeInOutSine");
			break;
		case "Committee":
			$('#current').animate({left: "273px"},300,"easeInOutSine");
			break;
		case "Events":
			$('#current').animate({left: "375px"},300,"easeInOutSine");
			break;
		case "Affiliates":
			$('#current').animate({left: "477px"},300,"easeInOutSine");
			break;
		case "Contact":
			$('#current').animate({left: "579px"},300,"easeInOutSine");
			break;
		default:
			$('#current').animate({left: "69px"},300,"easeInOutSine");
			x = 'Home';
			break;
	}
	document.title = 'Brunel Entrepreneurs - ' + x;
	fillpage(x);
	}
};
function setclasses(x){
	$('#menHome').addClass('link');
	$('#menAbout').addClass('link');
	$('#menCommittee').addClass('link');
	$('#menEvents').addClass('link');
	$('#menAffiliates').addClass('link');
	$('#menContact').addClass('link');
	$('#'+ x).removeClass('link');
	
};
function fillpage(x){
	var windowWidth = $(window).width();
	window.isdoingit = 1;
	twit(1);
	$('.pagecontent').animate({right: '+=' + 20},300, function (){
		$('.pagecontent').animate({ right: '-=' + windowWidth}, 600, function(){
			$('.loading').fadeIn();
			$('.pagecontent').load(x+'.php', 
			function(){
				$('.loading').hide();
				if(x=='Home'){$('.data').hide();window.isdoingit=0; hidewidget(1);} else {$('.data').show(); twit(1)};
				window.isdoingit = 0;
				$('.pagecontent').animate({right: '+=' + windowWidth}, 600);
				$('.pagecontent').animate({right: '-=' + 20}, 300);
				loadlinks();
				});
			});
		});
};
$(document).ready(function(){
    $("#open-twitter").mouseover(function(){
		window.mouseisover = 1;
        $(this).stop().animate({left:'-1px'},{queue:false, duration:600, easing: 'easeOutBounce'})
    });
    $("#open-twitter").mouseout(function(){
		window.mouseisover = 0;
        $(this).stop().animate({left:'-100px'},{queue:false, duration:600, easing: 'easeOutBounce'})
		;});
	$(".menulink").click(function(){
		var x = $(this).attr('href');
		var page = x.substr(0,1).toUpperCase() + x.substr(1);
		location.href = '#' + page;
		/*x = x.substr(11);
		location.href = '#' + x;*/
		return false;
		});
});
function twit(x){
	if(x){
		window.clicked = 1;
		$("#open-twitter").stop().animate({left:'-142px'}, 100, function(){
		$("#open-twitter").hide();});
	} else {
		window.clicked = 0;
		$("#open-twitter").css('left', '-142px');
		$("#open-twitter").show();
		//$("#open-twitter").animate({left:'-100px'});
		bouncetwit();
	}
}   
function startsite(){
		urlquery=location.href.split("#");
	   if (!urlquery[1] || urlquery[1] =='Home'){
		hidewidget(1);
	   } else{
		  $(".widget").hide();
		  $(".data").show();
		movemenu(urlquery[1]);
	   }
	};
	
	$(window).hashchange(function(){
		if(!window.isdoingit){
			x = window.location.hash;
			x=x.substr(1);
			movemenu(x);
		} else {
			window.location.hash = '';
		}
});
function loadgallery(x){
			$('a[rel='+x+']').colorbox({open:true, maxHeight: ($(window).height()-50), maxWidth:($(window).width()), onLoad: function(){$('body').css('overflow', 'hidden')}, onClosed: function(){$('body').css('overflow', 'auto')}})
	};
function bouncetwit(){

	$('#open-twitter').animate({
		left:'-1px'
	},{
		queue:false, 
		duration:600,
		complete: function(){
			setTimeout("if(!window.mouseisover){$('#open-twitter').animate({left:'-100px'},{queue:false, duration:600, easing:'easeOutBounce'})}",1000)
			}
	});
	
	
}

function loadlinks(){
	$(".menulink").click(function(){
		var x = $(this).attr('href');
		var page = x.substr(0,1).toUpperCase() + x.substr(1);
		location.href = '#' + page;
		/*x = x.substr(11);
		location.href = '#' + x;*/
		return false;
		});
	}

