document.write('<style type="text/css">#galleryElements li, #nextCongressElements li, #twitterElements li {display:block;}</style>');


/* TABLE SORTER */



 /* TOOLTIP */
 
 $(document).ready(function() {
    $("#newEventForm .tooltip").hover(
      function() { $(this).find("span.tooltipContent").css({ display: "block" }); },
      function() { $(this).find("span.tooltipContent").css({ display: "none" }); }
    );
});
 
$(document).ready(function() {
    $(".tooltips").hover(
	function() { $(this).contents("span.tooltipContent:last-child").css({ display: "block" }); },
	function() { $(this).contents("span.tooltipContent:last-child").css({ display: "none" }); }
    );
    $(".tooltips").mousemove(function(e) {
        var mousex = e.pageX -200;
        var mousey = e.pageY + 5;
        $(this).contents("span.tooltipContent:last-child").css({  top: mousey, left: mousex });
    });
});

function popup (url) {
 fenster = window.open(url, "Facebook", "width=800,height=400,resizable=yes,top=200, left=200");
 fenster.focus();
 return false;
}
 
 
 /* ACCORDION  */
	
 $(document).ready(function() {
		// simple accordion
		$('#list1b').accordion({
			autoheight: false
		});
		
		$('#themes').accordion({
			autoheight: false

		});
		
		$('#suche').accordion({
			autoheight: false,
			active: false
		});
});
 
  $(document).ready(function() {
			$("#headerUp").click(function () {
			$("#head-image").slideToggle("slow");
			});
			
			$("#headerUp").click(function () {
			$("#head-image-transparent").slideToggle("slow");
		    });
			
			$("#headerDown").click(function () {
			$("#head-image").slideToggle("slow");
			});
			
			$("#headerDown").click(function () {
			$("#head-image-transparent").slideToggle("slow");
		    });
			
			$("#headerDown").click(function () {
			$('#headerDown').hide('slow', function() {});
			$('#headerUp').show('slow', function() {});
			});
		  
			$("#headerUp").click(function () {
			$('#headerUp').hide('slow', function() {});
			$('#headerDown').show('slow', function() {});
			
		
		});
	 });
	
	$(document).ready(function() {
		$('.rmv-dft-val').click(
			function() {
			if (this.value == this.defaultValue) {
			this.value = '';
			}
		});
		$('.rmv-dft-val').blur(
			function() {
			if (this.value == '') {
			this.value = this.defaultValue; }
		});
	});
	

/* CONTAINER SLIDER */
	
$(document).ready(function() {
	<!-- Example -->
	$("#kongressSlider").multipleElementsCycle({
		elementContainer: '#kongressElements',
		prevElement: '#kongressLeft',
		nextElement: '#kongressRight',
		speed: 500,
		overrideStart: 0,
		showCount: 1
	});
	
});

$(document).ready(function() {
	<!-- Example -->
	$("#gallerySlider").multipleElementsCycle({
		elementContainer: '#galleryElements',
		prevElement: '#galleryLeft',
		nextElement: '.galleryRightImage',
		speed: 500,
		overrideStart: 0,
		showCount: 1
	});
	
});

$(document).ready(function() {
	<!-- Example -->
	$("#nextCongressSlider").multipleElementsCycle({
		elementContainer: '#nextCongressElements',
		prevElement: '#nextCongressLeft',
		nextElement: '#nextCongressRight',
		speed: 500,
		overrideStart: 0,
		showCount: 1
	});
	
});

$(document).ready(function() {
	<!-- Example -->
	$("#mmeBlogSlider").multipleElementsCycle({
		elementContainer: '#mmeBlogElements',
		prevElement: '#mmeBlogLeft',
		nextElement: '#mmeBlogRight',
		speed: 500,
		overrideStart: 0,
		showCount: 1
	});
	
});

