jQuery(document).ready(function(){

	function calculos(id_to_box,destino){
		//var classe_posi = jQuery('#' + id_to_box).attr("class");
		//alert(classe_posi);
		if(jQuery('#' + id_to_box).hasClass('current') == false && jQuery('#' + id_to_box).hasClass('central') == false){
		if(jQuery('#' + id_to_box).hasClass('esquerda') == true){
			var classe_posi = 'esquerda';
			var classe_posi_others = 'direita';
			var inserta = 'insertBefore';
		}
		else{
			var classe_posi = 'direita';
			var classe_posi_others = 'esquerda';
			var inserta = 'insertAfter';
		}
		//alert(classe_posi);
		//alert(jQuery('.' + classe_posi + ':eq(2)').attr('id'));
		var c_taget = new Array(3);
		var c_move = new Array(3);
		var i = 0;
		for(i=0;i<=2;i++){
			c_taget[i] = jQuery('.' + classe_posi + ':eq(' + i + ')').attr('id');
			c_move[i] = jQuery('.' + classe_posi_others + ':eq(' + i + ')').attr('id');
		}
		
		if(classe_posi == 'esquerda'){
			//alert('esquerda before');
			var j = 0;
			for(j=0;j<=2;j++){
				jQuery('#' + c_move[j]).clone().removeClass(classe_posi_others).addClass(classe_posi).width(0).insertBefore('#' + c_taget[j]);
			}
		}
		else{
			//alert('direita after');
			var j = 0;
			for(j=0;j<=2;j++){
				jQuery('#' + c_move[j]).clone().removeClass(classe_posi_others).addClass(classe_posi).width(0).insertAfter('#' + c_taget[j]);
			}
		}
		jQuery('.current').removeClass('current');
		jQuery('#' + id_to_box).addClass('current');
		jQuery('.' + classe_posi_others).animate({ 'width' : '0px' },2000, function(){ jQuery(this).remove(); });
		//jQuery('.central').removeClass('central').addClass(classe_posi_others);
		jQuery('.central').removeClass('central').addClass('tempo');
		jQuery('#' + c_taget[0] + ', #' + c_taget[1] + ', #' + c_taget[2]).removeClass(classe_posi).addClass('central');
		//talve de pra colocar a chamada pra calculos2 aqui...testar...
		//calculos2(id_to_box);
		var cont = 0;
		jQuery('.' + classe_posi).animate({ 'width' : '1280px' }, 2000, function(){
			jQuery('.tempo').removeClass('tempo').addClass(classe_posi_others);
			cont++;
			if(jQuery('#' + id_to_box).hasClass('middle') == false && cont == 3){ calculos2(id_to_box,destino); }
			else if(jQuery('#' + id_to_box).hasClass('middle') == true && cont == 3){ window.location = destino; }
		});
	} //encerra if inicio
	else if(jQuery('#' + id_to_box).hasClass('middle') == false){calculos2(id_to_box,destino);}
	else{ window.location = destino; }
	}
	
function calculos2(id_to_box,destino){
	//if(jQuery('#' + id_to_box).hasClass('middle') == false){
		//alert('ate aqui beleza');
		if(jQuery('#' + id_to_box).hasClass('top') == true){
			var classe_vert = 'top';
			var classe_vert_others = 'bottom';
			jQuery('.' + classe_vert).removeClass(classe_vert).addClass('temp');
			jQuery('.' + classe_vert_others).clone().removeClass(classe_vert_others).addClass(classe_vert).height(0).prependTo('#fundo');
		}
		else {
			var classe_vert = 'bottom';
			var classe_vert_others = 'top';
			jQuery('.' + classe_vert).removeClass(classe_vert).addClass('temp');
			jQuery('.' + classe_vert_others).clone().removeClass(classe_vert_others).addClass(classe_vert).height(0).appendTo('#fundo');
		}
		jQuery('.' + classe_vert_others).animate({ 'height' : '0px' },3000, function(){ jQuery(this).remove(); });
		//jQuery('.' + classe_vert).animate({ 'height' : '760px' },3000);
		jQuery('.' + classe_vert).animate({ 'height' : '760px' },3000, function(){ window.location = destino; });
		jQuery('.middle').removeClass(classe_vert).removeClass('middle').addClass(classe_vert_others);
		jQuery('.temp').removeClass('temp').addClass('middle');
	//}
	//else{ alert('eu nao devia aparecer!'); window.location = destino; }
}
	//var height_content = jQuery("div#content").height();
	//jQuery("div#tela").height(height_content);
	jQuery("#fade_content, #back_menu").css({'display' : 'none'});
	jQuery("#fade_content, #back_menu").fadeIn('slow');

function mv_compass(coordenada){
var obj = document.getElementById("compass");
if (obj && typeof obj.spin != "undefined") {
	switch(coordenada)
	{
	case 'box1':
		obj.spin('nw');
		break;
	case 'box2':
		obj.spin('n');
		break;
	case 'box3':
		obj.spin('ne');
		break;
	case 'box4':
		obj.spin('w');
		break;
	case 'box6':
		obj.spin('e');
		break;
	case 'box7':
		obj.spin('sw');
		break;
	case 'box8':
		obj.spin('s');
		break;
	case 'box9':
		obj.spin('se');
		break;
	default:
		//jQuery(".arrow").fadeIn('slow');
	}
}
}
	//jQuery('#orient_yourself').css({ 'display' : 'none' });
	robledo = jQuery.flash({
		swf: 'swf/main.swf',
		width: 100,
		height: 80,
		id: 'compass',
		name: 'compass',
		//style: 'display: none',
		params: { wmode: 'transparent' }
	});

	jQuery('#orient_yourself').html(robledo);
	//jQuery('#orient_yourself').fadeIn('slow');

	world = jQuery.flash({
		swf: 'swf/imap_world.swf',
		width: 600,
		height: 600,
		id: 'imap_world_flash',
		name: 'imap_world_flash',
		params: { wmode: 'transparent' }
	});
	
	jQuery('#imap_world_flash_wrap').html(world);
	jQuery('#imap_world_link').click(function(){ jQuery('#imap_world_box').fadeIn('slow'); });
	jQuery('#imap_world_box a').click(function(){ jQuery('#imap_world_box').fadeOut('slow'); });

	jQuery(".link").click(function(){
		//alert("fechou!");
		var id = jQuery(this).attr("id");
		var destino = jQuery(this).attr("href");
		//alert(destino);
		//alert('vai para box: ' + id.slice(3));
		var id_to_box = id.slice(3);
		jQuery("#fade_content, #back_menu").fadeOut('slow');
		if(id_to_box == 'box5'){jQuery("#menu").fadeOut('slow');}
		mv_compass(id_to_box);
		//robledo();
		calculos(id_to_box,destino);
		//calculos2(id_to_box);
		return false;
	});
	var src_img_year = '';
	jQuery("a.per_year").hover(
		function(){
			src_img_year = jQuery(this).find('img').attr('src');
			var alt_img = jQuery(this).find('img').attr('alt');
			var src_img = 'img/schedule/bt_red_' + alt_img + '.png';
			jQuery(this).find('img').attr('src',src_img);
		},
		function(){
			jQuery(this).find('img').attr('src',src_img_year);
		}
	);
	
});

