$(document).ready(function(){
	$('#accordion').find('h3:first').addClass('selected').end().find('.accor:first').slideDown('slow');
	$('#accordion h3').click(function(){
		$(this).parents('#accordion').find('.accor').slideUp();
		$(this).parents('#accordion').find('h3').removeClass('selected');		
		if($(this).next().is(':visible')){
			$(this).next().slideUp('normal');
		}
		else{
			$(this).addClass('selected');
			$(this).next().slideDown('slow');
		}		
	});
	
	$('#boxTop5 ul li a').click(function(){
		$('#boxTop5 ul li a').removeClass('hover');
		$(this).addClass('hover');
		$('#boxTop5 div').hide();
		$('#boxTop5').find($(this).attr('href')).hide().fadeIn('slow');
		return false;
	});

	$('#top5_sideBar ul li a').click(function(){
		$('#top5_sideBar ul li a').removeClass('hover');
		$(this).addClass('hover');
		$('#top5_sideBar div').hide();
		$('#top5_sideBar').find($(this).attr('href')).hide().fadeIn('slow');
		return false;
	});
	$('#top5_sideBar ul li a:first').trigger("click");

	/*$(".twitterSidebar").each(function(){
		$(this).getTwitter({
			userName: "Eduardo_sciarra",
			numTweets: 2,
			loaderText: "Carregando tweet...",
			slideIn: true,
			showHeading: false,
			showProfileLink: false
		});
	});*/
	
	//alert(parsed_dateAtual);
	
	$.Juitter.start({
		searchType: "fromUser",
		searchObject: "eduardo_sciarra",
		placeHolder: "twitt",
		loadMSG: "Carregando...",
		total: 2,
		nameUser: "text",
		lang: "pt",
		openExternalLinks: "newWindow",
		live: "live-60"
	});
	
	$('#twtSearch input[type="image"]').click(function(){
		if($(this).prev().val() == "" || $(this).prev().val() == "Buscar no twitter"){
			$(this).prev().addClass("error").focus();
		}
		else{
			$(this).prev().removeClass("error");
			$urlSearch = $(this).prev().val().replace('#', '%23');
			$.Juitter.start({
				searchType: "searchWord",
				searchObject: $urlSearch,
				placeHolder: "twitt",
				loadMSG: "Carregando...",
				total: 2,
				nameUser: "text",
				lang: "pt",
				openExternalLinks: "newWindow",
				live: "live-60"
			});			
			$('a.verT').attr('href', 'http://twitter.com/#search?q=' + $urlSearch);
		}
		return false;
	});
	
	$('#formContato').validate({ errorContainer: $('.msgError'),
        submitHandler: function() {
            $.ajax({
                type: 'POST',
                data: $('#formContato').serialize(),
                dataType: 'json',
                url: '/wp-content/themes/sciarra/gravaContatos.php',
                success: function(json) {
                    if (json.msg == 'ok') {
                        $('p.msgError, p.msgErrorBack').hide();
                        $('p.msgSucesso').fadeIn();
						$('#formContato input:text, #formContato textarea').val('');
					} else {
						$('p.msgError, p.msgSucesso').hide();
                        $('p.msgErrorBack').fadeIn();
                    }
                }
            });
        }
    });
	
	$('#newsletter').validate({ errorContainer: $('.msgError'),
        submitHandler: function() {
            $.ajax({
                type: 'POST',
                data: $('#newsletter').serialize(),
                dataType: 'json',
                url: '/wp-content/themes/sciarra/gravaNews.php',
                success: function(json) {
                    if (json.msg == 'ok') {
                        $('p.msgError, p.msgErrorBack').hide();
                        $('p.msgSucesso').fadeIn();
						$('#newsletter input:text').val('');
					} else {
						alert('erroooo');
						$('p.msgError, p.msgSucesso').hide();
                        $('p.msgErrorBack').fadeIn();
                    }
                }
            });
        }
    });

	$("#trajetoria .item:first").show();
		
	$("#trajetoria .item a.prev").click(function(){
		if($(this).parents(".item").prev().size() == 1){
			$(this).parents(".item").hide().prev().fadeIn();
		}else{
			$(this).parents(".item").hide();
			$("#trajetoria .item:last").fadeIn();
		}
		return false;
	});

	$("#trajetoria .item a.next").click(function(){
		if($(this).parents(".item").next().size() == 1){
			$(this).parents(".item").hide().next().fadeIn();
		}else{
			$(this).parents(".item").hide();
			$("#trajetoria .item:first").fadeIn();
		}
		return false;
	});
	
	$("#carousel ul").jcarousel({ scroll: 10 });

	$("#carousel ul li a").click(function(){
       $id = $(this).attr("href").split("#")[1];
       $("#trajetoria .item").hide();
       $("#trajetoria .item[rel='"+ $id +"']").show();
	   return false;
     });
       
    

	$("#mapParana").each(function(){
		$addInfo = function(marker, txt){
			GEvent.addListener(marker, "click", function() { 
				marker.openInfoWindowHtml('<div style="width: 280px;">' + txt + '</div>');
			});
		}
		if (GBrowserIsCompatible()){
			
			var map;
				map = new GMap2(document.getElementById("mapParana"));
				map.addControl(new GSmallMapControl());
				map.addControl(new GMenuMapTypeControl());
				map.setCenter(new GLatLng(0,0), 0);
				map.setMapType(G_HYBRID_MAP);

			var baseIcon = new GIcon();
				baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
				baseIcon.iconSize = new GSize(16, 16);
				baseIcon.shadowSize = new GSize(25, 25);
				baseIcon.iconAnchor = new GPoint(9, 34);
				baseIcon.infoWindowAnchor = new GPoint(5, 5);
				baseIcon.infoShadowAnchor = new GPoint(5, 5);

			var $i = 0;
			var latlng1 = new Array();
			var latlngbounds = new GLatLngBounds();
			$("#infoParana .geo").each(function(){
				$lat = $(this).find(".latitude").text();
				$lon = $(this).find(".longitude").text();
				$txt = $(this).find(".info").html();
				var customIcon = new GIcon(baseIcon);
					customIcon.image = "/wp-content/themes/sciarra/img/icoMapTrans.gif";
					markerOptions = { icon: customIcon };
				
				latlng1[$i] = new GLatLng($lat, $lon);
				var marker = new GMarker((latlng1[$i]), markerOptions);
				if($txt != null){
					$addInfo(marker,$txt);
				}
				map.addOverlay(marker);
				latlngbounds.extend(latlng1[$i]);
				$i++;
			});
			map.setCenter(latlngbounds.getCenter(), map.getBoundsZoomLevel(latlngbounds));
		}
	});
	

	// hint
	$('.hint').each(function(){
		$(this).val($(this).attr('title'));
	});
	$('.hint').focus(function(){
		if($(this).val() == $(this).attr('title')){
			$(this).val('');
		};
	}).blur(function(){
		if($.trim($(this).val()) == ''){
			$(this).val($(this).attr('title'));
		}
		else{
			$(this).val($.trim($(this).val()));
		};
	});
	$('input.enviar').click(function(){
		$('.hint').each(function(){
			if($.trim($(this).val()) == $(this).attr('title')){
				$(this).val('');
			}
			else{
				$(this).val($.trim($(this).val()));
			};
		});
		$(this).blur();
	});
	//hint

	/*$(".aspas").each(function(){
		$(this).getTwitter({
			userName: "Eduardo_sciarra",
			numTweets: 1,
			loaderText: "Carregando tweet...",
			slideIn: true,
			showHeading: false,
			showProfileLink: false
		});
	});*/
	
$(".fontsize").each(function(){
		fontResizer('12px','12px','15px');
	});

$('#atuacaoContent table tbody tr:even').addClass('alt');

$('#atuacaoContent table tbody tr').mouseover(function() {
		$(this).addClass('over');
	});

$('#atuacaoContent table tbody tr').mouseout(function() {
		$(this).removeClass('over');
	});

$(".podcast").each(function(){
	$mp3 = $(this).attr("rel");

	$(this).flash({ src: '/wp-content/themes/sciarra/swf/player.swf', width: 450, height: 24, flashvars: { soundFile: [$mp3].join(' ') }}, { version: 9 });
});

$(".podcastSmall").each(function(){
	$mp3 = $(this).attr("rel");

	$(this).flash({ src: '/wp-content/themes/sciarra/swf/player.swf', width: 303, height: 24, flashvars: { soundFile: [$mp3].join(' ') }}, { version: 9 });
});

});

