$(document).ready(function() {	
	$("#slideshow").fadeIn();
	var jg = new jsGraphics("Canvas");

	function drawRoute(route) { 
		jg.setStroke(5);
		jg.setColor("#0066CC");
		// Cape Town to Port Elizabeth
		jg.drawPolyline(new Array(331, 432, 488, 504, 517, 529, 573), new Array(473, 488, 470, 472, 473, 470, 472));
		// Port Elizabeth to Durban
		if ((route == "durban") || (route == "all")) {
			jg.drawPolyline(new Array(573, 630, 690, 695, 730, 771, 807, 825), new Array(472, 462, 442, 435, 378, 326, 326, 287));
		}
		// Durban to Johburg
		if (route == "all") {
			jg.drawPolyline(new Array(825, 798, 768, 759, 754, 740), new Array(285, 273, 240, 193, 169, 115));
		}
		jg.paint();
	}
	function clearRoute() { 
		jg.clear();
	}

	setInterval( "slideSwitch()", 3000 );
	$("#ticket_options a").hover(function() { 
		var route = $(this).attr("class");
		if (route != "none" && route != "hopon" && route != "travelpass" && route != "flexitour") {
			if (route == "durban") {
				drawRoute("durban");	
			} else { 
				if (route == "portelizabeth") {
					drawRoute("portelizabeth");
				} else { 
					drawRoute("all");
				}
			}
		}
	}, 
	function() { 
		clearRoute();
	});

	
	$('.hopon').click(function(){
		window.open('http://www.bazbus.com/what1.aspx',	'Continue_to_Application','width=450,height=420');	ev.preventDefault();
		return false;
	});
	$('.travelpass').click(function(){
		window.open('http://www.bazbus.com/what2.aspx',	'Continue_to_Application','width=450,height=420');	ev.preventDefault();
		return false;
	});
	$('.flexitour').click(function(){
		window.open('http://www.bazbus.com/what3.aspx',	'Continue_to_Application','width=450,height=420');	ev.preventDefault();
		return false;
	});
});	
function slideSwitch() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	var $next =  $active.next().length ? $active.next()
		: $('#slideshow IMG:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}
