$(function(){	  
	var map_flyout = $('#map_flyout').html();
		   
	var ie = (function(){
		var undef,
			v = 3,
			div = document.createElement('div'),
			all = div.getElementsByTagName('i');
		
		while (
			div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
			all[0]
		);
		
		return v > 4 ? v : undef;
	}()), timeout;
		   
	$('#map_interact').maphilight({
		fill: true,
		fillColor: '832C2C',
		fillOpacity: 1,
		stroke: false,
		strokeColor: 'ff0000',
		strokeOpacity: 1,
		strokeWidth: 1,
		fade: false,
		alwaysOn: false,
		neverOn: false,
		groupBy: 'class'
	});
	
	$('#main_carousel .carousel_slides').cycle({ 
		speed:  1, 
		timeout: 5000,  
		pager:  '.carousel_nav ul', 
		cleartype: 1,
		pause: true,
		fastOnEvent: 500,
		after: function(curr, next, opt, fwd){
			var eq = $(next).index(),
				arr = new Array('first', 'second', 'third', 'forth'),
				href = $(next).find('a').attr('href');
			
			$('.carousel_nav').removeClasses(arr).addClass(arr[eq]);
			$('#view_link').attr('href', href);
		},
		pagerAnchorBuilder: function(idx, slide) { 
			return ".carousel_nav ul li:eq("+idx+") a";
		} 
	});
	
	$('#map_close').live('click', function(){
		$('#map_flyout').children().fadeOut().parent().html(map_flyout).animate({'width': '234px'}, 'fast', function(){
			$('#map_flyout').removeClass('open');
			$('#map_wedge').animate({'left': '250px'}, 'fast');
			$('#map_container h2.alpha').html('Select a destination&hellip;');
		});
	})
	
	$('#crm_form_4').attr('action', '/register-now');
	
	$('#map_interactMap area').hover(function(){
		if(!$('#map_flyout').hasClass('open')){
			clearTimeout(timeout);
			timeout = setTimeout(function(){
				$('#map_wedge').stop().animate({'left': '320px'}, 'fast');
			}, 250);
		}
	}, function(){
		if(!$('#map_flyout').hasClass('open')){
			clearTimeout(timeout);
			timeout = setTimeout(function(){
				$('#map_wedge').stop().animate({'left': '250px'}, 'fast');
			}, 250);
		}
	}).click(function(){
		var t = $(this),
			href = t.attr('href').split('/'),
			destination = href[href.length - 1];
			
		api('wild_frontiers', '_model', 'get_map_contents', [destination, false], function(continent){
			var html = '',
				image = continent.uri.replace(/-+/ig, '_')+'_map_small.gif';
			$('#flyout_name').html(continent.name);
			$('#flyout_intro').html('<p>'+continent.overview+'</p>');
			$('#flyout_map').html('<img src="/images/'+image+'" />');
			$('#flyout_link').html('<a href="/world-regions/'+continent.uri+'">View Detailed Map</a>');
			
			$(continent.countries).each(function(){
				html += '<li><span class="bullet"></span><a href="/world-regions/'+continent.uri+'/'+this.uri+'">'+this.name+'</a></li>';
			})
			
			$('#flyout_countries').html(html);
			
			$('#map_flyout').addClass('open').animate({
				'width': '855px'
			}, 750, function(){
				$('#map_container h2.alpha').html('Select another destination&hellip;');
			})
		});
		
		
		
		return false;
	})
})
