// Webcko Mootools Related

// START ITINERARY
function i_add(id,type) {
	// perform ajax request and update i_status
	var url = '?ajax=i_add&id='+id+'&type='+type;
	new Ajax(url, {
			 method: 'get',
			 update: $('i_status_'+id)
	}).request();
	return false;
}

function i_list_remove(id,type) {
	// perform ajax request and update i_status
	var url = '?ajax=i_list_remove&id='+id+'&type='+type;
	new Ajax(url, {
			 method: 'get',
			 update: $('i_listing')
	}).request();
	return false;
}

function i_shortlist_remove(id,type) {
	// perform ajax request and update i_status
	var url = '?ajax=i_shortlist_remove&id='+id+'&type='+type;
	new Ajax(url, {
			 method: 'get',
			 update: $('i_listing')
	}).request();
	
	// update the map now
	var url = '?ajax=i_map_refresh';
	new Ajax(url, {
			method: 'get',
			update: $('i_map')
	}).request();
	
	return false;
}

function i_remove(id,type) {
	// perform ajax request and update i_status
	var url = '?ajax=i_remove&id='+id+'&type='+type;
	new Ajax(url, {
			 method: 'get',
			 update: $('i_status_'+id)
	}).request();
	return false;
}

function i_view() {
	// redirect the user to the view page
	document.location = '/page/itinerary';
	return false;
	
	// display a listing of stores to the user
	var url = '?ajax=i_view';
	new Ajax(url, {
			 method: 'get',
			 update: $('i_status')
	}).request();
	return false;
}

function i_list_clear() {
	// perform ajax request and update i_status
	var url = '?ajax=i_list_clear';
	new Ajax(url, {
			 method: 'get',
			 update: $('i_listing'),
			 onComplete: document.location = '/page/events'
	}).request();
	return false;
}

function i_print() {
	if ( confirm('Press OK to print this page') )
		window.print();
	return false;
}
// END ITINERARY

// css skinable scrollbar
function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getSize().scrollSize.x - content.getSize().size.x):(content.getSize().scrollSize.y - content.getSize().size.y))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}


window.addEvent('domready', function() {
	
	// noobslide for homepage
	if ( $('box4') ) {
		var hs4 = new noobSlide({
			box: $('box4'),
			items: $ES('div','box4'),
			size: 450,
			handles: $ES('span','handles4'),
			autoPlay: true,
			onWalk: function(currentItem,currentHandle){
				$('info4').setHTML(currentItem.getFirst().innerHTML);
				this.handles.removeClass('active');
				currentHandle.addClass('active');
			}
		});
	}
	
	// handle search box
	var search_box = $('search_box');
	if ( search_box ) {
		search_box.addEvent('focus', function(e) {
			if ( search_box.value == 'SEARCH' )
				search_box.value = '';
		});
		search_box.addEvent('blur', function(e) {
			if ( search_box.value == '' )
				search_box.value = 'SEARCH';
		});
	}

	// fix alignment of search container on safari (safari sucks too)
	var search_container = $('search_container');
	if ( BrowserDetect.browser == 'Safari' ) {
		search_container.setStyle('margin-top', -2);
	}
	
	// try to do the bottles piece
	var bottles_container = $('bottles_container');
	
	if ( bottles_container ) {
		var bottles = $$('.bottle');
		var bottle_padding = 10;
		var bottle_width = 39; // STATICALLY SET FOR SAFARI
		
		// set tooltips for any bottles
		if ( BrowserDetect.browser != 'Explorer' ) {
			var bottle_tips = new Tips('.bottle', {
				className: 'bottle',
				initialize:function(){
					this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
				},
				onShow: function(toolTip) {
					this.fx.start(1);
				},
				onHide: function(toolTip) {
					this.fx.start(0);
				}
			});
		}

		var widths = 0;
		bottles.each(function(bottle) {
			if ( BrowserDetect.browser == 'Safari' ) {
				widths += bottle_width + bottle_padding;
			} else {
				widths += bottle.width + bottle_padding;
			}
			bottle.addEvent('mouseover', function(event) {
				// when the mouse moves over the bottle
				
			});
		});

		// set container width to center it
		bottles_container.setStyle('width', widths);
	}
	
	// member login button
	var toplogin_button = $('toplogin_button');
	
	if ( toplogin_button ) {
		toplogin_button.addEvent('mouseenter', function(event) {
			toplogin_button.src = '/img/buttons/member_login_ro.png';
		});
		toplogin_button.addEvent('mouseout', function(event) {
			toplogin_button.src = '/img/buttons/member_login.png';
		});
	}
	
	// scrollbars
	var event_scroll = $('event_scroll');
	if ( event_scroll ) {
		// force a height for this box
		forceMinHeight('event_boxer', 100);
		
		makeScrollbar( $('event_scroll'), $('event_scrollbar'), $('event_handle') );
	}

	var content = $('content_scroll');
	if ( content ) {
		// grab the height and make sure it's at least 290px, if larger, leave alone
		forceMinHeight('content_boxer', 360);
		
		makeScrollbar( $('content_scroll'), $('content_scrollbar'), $('content_handle') );
	}
	
});