/* FONT SIZER VERSION 1.0
 Developed by fluidByte (http://www.fluidbyte.net) */
function fontResizer(smallFont,medFont,largeFont){
	function clearSelected(){
		$(".smallFont, .medFont, .largeFont").removeClass("curFont");
	}
	function saveState(curSize){
		var date = new Date();
			date.setTime(date.getTime()+(7*24*60*60*1000));
		var expires = "; expires="+date.toGMTString(); document.cookie = "fontSizer"+"="+curSize+expires+"; path=/";
	}

	$(".smallFont").click(function(){
		$('.fontsize').css('font-size', smallFont);
		clearSelected();
		$(".smallFont").addClass("curFont");
		saveState(smallFont);
		return false;
	});

	$(".medFont").click(function(){
		$('.fontsize').css('font-size', medFont);
		clearSelected();
		$(".medFont").addClass("curFont");
		saveState(medFont);
		return false;
	});

	$(".largeFont").click(function(){
		$('.fontsize').css('font-size', largeFont);
		clearSelected();
		$(".largeFont").addClass("curFont");
		saveState(largeFont);
		return false;
	});

	function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; }

	var savedSize = getCookie('fontSizer');

	if (savedSize!="") { $('.fontsize').css('font-size', savedSize); switch (savedSize) { case smallFont: $(".smallFont").addClass("curFont"); break; case medFont: $(".medFont").addClass("curFont"); break; case largeFont: $(".largeFont").addClass("curFont"); break; default: $(".medFont").addClass("curFont"); } }
	else { $('.fontsize').css('font-size', medFont); $(".medFont").addClass("curFont"); }
}