/*
	var options = { 
        target: '#alert',
		url:    'contato_imap.php',
		type:   'POST'
	};
	jQuery('#form').submit(function(){
		jQuery.ajax({
		   type: "",
		   url: news_url,
		   dataType: (jQuery.browser.msie) ? "text" : "xml",
		   success: function (data) {
			var xml;
			if (typeof data == "string") {
			   xml = new ActiveXObject("Microsoft.XMLDOM");
			   xml.async = true;
			   xml.loadXML(data);
			} else {
			   xml = data;
			   }
			if(news_type == 'news'){
			
			var one_news = '<p class="news_link" ><a href="#" ><span>Coming soon...</span></a></p>';
			jQuery("div#text_news").append(one_news);
			}
			else{ jQuery("div#text_news").append(xml); }
			}
		});
		return false;
	});
*/		

jQuery(window).load(function(){
/*
	jQuery('#orient_yourself').flash({
		swf: 'swf/main.swf',
		width: 100,
		height: 80,
		id: 'compass',
		name: 'compass',
		style: 'display: none',
		params: { wmode: 'transparent' }
	});*/
	//document.getElementById("compass").show('slow');
	//jQuery('#orient_yourself').html(robledo);
	jQuery('#orient_yourself').fadeIn('slow');
	//jQuery('#compass').fadeIn('slow');
	//fadeIn('compass',2000);
});
