var geocoder;
var map;
var marker;
    
function initialize(){
	geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var address = document.getElementById("address").innerHTML.split(' ').slice(1)+', Constanta, Romania';
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map,
            position: results[0].geometry.location
        });
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
}

(function($){
$(document).ready(function() {
	/* TARGET BLANK */
	$("a").filter(function() { return this.hostname && this.hostname !== location.hostname;}).attr('target', '_blank').addClass('ext');
	
	/* CLEAR INPUT */
	$('input:text').each(function(){
		var default_value = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == default_value) $(this).val("");
		});
		$(this).blur(function(){
			if ($(this).val() == "") $(this).val(default_value);
		});
	});
	
	$('#sidebar ul li.widget_links h1').prepend('<span></span>');
	/* AUTO-ICONS for PDF,MAIL */
	$("a[href$='pdf']").addClass("pdf");
	$("a[href*='mailto']").addClass("mail");
	$("a[href$='jpg']").addClass("fancybox");
	$("a.fancybox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	/* GMAPS */
	if ($('#address').html() !=null) {initialize(); };
	
	/* HEADER SLIDER */
	$('.flexslider').flexslider({
          animation: "fade",
		  slideshowSpeed: 7000, 
          controlsContainer: "#slideshow"
    });
	
	/* SIDEBAR SLIDER */
	$('#membri .slidew').flexslider({
          animation: "slide",
		  controlNav: false,
		  slideshowSpeed: 7000, 
          controlsContainer: "#slideshow"
    });
	
	$('#harti li').click(function(){
		if ($('span',this).html()==null) {
			nadd = $(this).html().split(' ').slice(1)+', Constanta, Romania';
		} else {
			nadd = $('span',this).html();
		}
		geocoder.geocode( { 'address': nadd}, function(results, status) {
		  if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
				map: map,
				position: results[0].geometry.location
			});
		  } else {
			alert("Geocode was not successful for the following reason: " + status);
		  }
		});
	});
	
	/* MEMBRI TOOLTIP */
	$('#slider li').hover(function(){
		$('div',this).show(50);
	},function(){
		$('div',this).hide(50);
	});
});

})(jQuery);;