$(document).ready(function() {
	<!-- Example -->
	$("#twitterSlider").multipleElementsCycle({
		elementContainer: '#twitterElements',
		prevElement: '#twitterLeft',
		nextElement: '#twitterRight',
		speed: 500,
		overrideStart: 0,
		showCount: 1
	});
	
});

  $(document).ready(function() {
    
    $('a.external').attr('target', '_blank');
    
    $('#navStartcenter > ul').startcenterNav({ fadeSpeed: 650});
	$('#loggedIn > ul').startcenterNav({ fadeSpeed: 650});
	
	});
  
  (function($){

    $.fn.startcenterNav = function(){
        
        var o = {
            fadeSpeed : 600,
            subTimeout : null
        }
        
        o = jQuery.extend(o);
        
        return $(this).each(function() {
            
            var lis = $(this).children('li');
            
            /*lis.children('a').hover(
                function() {
                    
                    $(this).siblings('.levelSub').stop(true, true).slideDown(o.fadeSpeed);
                },
                function() {
                  $(this).siblings('.levelSub').stop(true, true).slideUp(o.fadeSpeed);
                }
	        );
			
			lis.hover(
				
                function() {
		           //$(this).children('.levelSub').css('display', 'none');
                },
                function() {
                    //$(this).children('.levelSub:hidden').css('display', 'block');
                    //$(this).children('.levelSub').stop(true, true).slideUp(o.fadeSpeed);
                }
            );*/
          
          lis.mouseenter(function() {
            $(this).children('.levelSub').stop(true, true).slideDown(o.fadeSpeed);
          }).mouseleave(function() {
            $(this).children('.levelSub').stop(true, true).slideUp(o.fadeSpeed);
          });
          
        });
    }
    
})(jQuery)
  		
$(function(){
    $('a.extern').click(function(){
        window.open(this.href);
        return false;
    });
});


$(document).ready(function() {
		// Alle internen Links auswählen
		$('a[href*=#]').bind("click", function(event) {
      if($(this).parent('td.actions').length > 0)
        return true;
			// Standard Verhalten unterdrücken
			event.preventDefault();
			// Linkziel in Variable schreiben
			var ziel = $(this).attr("href");
			//Browserweiche
			if ($.browser.opera) {
                    //Wenn Browser Opera
					var target = 'html';
                }else{
					//Wenn der Browser NICHT Opera
                    var target = 'html,body';
                }
			//Scrollen der Seite animieren, body benötigt für Safari
			//Variable für Browserweiche
			//$('html,body').animate({
			$(target).animate({
				//Zum Ziel scrollen (Variable)
				scrollTop: $(ziel).offset().top
			// Dauer der Animation und Callbackfunktion die nach der Animation aufgerufen wird, sie stellt das Standardverhalten wieder her und ergänzt die URL
			}, 1000 , function (){location.hash = ziel;});
	   });
	return false;
	});


/*
 *  autosuggest & overlays VA hinzufuegen
 */
 
