$(document).ready(function(){
	//target blank
	$("a[href^='http://']").attr('target','_blank');
	$("a[href^='http://']").addClass('extern');
	$("a.extern").attr('target','_blank');
	
//	$("a[href$=.pdf]").addClass('pdf');
	$("a[href$=.doc]").addClass('doc');
	$("a[href$=.xls]").addClass('xls');
	$("a[href$=.docx]").addClass('docx');
	$("a[href^=mailto]").addClass('mailto');
	
	$("ul li:first-child").addClass('first');
	$("ul li:last-child").addClass('last');


	//for special effects in the navi
	$('#navigation ul ul').parent().addClass('sub');
	
	//fix the corner for hovers
	$('#navigation ul ul').parent().mouseover(function(){
		$(this).children('a').addClass('corner');
	});
	$('#navigation ul ul').parent().mouseout(function(){
		$(this).children('a').removeClass('corner');
	});
		
	
	$('#navigation li.sub').mouseover(function(){
		$(this).addClass('hover');
	});
	
	$('#navigation li.sub').mouseout(function(){
		$(this).removeClass('hover');
	});


	$('#branding a.extern').attr('target','_self');
	$('#navigation a.extern').attr('target','_self');
	
	
	 $("input[type=file]").filestyle({ 
		 image: "files/_img/choose-file.gif",
		 imageheight : 21,
		 imagewidth : 98,
		 width : 140
	 });

	$('.formlabel-steckbrief textarea').attr('maxlength',1300);
    $('.formlabel-steckbrief textarea').keyup(function(){
        var max = parseInt($(this).attr('maxlength'));

        if($(this).val().length > max){
            $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
        }
 
        $(this).parent().find('.charsRemaining').html('' + (max - $(this).val().length) + ' Zeichen');
    });

	$('a.abstimmen').click(function(){
		$(this).trigger('blur');
		sportler = $(this).attr('rel');
		$('#voting .form_vote input').removeAttr('checked');
		$('#voting .form_vote input[value="'+sportler+'"]').attr('checked','checked');
		$.scrollTo('#voting',1000,function(){
			
			//$('#voting form').trigger('submit');
		});
		
		return false;
	});



	if (document.attachEvent)
	{
		// Suckerfish Hovers
		// Hinweis: Wenn es im html kein Element mit id="navigation" gibt, getElementById("navigation") loeschen oder austauschen
		var sfEls = document.getElementById("navigation").getElementsByTagName("UL")[0].getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}


	
});