var it = 1;
var last_it = 0;
var cycle = null;
var no_preload = true;
var now_over = 0;
var cycle_interval = 6500;
var mopics = new Array ( '9','3','4','5','2' );


$(document).ready(function() {
	/*
	$.get("/roadtrips/products/monthly_special_block/", function(monthly){
		$("#monthly").html(monthly);
	});
	*/
	$(".superlink").css("cursor", "pointer");

	$(".superlink .forsuper").each(function(i) {
		url = $(this).attr('href');
		$(this).parent().click(function() {
			window.location = $(this).children('.forsuper').attr('href');;
		});
	});
	var mapjs = $.getScript("/roadtrips/categories/paper_gmap_js/", function(){
		initialize();
		//if(console)console.log('get script');
		setTimeout('delay_slideshow()', 2000);	
	});
	//if(console)console.log('js');


});


/*	map
================================================================================== */

var visible_bounds = new Array();
var all_bounds = new Array();
var all_bound_data = new Array();
var map;
var tinyIcon;
function createMarker(point, infohtml, model, icon) {
	//if(console)console.log(infohtml);
	if (model.substr(0,3) == "GOT" || model.substr(0,2) == "RR") { 
		markerOptions = { icon:tinyIcon };
	} else {
		markerOptions = { icon:regIcon };
	}
	var marker = new GMarker(point, markerOptions);
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(infohtml);
	});
	GEvent.addListener(marker, 'mouseover', function() {
		jQuery.each(all_bounds, function() {
			this.hide();
		}); 
		if (all_bounds[model]) {
			all_bounds[model].show();
		} else {
			createBounds(model,all_bound_data[model][0],all_bound_data[model][1],all_bound_data[model][2],all_bound_data[model][3]);
		}
	});
	GEvent.addListener(marker, 'mouseout', function() {
		all_bounds[model].hide();
	});
	return marker;
}

function createBounds(model,n,s,e,w) {
	var polygon = new GPolygon([
	    new GLatLng(n,w),
	    new GLatLng(n,e),
	    new GLatLng(s,e),
	    new GLatLng(s,w),
	    new GLatLng(n,w)
	  ], '#E4652B', 1, 1, '#E4652B', 0.4);
	map.addOverlay(polygon);
	all_bounds[model] = polygon;
	all_bounds[model].show();
}

function show_bounds(model) {
	all_bounds[model].show();
}

function hide_visible_bounds() {
	jQuery.each(visible_bounds, function(i, val) {
		map.addOverlay(boundary);
	}); 
}



/*	Slideshow
================================================================================== */

function delay_slideshow() {
	cycle = setInterval('slideSwitch()', cycle_interval);	
}

function slideSwitch() {
	if (mopics.length > 0) {
		var newpic = mopics.pop();
		var newli = '<li><img width="434" height="289" src="http://' + location.host + '/images/index/slideshow/' + newpic + '.jpg" alt="" /></li>';
		$("#gallery_carousel").append(newli);
	}
		
    var active = $('#gallery_carousel li.active');
    if ( active.length == 0 ) active = $('#slideshow li:last');
    var $next =  active.next().length ? active.next() : $('#gallery_carousel li:first');
    active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('active last-active');
        });
}