// autosuggest
(function($) {
	 
	var VAAjaxRequest = null;
	var openAutosuggest = null;
	
	$.fn.autosuggest = function(o) {
    $('.autosuggestInfo .empty').live('click', function() {
      $.autosuggest.unpopulate($(this));
    });
		return this.each(function() {
			var $t = $(this);
			var idField = $(this).siblings('#'+$(this).attr('id')+'ID');
			var id = $t.attr('id').toLowerCase();
			var autosuggest = $.autosuggest.init(id, $t);
			var autosuggestList = autosuggest.find('ul');
			$t.keyup(function(e) {
				e.stopPropagation();
				e.preventDefault();
				if($t.val().length < 3) {
					if (autosuggest.length != 0) {
						$.autosuggest.hide(autosuggest);
						autosuggestList.empty();
					}
					return false;
				}
				$.autosuggest.show(autosuggest);
				if ($.inArray(e.keyCode, [13,27,38,40]) != -1) {
					switch(e.keyCode) {
						case 13:
							if(autosuggestList.find('.active').length > 0)
								autosuggestList.find('.active').click();
						break;
						case 27:
							$.autosuggest.hide(autosuggest);
							autosuggestList.empty();
						break;
						case 38:
							var active = autosuggestList.find('.active');
							if(active.length == 0) {
								active = autosuggestList.children(':last');
							} else {
								active.removeClass('active');
								active = active.prev().length > 0 ? active.prev() : autosuggestList.children(':last');
							}
							active.addClass('active');
						break;
						case 40:
							var active = autosuggestList.find('.active');
							if(active.length == 0) {
								active = autosuggestList.children(':first');
							} else {
								active.removeClass('active');
								active = active.next().length > 0 ? active.next() : autosuggestList.children(':first');
							}
							active.addClass('active');
						break;
					}
					return false;
				}
				$.autosuggest.sendRequest(id, $t.val(), function(answer) {
					//console.log(answer);
					if($(answer).length == 0)
						$.autosuggest.hide(autosuggest);
					autosuggestList.empty();
					var answerArr = {};
					$(answer).each(function() {
						answerArr[this.id] = this;
						var title = '';
						switch(id) {
							case 'veranstaltungsort':
								var titleArr = [];
								if ($.trim(this.title)) titleArr.push($.trim(this.title));
								if ($.trim(this.address)) titleArr.push($.trim(this.address));
								if ($.trim(this.address2)) titleArr.push($.trim(this.address2));
								if ($.trim(this.city)) titleArr.push($.trim(this.city));
								title = titleArr.join(', ');
							break;
							case 'veranstalter':
								var titleArr = [];
								if ($.trim(this.company)) titleArr.push($.trim(this.company));
								if ($.trim(this.company2)) titleArr.push($.trim(this.company2));
								title = titleArr.join(', ');
							break;
							case 'organisator':
								title = $.trim(this.company);
							break;
						}
						
						var regex = new RegExp('('+$t.val()+')', 'i');
						title = title.replace(regex, '<strong>$1</strong>');
						autosuggestList.append($('<li>'+title+'</li>').data('vo_id', this.id));
					});
					autosuggest.find('li').click(function(e) {
						e.stopPropagation();
						e.preventDefault();
						
						var data = answerArr[$(this).data('vo_id')];
						
						$.autosuggest.populate($t, data);
						
						$.autosuggest.hide(autosuggest);
						autosuggestList.empty();
					}).hover(function() { $(this).addClass('active'); }, function() { $(this).removeClass('active'); });
				});
			});
			$(document).bind('click.autosuggest', function() {
				$.autosuggest.hide(autosuggest);
				autosuggestList.empty();
			});
		});
	}
	
	$.autosuggest = new function() {
		
		this.init = function(id, element) {
			var $autosuggest = element.siblings('.autosuggestResults');
			if($autosuggest.length == 0) {
				element.after('<div class="autosuggestResults" style="display: none"><ul /></div>');
				$autosuggest = element.siblings('.autosuggestResults');
			}
			return $autosuggest;
		}
		
		this.show = function(a) {
			a.stop().fadeTo(200, 1);
			$(document).bind('keydown.autosuggest', function(e) {
				if($.inArray(e.keyCode, [13,27,38,40]) != -1) {
					e.stopPropagation();
					e.preventDefault();
					return false;
				}
			})
		};
		
		this.hide = function(a) {
			a.stop().fadeTo(200, 0, function() {
				$(this).css({ display: 'none' });
			});
			$(document).unbind('keydown.autosuggest');
		}
		
		this.sendRequest = function(id, val, cb) {
			if (VAAjaxRequest != null)
				VAAjaxRequest.abort();
			VAAjaxRequest = $.ajax({
				url: 'http://www.my-medical-education.com/cms/mme/index.php',
				type: 'get',
				dataType: 'json',
				data: 'page=new_event_ajax_search&search='+id+'&term='+val,
				success: function(answer){
					cb(answer);
				}
			});
		}
		
		this.populate = function(what, data) {
			var whatID = what.siblings('#'+what.attr('id')+'ID');
			
			what.val(($.trim(data.title) || $.trim(data.company) || $.trim(data.company2) || $.trim(data.city)));
			if ($.trim(data.id))
				whatID.val($.trim(data.id));
			
			if(what.siblings('.autosuggestInfo').length > 0)
				what.siblings('.autosuggestInfo').remove();
	
			var info = '';
			if($.trim(data.company2)) info += $.trim(data.company2) + '<br />';
			if($.trim(data.address)) info += $.trim(data.address) + '<br />';
			if($.trim(data.address2)) info += $.trim(data.address2) + '<br />';
			if($.trim(data.zip)) info += $.trim(data.zip) + ' ';
			if($.trim(data.city)) info += $.trim(data.city) + '<br />';
			if($.trim(data.country_name)) info += $.trim(data.country_name) + '<br />'; // tel, fax, email, url
      if($.trim(data.phone) || $.trim(data.fax) || $.trim(data.email) || $.trim(data.website_url)) info += '<br />';
      if($.trim(data.phone)) info += $.trim(data.phone) + '<br />';
      if($.trim(data.fax)) info += $.trim(data.fax) + '<br />';
      if($.trim(data.email)) info += $.trim(data.email) + '<br />';
      if($.trim(data.website_url)) info += $.trim(data.website_url) + '<br />';
			if(info != '');
				what.parent().append('<div class="autosuggestInfo"><div class="empty"></div>'+info+'</div>');
			
		}
    
    this.unpopulate = function(what) {
      what.parents('.autosuggestInfo').siblings('input[type=text]').val('');
      what.parents('.autosuggestInfo').siblings('input[type=hidden]').val('');
      what.parents('.autosuggestInfo').remove();
    }
    
	}
	
})(jQuery);

