jQuery(document).ready(function($) {
	
	/* ------------------------------------------------- */
	/* NEWSLETTER 
	/* ------------------------------------------------- */
	$('#SubscriptionAddForm #feedback').hide();
	function initNewsletter()
	{
		$('#SubscriptionAddForm button').unbind('click').click(function(e) {
			e.preventDefault();
			var url = $('#SubscriptionAddForm').attr('action');
			$(this).ajaxStart(function() { $(this).attr('disabled', 'disabled'); })
			$.ajax({
				 url: url,
				type: 'POST',
				data: $.param($('#SubscriptionAddForm #SubscriptionEmail')),
				complete: function() {
					initNewsletter();
				},
				success: function(data, textStatus) {
					if(textStatus == 'success')
					{
						$('#SubscriptionAddForm').replaceWith(data);
					}
				}
			});
			return false;
		}).removeAttr('disabled');
	}
	initNewsletter();
	if($('#gmap').size() > 0) initialize();
	/* ------------------------------------------------- */
	/* ScrollPane
	/* ------------------------------------------------- */
	if($('div.scrollable').size() > 0) $('div.scrollbar').jScrollPane();
	/* ------------------------------------------------- */
	/* SCROLLABLE ACTIVITATION
	/* ------------------------------------------------- */
	if($('div.scrollable').size() > 0) { $("div.scrollable").scrollable({'clickable':false,'size':1}).mousewheel(); }
	/* ------------------------------------------------- */
	/* FOOTER SCROLLER
	/* ------------------------------------------------- */
	$("#scroller").smoothDivScroll({autoScroll:'always',autoScrollDirection:'endlessloop',pauseAutoScroll:'mouseover',scrollingSpeed:1})
	/* ------------------------------------------------- */
	/* PAGINATE PARTNERS
	/* ------------------------------------------------- */
	if($('ul.paginate li').size() > 0) $('ul.paginate li').quickpaginate({perpage:12,showcounter:false,pager:$('#pager')});
	/* ------------------------------------------------- */
	/* PAGINATE PERS
	/* ------------------------------------------------- */
	if($('#press-articles div').size() > 0) $('#press-articles div').quickpaginate({perpage:4,showcounter:false,pager:$('#pager')});
	/* --------------------------------------------------------- */
	/* TEXT RESIZER
	/* --------------------------------------------------------- */
	$('a.resize').click(function(e) {
		e.preventDefault();
		var clicked = $(this).attr('id');
		var ourText = $('h1,p');
		ourText.each(function() {
			var currFontSize = $(this).css('fontSize');
			var finalNum = parseFloat(currFontSize, 10);
			var stringEnding = currFontSize.slice(-2);
			if(clicked == 'large') {
				finalNum *= 1.2;
			}
			else if (clicked == 'small'){
				finalNum /=1.2;
			}
			$(this).css('fontSize', finalNum + stringEnding);
		});
	});
});

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e) {
		this.t = this.title;
		this.title = "";
		$("body").append("<div id='tooltip'>"+ this.t +"</div>");
		$("#tooltip")
			.css("top",(e.pageY + yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
		.css("top",(e.pageY + yOffset) + "px")
		.css("left",(e.pageX - xOffset) + "px")
	});
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});


/* --------------------------------------------------------- */
/* GMAP SHIT
/* --------------------------------------------------------- */
var geocoder;
var map;

function initialize() {
	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(51.04830113331224, 3.72711181640625);
	var myOptions = {
		zoom: 16,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("gmap"), myOptions);
	if($('p.address').size() > 0) codeAddress($('p.address').text());
}

function codeAddress(address) {
  if (geocoder) {
	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);
	  }
	});
  }
}