$(document).ready(function() {
						   
	$('#uploadnow').slideDown('slow');
						   
	var first = 0;
	var speed = 700;
	var pause = 3500;
	
	var speed = 700;
	var pause = 4000;
	
	function newsticker()
	{
	    // algorithm:
	    // get last element, remove it from the list,
	    // add to first position with hidden style
	    // slideDown the new first element
	    // continue
	    last = $('ul#listticker li:last').hide().remove();
	    $('ul#listticker').prepend(last);
        $('ul#listticker li:first').slideDown("slow");
	}
	
	interval = setInterval(newsticker, pause);
						   
 	var a = $('#suchfeld').autocomplete({ 
  	 serviceUrl:'/direct.php',
  	 minChars:3, 
  	 delimiter: /(,|;)\s*/, // regex or character
   	 maxHeight:400,
   	 width:220,
   	 zIndex: 9999,
   	 deferRequestBy: 400, //miliseconds
   	 params: { }, //aditional parameters
   	 // callback function:
   	 onSelect: function(value, data){ window.location = data; },
   	 // local autosugest options:
   	 //lookup: ['Game icons v1', 'Retweet webSPELL-News using Tweetmeme', 'BBCode Mod v2.7', 'Top User addon', 'Forum Polls V1.1', 'WS Cart [Shop addon]', 'Shoutbox - Only registered', 'Shoutbox User Links V1.0', 'News Jumper', 'Game Icon Pack 2', 'Twitter', 'Skype', 'Icons', 'Shop', 'Tweetmeme', 'Pagination', 'Jumper', 'Tweetr'] //local lookup values 
  	});

	$("#navblog").hover(function(){
		$("#blogsub").toggle();
		return false;
	}, function() {
      $('#blogsub').toggle();
 	});
	
	$("#blogsub").hover(function(){
		$("#blogsub").toggle();
		return false;
	}, function() {
      $('#blogsub').toggle();
 	});
						   
	$("#gettweets").click(function(){
	  $("#twitterupdates").getTwitter({ 
		userName: "weSEOde",
		numTweets: 3, loaderText: "Loading tweets...",
		slideIn: true, showHeading: true,
		headingText: "Latest Tweets", showProfileLink: false
	  });
	 });
						   						   
	// Expand Panel
	$("#jqopen").click(function(){
		$("div#jqpanel").slideDown("slow");
	
	});

	$(".slidepanel").click(function(){
		$("div#jqpanel").slideDown("slow");
	
	});	
	
	
	// Collapse Panel
	$("#jqclose").click(function(){
		$("div#jqpanel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#jqtoggle a").click(function () {
		$("#jqtoggle a").toggle();
	});	
						   
	$('.lovethis').ajaxForm(function() {							 
    	$('.message').hide();
		
		var anzloves = parseInt($(".anzahl").html(),10)
		anzloves++;
		$(".anzahl").hide().fadeIn('slow').html('<br />'+anzloves);

    }); 
	
	//When page loads...
	$("ul.dltabs li:first").addClass("active").show(); //Activate first tab
	$(".dltab_content:first").show(); //Show first tab content
	
	$("ul.commentstabs li:first").addClass("active").show(); //Activate first tab
	$(".commentstab_content:first").show(); //Show first tab content
		
	$("ul.blogtabs li:first").addClass("active").show(); //Activate first tab
	$(".blogtab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.dltabs li").click(function() {

		$("ul.dltabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".dltab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		
		return false;
	});
	
	$("ul.commentstabs li").click(function() {

		$("ul.commentstabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".commentstab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});	
	
	$("ul.blogtabs li").click(function() {

		$("ul.blogtabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".blogtab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
function limitChars(textid, limit, infodiv)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

$(function(){
 	$('#shortinfo').keyup(function(){
 		limitChars('shortinfo', 140, 'charlimitinfo');
 	})
});


						   
// <HEADER> -------------------------------------------------------------------------------

 // span-Tag hinzufügen
 $('#header .right').append('<span></span>');
 
 // Mousover Event (Titel des <img /> anzeigen)
 /*$('#header .right img').mouseenter(function() {
  $('#header .right span')
   .hide()
   .fadeIn(700)
   .html(this.title);
 });*/
 
 // Click Event (Externe Datei laden)
 $('#header .right img').click(function() {
	$('.containerfirst').addClass('container');
	$('.containerfirst').removeClass('containerfirst');
    $('#header .right span').html('');
	if(this.className == 'login') var dateiname = '../templates/login.html';
	if(this.className == 'lostpw') var dateiname = '../templates/lostpw.html';
	if(this.className == 'register') var dateiname = '../templates/register.html';	
	$('<div class="do" />').load(dateiname+ '#holmich', function() {
	$(this).hide().appendTo('#header .right span').fadeIn(800);
	});
	return false;
  });
 



// </HEADER> -------------------------------------------------------------------------------

// <MIDDLE> --------------------------------------------------------------------------------

// SIDEBAR

  // Klasse -active- für jeweiligen block entfehrnen.
  $('#blogposts .stayopen ul').mouseover(function() {
	$('#blogposts .stayopen ul li').removeClass();						   
  });
  $('#latestdownloads .stayopen ul').mouseover(function() {
	$('#latestdownloads .stayopen ul li').removeClass();						   
  });
  $('#downloads .stayopen ul').mouseover(function() {
	$('#downloads .stayopen ul li').removeClass();						   
  });
  $('#comments .stayopen ul').mouseover(function() {
	$('#comments .stayopen ul li').removeClass();						   
  });


  // Klasse -active- setzen
  $('#sidebar ul.clear li').mouseout(function() {
	$(this).addClass('active');
  });  


// CONTENT

 // FEATURED DOWNLOADS
  
  $('#featuredimg').cycle({ 
    delay:  2000, 
    speed:  550, 
	prev:   '#prev', 
    next:   '#next',
	pause: true,
    before: onBefore 
  }); 
  
 $('#featureddesc').hover(function() {
    $('#featuredimg').cycle('pause');
 }, function() {
    $('#featuredimg').cycle('resume');
 });
 
 
  function onBefore() { 
    $('#featuredtitle') 
        .html(this.title);
	$('#featureddesc')
	    .html('<a href="'+this.href+'"><img src="/design/icons/info.gif" alt="Info" border="0"></a>');
  }; 


// </MIDDLE> --------------------------------------------------------------------------------




						   
/*	$('#allregusers div').quicksearch({
  		position: 'before',
  		attached: '#allregusers',
  		loaderText: '',
 		delay: 100
	})*/					   

	/*$('.readmorelink').click(function(){

		var id     = $(this).attr('rel');
		var toLoad = '/news_more.php?newsID='+id;
		var myhash = $(this).attr('href');
		myhash = myhash.replace('/blog/','');
		
		//$('#news'+id+'').hide('fast',loadContent);
		$('#news'+id+'').load(toLoad,'',showNewContent())  
		$('#news'+id+'').html('<span id="load"><b>LOADING...</b></span>');  
		  
		window.location.hash = myhash;
	
		function loadContent() {  
			$('#news'+id+'').load(toLoad,'',showNewContent())  
		} 
		function showNewContent() {  
			$('#news'+id+'').show('normal',hideLoader());  
		}
		
		function hideLoader() {  
			$('#load').fadeOut('normal');  
		} 		
		
		return false;
		

		
	});	*/
 					   											

});
