var map;

jQuery(document).ready(function(){
	if (jQuery.cookie("altoContrasteNovaOrigem")) {
		jQuery(".single").addClass("alto-contraste");
	}
	jQuery(".contraste-branco").click(function(){
		jQuery(".single").addClass("alto-contraste");
		if (!jQuery.cookie("altoContrasteNovaOrigem")) {
			jQuery.cookie("altoContrasteNovaOrigem", true, { path: '/' });
		}
		return false;
	});
	jQuery(".contraste-verde").click(function(){
		jQuery(".single").removeClass("alto-contraste");
		if (jQuery.cookie("altoContrasteNovaOrigem")) {
			jQuery.cookie("altoContrasteNovaOrigem", null, { path: '/' });
		}
		return false;
	});


	var currentFontSize = parseInt(jQuery.cookie("tamTextoSalvoNovaOrigem"));
	if (!currentFontSize) {
		currentFontSize = 100;
	}
	else {
		setSize();
	}
	//Recebe e configura o tamanho 
	function setSize() {
		jQuery('.single').css('font-size', currentFontSize + "%");
		jQuery.cookie('tamTextoSalvoNovaOrigem', currentFontSize, { path: '/' });
		return false;  
	}

	jQuery(".a-maior").click(function(){
		if (currentFontSize <= 100) {
			currentFontSize += 15;
			setSize();
		}
		return false;
	});
	jQuery(".a-menor").click(function(){	
		if (currentFontSize >= 100) {
			currentFontSize -= 15;
			setSize();
		}
		return false;
	});	

	//jQuery(".flickr_badge_image a").attr("rel", "prettyPhoto");
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:"facebook"});

	jQuery(".toggleComments").click(function(){
		jQuery(".photo-comments").slideToggle();
		return false;
	});
	
	// carrossel topo
	jQuery(".timeline-container").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
	});

	
	//interações do formulário de cadastro do Mapa Interativo
	jQuery("#form-mapa-interativo").hide();

	jQuery("#mapa-interativo a.colaborar").click(function(){
		jQuery(this).toggleClass("aberto");
		jQuery("#form-mapa-interativo").slideToggle();

		jQuery(".open-select").click(function(){
			jQuery("#select-icone").fadeIn();
			jQuery(".fechar-janela").click(function(){
				jQuery("#select-icone").fadeOut();
				return false;
			});
			jQuery("#select-icone ul li a").click(function(){
				var img = jQuery(this).find("img").attr("src");
				jQuery("#icone").val(img);
				jQuery(".open-select img").attr("src", img);
				jQuery("#select-icone").hide();
				return false;
			});
			return false;
		});
		return false;
	});

	if (jQuery("#map").length > 0) {
		map = new GMap2(document.getElementById('map'));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(0,25),2);


		var geoXml = new GGeoXml("http://maps.google.com/maps/ms?ie=UTF8&hl=pt-BR&vps=1&jsv=213a&msa=0&output=georss&msid=106825452339641703069.0004781eacd3f2b367c2e");
		map.addOverlay(geoXml);

		linhasVermelhas();

		/* Avião EUA - Europa */
		addMarker(33, -67, "<h1>Avião</h1><p>EUA - Europa</p>", "aviao");
		
		/* Barco Santarém - Manaus */
		//addMarker(-4, -57, "<h1>Barco</h1><p>Santarém - Manaus </p>", "barco");
		
		/* Barco Colômbia - Panamá */
		addMarker(9, -77, "<h1>Barco</h1><p>Colômbia - Panamá </p>", "barco");
		
		/* Avião Dubai - Índia */
		addMarker(22, 63, "<h1>Avião</h1><p>Dubai - Índia </p>", "aviao");
		
		/* Avião Indonésia - Austrália */
		addMarker(-18, 130, "<h1>Avião</h1><p>Indonésia - Austrália </p>", "aviao");
		
		/* Avião Austrália - Nova Zelândia */
		addMarker(-36, 162, "<h1>Avião</h1><p>Austrália - Nova Zelândia</p>", "aviao");
		
		/* Avião Nova Zelândia - Casa */
		addMarker(-38, -168, "<h1>Avião</h1><p>Nova Zelândia - Casa </p>", "aviao");
	}

	//jQuery("#formulario-mapa").validate();
});

function linhasVermelhas() {
	var sXml = "http://novaorigem.com.br/gmaps-xml/";
	var lat, lng;

	jQuery.ajax({
		type: "GET",
		url: sXml,
		dataType: "json",
		success: function(json) {
			for (var i = 0; i < json.length; i++ ) {
				var points = [];
				for (var j = 0;j < json[i].length; j++ ) {
					lat = json[i][j][0];
					lng = json[i][j][1];
					points[j] = new GLatLng(lat, lng);
				}
				map.addOverlay(new GPolyline(points, "#FF0000"));
			}
		},
		error: function(o) {
			alert("erro");
		}
	});	
	
	//var points = [ new GLatLng(40,-80), new GLatLng(40,80)];
	//map.addOverlay(new GPolyline(points, "#FF0000"));
}

function addMarker(lat, lng, texto, icone) {
	var aviao = new GIcon(G_DEFAULT_ICON, "http://novaorigem.com.br/wp-content/themes/irresistible/images/icon.airplane.png");
	aviao.iconSize = new GSize(28, 28);
	aviao.shadowSize = new GSize(0, 0);
	var barco = new GIcon(G_DEFAULT_ICON, "http://novaorigem.com.br/wp-content/themes/irresistible/images/icon.boat.png");
	barco.iconSize = new GSize(28, 28);
	barco.shadowSize = new GSize(0, 0);


	var point = new GPoint(lng,lat);
	if (icone == "aviao") {
		var marker = new GMarker(point,aviao);
	}
	else {
		var marker = new GMarker(point,barco);
	}
	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(texto);
	});
	map.addOverlay(marker);

}

	var langTextArray= new Array();
	langTextArray['btn_ok']="OK";
	langTextArray['email']="Email";
	langTextArray['msg_drag']="Drag this to your bookmarks bar.";
	langTextArray['msg_right_click']="Right-click on this and add it to your favorites.";
	langTextArray['msg_username']="Please enter your username.";
	langTextArray['msg_password']="Please enter your password.";
	langTextArray['using']="using";
	langTextArray['email_message']="Message:";
	langTextArray['msg_blogger_dtls']="Invalid Blogger Username or Password";
	langTextArray['msg_signon_blog']="You have successfully signed on. Please select a blog.";
	langTextArray['msg_cred_rem']="Remembering Credentials is for Signed in Users Only";
	langTextArray['msg_not_connect']="Unable to connect to your blog.";
	langTextArray['msg_error_post']="Error while trying to post to your blog.";
	langTextArray['msg_status_update']="Please enter a status update.";

function mycarousel_initCallback(carousel) {

    jQuery('.timeline-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('.timeline-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};