$(document).ready(function() {
	if($('#newEventForm').find('a.neuVeranstaltungsort, a.neuVeranstalter, a.neuOrganisator').length > 0) {
		$('#newEventForm').find('a.neuVeranstaltungsort, a.neuVeranstalter, a.neuOrganisator').unbind('click').click(function(e) {
			e.preventDefault();
			e.stopPropagation();
      
      var id = $(this).attr('class').replace(/neu/, '');
      var url = 'http://www.my-medical-education.com/cms/mme/index.php?page=new_event_' + id.toLowerCase();
      
			tb_show_addVA(id + ' hinzuf&uuml;gen', url, function() {
				$('#TB_ajaxContent').find('#newEventLocationForm, #newEventContactForm, #newEventOrganizerForm').submit(function(e) {
					e.preventDefault();
					e.stopPropagation();
					
					$.post(
						$(this).attr('action'),
						data = $(this).serialize(),
						function(answer) {
							if(!answer.result || answer.result == 'error') {
								var errorMessagesHTML = '';
								$(answer.errors).each(function() {
									errorMessagesHTML += '<p>' + this.message + '</p>';
								});
								$('#TB_ajaxContent .AJAXcontent').children('div.errors').remove();
								$('#TB_ajaxContent .AJAXcontent').prepend(
									'<div class="errors errorsRed">' + errorMessagesHTML + '</div>'
								);
                $('#TB_ajaxContent').scrollTop(0);
								//TB_HEIGHT = $('#TB_ajaxContent').children().outerHeight();
								//$('#TB_ajaxContent').height(TB_HEIGHT);
								//tb_position();
							}
							else if(answer.result == 'success') {
								var $t = $('input#' + id);
								
								$.autosuggest.populate($t, answer.data);
								
								tb_remove();
							}
						}
					);
					
					return false;
				});
			});
			return false;
		});
	}
	
	$('#newEventForm').find('input#Veranstaltungsort, input#Veranstalter, input#Organisator').autosuggest().attr('autocomplete', 'off');
	
});
 
// custom tb show fuer VA hinzufuegen
tb_show_addVA = function(caption, url, callback) {
	TB_WIDTH = 765;
	TB_HEIGHT = 470;
	if(document.getElementById("TB_overlay") === null){
		$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
		$("#TB_overlay").click(tb_remove);
	}
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}
	$("body").append("<div id='TB_load'><img src='images/loadingAnimation.gif' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
	
	$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+TB_WIDTH+"px;height:"+TB_HEIGHT+"px'></div>");
	$("#TB_closeWindowButton").click(tb_remove);
	
	$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
		tb_position();
		$("#TB_load").remove();
		$("#TB_window").css({display:"block"});
		if (callback)
			callback();
	});
}
