$(document).ready(function() {

	// Login zeigen
	$('a.login').click(function(e) {
		e.preventDefault();
		
		gm_tracker.ManualTrackClick($(this).attr('id'));
  	$.get('http://' + window.location.hostname + '/ajax/refererToSession.php', {referer : encodeURI(window.location)});
		$('#content *').remove();
		$('#content').html('<div id="loginFrame"></div>');
		$('#loginFrame').html('<iframe src="http://' + window.location.hostname + '/abo/login_zentral/" name="login" style="height: 1000px; width: 670px;" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"><p>Ihr Browser kann leider keine iFrames anzeigen</p></iframe>');
  	$('#sidebar').height($('#content').height());
		/*$('#loginFrame').load('/login_zentral_temp/login.php');*/
	});
    
  // Login zeigen
	$('a.register').click(function(e) {
		e.preventDefault();
		
		gm_tracker.ManualTrackClick($(this).attr('id'));
		
  	$.get('http://' + window.location.hostname + '/ajax/refererToSession.php', {referer : encodeURI(window.location)});
		$('#content *').remove();
		$('#content').html('<div id="loginFrame"></div>');
		$('#loginFrame').html('<iframe src="http://' + window.location.hostname + '/abo/login_zentral/register.php" name="login" style="height: 1000px; width: 670px;" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"><p>Ihr Browser kann leider keine iFrames anzeigen</p></iframe>');
  	$('#sidebar').height($('#content').height());
		/*$('#loginFrame').load('/login_zentral_temp/login.php');*/
	});

	// Logout
	$('a.logout').click(function(e) {
		e.preventDefault();
		$.get('/abo/login_zentral/login.php', {a :'logout'}, function() {
			window.location = 'http://' + window.location.hostname + '/';
		});
	});
	
	// Accountdetails
	$('a.detail').click(function(e) {
		e.preventDefault();
		
		$('#content *').remove();
		$('#content').html('<div id="loginFrame"></div>');
		$('#loginFrame').html('<iframe src="http://' + window.location.hostname + '/abo/login_zentral/as_login_list.php" name="login" style="height: 1000px; width: 670px;" scrolling="no" marginheight="0" marginwidth="0" frameborder="0"><p>Ihr Browser kann leider keine iFrames anzeigen</p></iframe>');
  	$('#sidebar').height($('#content').height());
		//$('#loginFrame').load('/abo/login_zentral/as_login_list.php');
	});
  
	if($("#author").lendth != 0) {
    $('#content').height("auto");
  }

	// Content und Sidebar anpassen	
	$('#sidebar').height($('#content').height());

	

	$('.search input.searchText').defaultText('Suchbegriff');
	
	$('.search a.submit').live('click', function(e) {
		e.preventDefault();
		if ($('.search input.searchText').val() != 'Suchbegriff') {
			$('.searchForm').submit();
		} else {
			$(location).attr('href', 'http://' + window.location.hostname + '/suche/');
		}
	});
	
	$('.searchForm').submit(function(e) {
	  $('.close').remove();
    $("#overlay").fadeIn(function() {
      $("body").css({overflow: "hidden"});
      $(".wait").show();
    });
	});

	$("a").each(function() {
	  var destination = $(this).attr("href");
	  if(typeof(destination) !== "undefined" && destination != null) {
		  var split = destination.split("##");
		  $(this).attr("href", split[0]);
		  if( split.length > 1) {
		    $(this).attr("title", split[1]);
		  }
	  }
	});
  

  $('#search form').submit(function(e) {
	  $('.close').remove();
    $("#overlay").fadeIn(function() {
      $("body").css({overflow: "hidden"});
      $(".wait").show();
    });
  });

});

//Plugin für den Platzhalter-Text
$.fn.defaultText = function(value) {

	var element = this.eq(0);
	element.data('defaultText', value);

	element.focus(function() {
		if (element.val() == value) {
			element.val('').removeClass('defaultText');
		}
	}).blur(function() {
		if (element.val() == '' || element.val() == value) {
			element.addClass('defaultText').val(value);
		}
	});

	return element.blur();
}
