/*-----------------------------------------------------
APPLICATION JAVASCRIPT

Website: http://www.roadrunnerrecords.com
-----------------------------------------------------*/

function loadContent(element, containerID){
	var contentURL = element.href; // URL that is requested
	var serverBase = window.document.referrer; // Server base path

	var spinnerHolder = new Element('div', { // Holder for the spinner
		'id': 'spinnerHolder',
		'class': 'spinnerHolder'
	});
	var spinner = new Element('img', { // The spinner
		'src': '/images/elements/misc/waiting.gif',
		'class': 'spinner'
	});
	
	var req = new Request.HTML({ // Setup the request object
			url: contentURL,
			onRequest: function(){
				spinnerHolder.inject(containerID, 'top'); // Inject the spinner holder
				spinner.inject(spinnerHolder); // Inject the spinner in the holder
			},
			onSuccess: function(x, y, html) {
				$(containerID).set('text', ''); // Clear out the current content
				//$(containerID).adopt(html); // Insert the new content
				$(containerID).innerHTML = html;
				new MooKissToggler(); // For all the expanders
				var rating = new RabidRatings();
				new Tips($$('.tooltip')); // For tooltips
				spinnerHolder.destroy(); // Remove the spinner bar
				scrollToMe(containerID); //Scroll to new content
			},
			onFailure: function() {
				spinnerHolder.destroy(); // Remove the spinner bar
				$(containerID).set('text', 'The request failed.'); // Display something if it failed
			}
		});
		req.send(); // Send it out and bring it back
	
}

function makeSlider(el){
	var theScrollbar = new Element('div',{
		'id': "scrollbar",
		'class': "scrollbar"
	});
	var theHandle = new Element('div',{
		'id': "handle",
		'class': "handle"
	}).inject(theScrollbar);
	var content = $(el);
	var scrollingContent = $(el+"_content");
	theScrollbar.inject(content);
	var slider = new Slider(theScrollbar, theHandle, {
		steps: scrollingContent.getScrollSize().y - scrollingContent.getSize().y,
		mode: 'vertical',
		onChange: function(step){
			scrollingContent.scrollTo(0, step);
		}
	}).set(0);
	$$(scrollingContent, theScrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
		//$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

function initializeItems(){
	// For the login form slide in/out
	if($('login_form')){
		var loginSlide = new Fx.Slide('login_form');
		$('login_form').setStyle('display', 'block');
		loginSlide.hide();
	}
	if($('vertical_slide')){
		var bugSlide = new Fx.Slide('vertical_slide');
		$('vertical_slide').setStyle('display', 'block');
		bugSlide.hide();
	}
	if($('signup_form')){
		var signupSlide = new Fx.Slide('signup_form');
		$('signup_form').setStyle('display', 'block');
		//signupSlide.hide();
	}
	if($('logged_in')){
		var loginSlide = new Fx.Slide('logged_in');
		$('logged_in').setStyle('display', 'block');
		loginSlide.hide();
	}
	$$('a.tooltip').each(function(element,index) {  
	       if(element.get('title') != undefined){
				 var content = element.get('title').split('::');  
	        element.store('tip:title', content[0]);  
	        element.store('tip:text', content[1]);  
				 }
	    });
	
}

function toggleLoginForm(){
	var loginSlide = new Fx.Slide('login_form');
	loginSlide.toggle();
}

function othertourdates(){
	var othertoursSlide = new Fx.Slide('other_tour_dates');
	othertoursSlide.hide();
}

function toggleOtherTourDates(){
	var othertoursSlide = new Fx.Slide('other_tour_dates');
	othertoursSlide.toggle();
}

function fullmap(){
	var fullmapSlide = new Fx.Slide('map_full');
	//fullmapSlide.hide();
}

function toggleFullMap(){
	var fullmapSlide = new Fx.Slide('map_full');
	fullmapSlide.toggle();
}


function toggleBugs(){
	var bugsSlide = new Fx.Slide('vertical_slide');
	bugsSlide.toggle();
}

function scrollToMe(elementID){
	if($(elementID)){
		$(elementID).setStyle('display', 'block');
		new Fx.Scroll(window).toElement(elementID);
	}
}

function cancelMe(elementID, scrollTo){
	$(elementID).setStyle('display', 'none');
	new Fx.Scroll(window).toElement(scrollTo);
}

function hideMe(elementID){
	var hidingSlide = new Fx.Slide(elementID);
	hidingSlide.hide();
}

/****************************************************
*	TOGGLE SINCE YOU LOGGED IN
* Shows/hides signup form
****************************************************/
function showSinceLoggedIn(){
	var loginSlide = new Fx.Slide('logged_in');
	loginSlide.toggle();
}

/****************************************************
*	TOGGLE SIGNUP FORM
* Shows/hides signup form
****************************************************/
function showSignupForm(){
	var signupSlide = new Fx.Slide('signup_form');
	signupSlide.toggle();
}

/****************************************************
*	TOOLTIP CODE
****************************************************/


//when the dom is ready
		window.addEvent('domready', function() {
			
			
			//store titles and text
			$$('a.tips').each(function(element,index) {
				var content = element.get('title').split('::');
				element.store('tip:title', content[0]);
				element.store('tip:text', content[1]);
			});
			
			//create the tooltips
			var tipz = new Tips('.tips',{
				className: 'tips',
				fixed: true,
				hideDelay: 50,
				showDelay: 50
			});
			
			//customize
			/*
			tipz.addEvents({
				'show': function(tip) {
					tip.fade('in');
				},
				'hide': function(tip) {
					tip.fade('out');
				}
			});
			*/
			
		});
