// Webcko Mootools Related

// BLOG PAGINATION
function commentpage(id, page) {
	var url = '?ajax=commentpage&id='+id+'&page='+page;
	new Ajax(url, {
			 method: 'get',
			 update: $('blog_comments'),
			 evalScripts: true
	}).request();
	return false;
}

// BLOG COMMENT RATINGS
function thumbsup(id) {
	var url = '?ajax=thumbsup&id='+id;
	new Ajax(url, {
			 method: 'get',
			 evalScripts: true
	}).request();
	return false;
}

function thumbsdown(id) {
	var url = '?ajax=thumbsdown&id='+id;
	new Ajax(url, {
			 method: 'get',
 			 evalScripts: true
	}).request();
	return false;
}

// START ITINERARY
function i_add(id,type) {
	// perform ajax request and update i_status
	var mUrl = '?ajax=i_add&id='+id+'&type='+type;
	new Request({
			 url: "/index.php", 
			 data: {"ajax":"i_add", "id":id, "type":type},
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {
			 	$('i_status_'+id).innerHTML = responseText;
			 }
	}).send();
	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 Request({
			 url: "/index.php",
			 data: {"ajax":"i_list_remove","id":id,"type":type},
			 method: 'get',
			 onSuccess: function(responseText, responseXML) {$('i_listing').innerHTML = responseText;}
	}).send();
	return false;
}

function i_shortlist_remove(sid) {
	// perform ajax request and update i_status
	var url = '?ajax=i_shortlist_remove&id='+sid;
	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(sid) {
	// perform ajax request and update i_status
	var url = '?ajax=i_remove&id='+sid;
	new Ajax(url, {
			 method: 'get',
			 update: $('i_status')
	}).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('mouseclick', function(e) {
			if ( search_box.value == 'SEARCH' )
				search_box.value = '';
		});
		search_box.addEvent('mouseleave', 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;
		
		// 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) {
			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') );
	}*/
	
	// handle topnav
	/*if ( $('topnav_button1') ) {
		var topnav1 = $('topnav_button1');
		
		topnav1.addEvent('mouseenter', function(){
			topnav1.src = '/img/v1/topnav/buttons/signin.png';
		});
	 
		topnav1.addEvent('mouseleave', function(){
			topnav1.src = '/img/v1/topnav/buttons/signin_off.png';
		});
	}
	if ( $('topnav_button2') ) {
		var topnav2 = $('topnav_button2');
		
		topnav2.addEvent('mouseenter', function(){
			topnav2.src = '/img/v1/topnav/buttons/share.png';
		});
	 
		topnav2.addEvent('mouseleave', function(){
			topnav2.src = '/img/v1/topnav/buttons/share_off.png';
		});
	}*/
	
	// handle country/provstate selector
	try {
		$('countryid').addEvent('change', function(e) {
			e = new Event(e).stop();
			
			var country_id = document.getElementById('countryid').value;
			var url = "/?ajax=provstate_selector&country_id="+country_id;
			var dest = $('provstate_id_container');
			dest.innerHTML='Loading...';
			
			new Ajax(url, {
				method: 'get',
				update: dest
			}).request();
		});
	} catch (e) {
	 
	}
	// slide_nav
	try {
		/* hover side menu thing */
		var list = $$('.slide_nav li');
		list.each(function(element) {
			var fx = new Fx.Styles(element, {duration:200, wait:false});
		 
			element.addEvent('mouseenter', function(){
				fx.start({
					'padding-left': 25
				});
			});
		 
			element.addEvent('mouseleave', function(){
				fx.start({
					'padding-left': 10
				});
			});

		});	
	} catch (e) {
		
	}	

	// dim_image
	try {
		/* hover side menu thing */
		var list = $$('.dim_image');
		list.each(function(element) {
			var fx = new Fx.Styles(element, {duration:300, wait:false});
		 
			element.addEvent('mouseenter', function(){
				fx.start({
					'opacity': .9
				});
			});
		 
			element.addEvent('mouseleave', function(){
				fx.start({
					'opacity': .3
				});
			});

			element.setStyle('opacity','.3');
		});	
	} catch (e) {
		
	}
});
