			String.prototype.countOccurences = function(s1) {
				return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
			}

			var $loading = $('<span id="imgLoading"><img src="' + urlImage + 'loading.gif" alt="loading"></span>');

			function toggleDisplay(id, toggleElmId) {

				var idToHide = id ;
				var idToToggle = '#' + toggleElmId ;

				$(idToToggle).toggle(
					function() {
						$(idToHide).hide() ;
						$(idToToggle).html('[Show]') ;
					},
					function() {
						$(idToHide).show() ;
						$(idToToggle).html('[Hide]') ;
					}
				) ;
			}


			function setTopMessage(msg, msgClassIn) {

				var msgClass = msgClassIn || 'temporary' ;
				$("#messageContainer").addClass(msgClass) ;
				$("#message").html(msg) ;
				showTopMessage() ;
			}

			function hideTopMessage() {
				$("#topMessageContainer").fadeOut(500) ;
			}

			function showTopMessage() {

				//what type of message is it?
				var messageContainerClass = $('#messageContainer').attr('class') ;

				if (messageContainerClass.indexOf('temporary') != -1) {
					//temp
					$("#topMessageContainer").fadeIn(400).delay(8000).fadeOut(500) ;
				}
				else if (messageContainerClass.indexOf('flashing') != -1) {
					//flashing
					$("#topMessageContainer").pulse({
						opacity: [0.5,1] // pulse between 1 and 0
					}, 200, 2);
				}
				else if (messageContainerClass.indexOf('permanent') != -1) {
					//permanent
					$("#topMessageContainer").fadeIn(400) ;
				}
				else {
					//default, permanent
					$("#topMessageContainer").fadeIn(400) ;
				}

			}

			$(document).ready(function() {

				var message = $("#message").html() ;
				if (message != '') {
					showTopMessage() ;
				}

				$('.tooltipBase').each(function() {
					var elm = $(this) ;
					setupTooltip(elm);
				}) ;

				$('.toggleLink').each(function() {
					toggleDisplay($(this).attr('rel'), $(this).attr('id'));
				}) ;

				if ($('#selectLeagues').length) {
					$('#selectLeagues').change(function() {
						window.location.href = url + this.value ;
					}) ;
				}

				if ($('#selectTeams').length) {

					var currentLeague = $('#selectLeagues').val() ;

					$('#selectTeams').change(function() {
						window.location.href = url + currentLeague + '/' + this.value + '/' + $(this).find(":selected").text() ;
					}) ;
				}

				$("a[rel=teamPhotos]").fancybox({
					'overlayShow'	: false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic'
//					'closeOnClick'  :  true
				});


				var subjectFreeformDefault = "Παρακαλώ εισάγετε το θέμα που επιθυμείτε" ;

				if ($("#subjectSelect").length) {

					$("#subjectSelect").change(function(){

						if ($(this).val() == 'Άλλο..') {
							//show freeform
							$("#subjectFreeformContainer").fadeIn() ;
	//						$("#subjectFreeform").show() ;
							if ($("#subjectFreeform").val() == '') {
								$("#subjectFreeform").val(subjectFreeformDefault) ;
							}
						}
						else {
							$("#subjectFreeformContainer").fadeOut() ;
	//						$("#subjectFreeform").hide() ;
						}
					});

				}

				if ($("#subjectFreeform").length) {

					$("#subjectFreeform").focus(function(){

						if ($(this).val() == subjectFreeformDefault) {
							$(this).val('') ;
						}

					});

					$("#subjectFreeform").focusout(function(){

						if ($(this).val() == '') {
							$(this).val(subjectFreeformDefault) ;
						}

					});

				}

			});


			function setupTooltip(elm, whatIn) {

				var what = whatIn || 'info' ;

//					elm.tooltip() ;
				var imgInfo = urlInclude + '/SexyButtons/images/icons/silk/information.png' ;
				var imgError = urlInclude + '/SexyButtons/images/icons/silk/exclamation.png' ;

				var imgToUse = imgInfo ;
				if (what == 'error') {
					imgToUse = imgError ;
				}

				var tooltipText = elm.attr('title') ;
				var infoSpanId = 'infospanFor-' + elm.attr('id') ;

				//check if already exists
				if ($('#' + infoSpanId).length > 0) {
					//if it already exists it could have a different message, don't just reshow it
					//but delete it first to recreate the tooltip div.
					$('#' + infoSpanId).remove() ;
//					$('#' + infoSpanId).show() ;
//					return true ;
				}

//					var $infoSpan = $('<div id="' + infoSpanId + '" class="info" title="' + tooltipText + '"><span class="infoTextReplace">Info</span></div>');
				var $infoSpan = $('<div id="' + infoSpanId + '" class="divTooltip" title="' + tooltipText + '"><img src="' + imgToUse + '"></div>');

				elm.after($infoSpan) ;

				$($infoSpan).tooltip({
					delay: 0,
					opacity: 1,
					extraClass: "tooltipText",
					track: 1,
					top: -35,
					left: -50,
					bodyHandler: function() {
						return tooltipText ;
					}
				});

				elm.attr('title', '') ;

				if (what == 'error') {
//					$('#' + infoSpanId).pulse() ;
				}

				return true ;

			}

			function hideTooltip(elm) {

				var infoSpanIdJq = '#infospanFor-' + elm.attr('id') ;

				//check if not already exists
				if ($(infoSpanIdJq).length == 0) {
					return false ;
				}

				$(infoSpanIdJq).hide() ;

				return true ;
			}

