// perform JavaScript after the document is scriptable.
$(function() {
	
	//Tweets
	$('#tweets').jTweetsAnywhere({
	    username: 'hamiltopia',
	    count: 1
	});
	
	// Tabs
	// setup ul.tabs to work as tabs for each div directly under div.panes
	$("ul.tabs").tabs("div.panes > div", { history: true });
	
	
	// select one or more elements to be overlay triggers
	var triggers = $(".modalInput").overlay({
	
		// some mask tweaks suitable for modal dialogs
		mask: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.5
		}
	});
	
	
	// Accordion
	$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});
	
	
	// Slideshow
	$(".slidetabs").tabs(".images > div", {

		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: "slow",
	
		// start from the beginning after the last tab
		rotate: true
	
	// use the slideshow plugin. It accepts its own configuration
	}).slideshow({
			
		// start slideshow on page load
		autoplay:true,
		
		// transition time in miliseconds
		interval:'3000'
	});
	
	
	
	// SUper Awesome Simple Accordion - 11/10
	
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();

	/********************************************************************************************************************
	OPENS THE DIV THAT IS ASSIGNED WITH THE ID open
	********************************************************************************************************************/	
	$(".openButton").trigger('click');
	
	
	
	//Tooltips
	$(".tip_trigger").hover(function(){
		tip = $(this).find('.tip');
		tip.show(); //Show tooltip
	}, function() {
		tip.hide(); //Hide tooltip
	}).mousemove(function(e) {
		var mousex = e.pageX + 20; //Get X coodrinates
		var mousey = e.pageY + 20; //Get Y coordinates
		var tipWidth = tip.width(); //Find width of tooltip
		var tipHeight = tip.height(); //Find height of tooltip

		//Distance of element from the right edge of viewport
		var tipVisX = $(window).width() - (mousex + tipWidth);
		//Distance of element from the bottom of viewport
		var tipVisY = $(window).height() - (mousey + tipHeight);

		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
			mousex = e.pageX - tipWidth - 20;
		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
			mousey = e.pageY - tipHeight - 20;
		}
		//Absolute position the tooltip according to mouse position
		tip.css({  top: mousey, left: mousex });
	});
	
	
	
	
//END
});

//Last.fm Stuffs
var _config = {
	username: 'hamiltopia',
	count: 20,
	period: 'overall',
	defaultthumb: 'http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_large.png'
};
  lastFmRecords.init(_config);
  
  //Hover Intent for Tool Tips
  var config = {    
    over: makeTall, // function = onMouseOver callback (REQUIRED)    
    timeout: 500, // number = milliseconds delay before onMouseOut    
    out: makeShort // function = onMouseOut callback (REQUIRED)    
};

$("#demo3 li").hoverIntent( config )
