/* DOCUMENT READY FUNCTION */
$(document).ready( function() {

	function getUrlVars()
	{
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
	    return vars;
	}
	
	
	
	var suchListe = getUrlVars()["suche"];
	
	if(suchListe=='koepfe'){
		$('input#koepfe').attr('checked','checked');
		$('.koepfeListe').show();
		$('.companyListe').hide();
	}
	if(suchListe=='company'){
		$('input#company').attr('checked','checked');
		$('.koepfeListe').hide();
		$('.companyListe').show();
	}

	/* suchliste company oder koepfe */
	//

	$('input#koepfe').click(function(){
		if( $('input#koepfe').attr('checked') == true){
			$('.koepfeListe').show();
			$('.companyListe').hide();
		}
	});
	
	$('input#company').click(function(){
		if( $('input#company').attr('checked') == true){
			$('.koepfeListe').hide();
			$('.companyListe').show();
		}
	});
	
	


	var pathname     = window.location.pathname;
    var checkkoepfevor9 = pathname.indexOf('koepfe');
    if(checkkoepfevor9>0){$('body').addClass('special')}
    var checkkoepfevor9 = pathname.indexOf('page/144');
    if(checkkoepfevor9>0){$('body').addClass('special')}
	$('body').show();
	
	setTimeout("$('#userProfileForm .jNiceWrapper').css('z-index','4')",500);
	setTimeout("$('#reg_form_box .jNiceWrapper').css('z-index','4')",900);

$('.Kontaktformular input[type="submit"]').attr('value',' ');


   /* extern links target _blank */
   $('a[href*="http://"]').attr('target','_blank');


   $('#Kontaktformular input').attr('value','');

   /* centerize banner img 

   var imgW = $('.colLeft .newsLine p img').width();
   $('.colLeft .newsLine p img').css('position','relative');
   $('.colLeft .newsLine p img').css('margin-left','50%');
   $('.colLeft .newsLine p img').css('left',imgW/2 * -1 + 'px');*/

/* NAVIGATION */
    if( $('#naviHauptnavigation ul li.node1').hasClass('active') ) {
        $('.navWrapper .navStart').css('background-position','0 0');
    }
    else {
        $('.navWrapper .navStart').css('background-position','0 -44px');
    }


        $('html body ').addClass('blue');
        changeMonthFormat();
        $('a.disabled').attr('onclick','return false');
    
/* COLUMNIZE DISABLED */
/*
$('.colLeftContent').columnize({
        column: 2,
        lastNeverTallest: true
});
*/

Hyphenator.run();

/* TAGCLOUD */

// create a sort by alphabet button
    var sortstrength = $('<a href="javascript:void(0)" class="btnStrength"></a>').toggle(
        function(){
            $("#tags ul li").tsort({
                order:"desc",
                attr:"class"
            });
            $("#tags .btnStrength").css('background-position', '-47px 0');
        },
        function(){
            $("#tags ul li").tsort({
                order:"asc",
                attr:"class"
            });
            $("#tags .btnStrength").css('background-position', '-67px 0');
        }
        );
    $('#tags').append(sortstrength);

// create a sort by alphabet button
    var sortabc = $('<a href="javascript:void(0)" class="btnSort"></a>').toggle(
        function(){
            $("#tags ul li").tsort({
                order:"asc"
            });
            $("#tags .btnSort").css('background-position', '0');
        },
        function(){
            $("#tags ul li").tsort({
                order:"desc"
            });
            $("#tags .btnSort").css('background-position', '-20px 0');
        }
        );
    $('#tags').append(sortabc);

// style tagcloud in the right column as widget
    $('#content .right .TagCloud #tags').wrap('<div class="widgetGrow" />').wrap('<div class="widgetTop" />');
    $('#content .right .TagCloud').append('<div class="widgetBottom"></div>');

    /*$('#content .right .advert').wrap('<div class="widgetGrow adBox" />').wrap('<div class="widgetTop" />');
    $('#content .right .advert').append('<div class="widgetBottom"></div>');*/

});


/* REGISTRATION "VOR9KÖPFE" */
function changeMonthFormat() {
    $('select#registration_birthday_month option, select#userprofile_birthday_month option').each(function () {
        switch($(this).val())
        {
            case '1':
                $(this).html('Jan');
                break;
            case '2':
                $(this).html('Feb');
                break;
            case '3':
                $(this).html('M&auml;r');
                break;
            case '4':
                $(this).html('Apr');
                break;
            case '5':
                $(this).html('Mai');
                break;
            case '6':
                $(this).html('Jun');
                break;
            case '7':
                $(this).html('Jul');
                break;
            case '8':
                $(this).html('Aug');
                break;
            case '9':
                $(this).html('Sep');
                break;
            case '10':
                $(this).html('Okt');
                break;
            case '11':
                $(this).html('Nov');
                break;
            case '12':
                $(this).html('Dez');
                break;
            default:
                break;
        }
    });
}


/****browse button style****/

(function($) {
    
    $.fn.filestyle = function(options) {
                
        /* TODO: This should not override CSS. */
        var settings = {
            width : 250
        };
                
        if(options) {
            $.extend(settings, options);
        };
                        
        return this.each(function() {
            
            var self = this;
            var wrapper = $("<div>")
            .css({
                "width": settings.imagewidth + "px",
                "height": settings.imageheight + "px",
                "background": "url(" + settings.image + ") 0 0 no-repeat",
                "background-position": "right",
                "display": "inline",
                "position": "absolute",
                "overflow": "hidden"
            });
                            
            var filename = $('<input class="file">')
            .addClass($(self).attr("class"))
            .css({
                "display": "inline",
                "width": settings.width + "px"
            });

            $(self).before(filename);
            $(self).wrap(wrapper);

            $(self).css({
                "position": "relative",
                "height": settings.imageheight + "px",
                "width": settings.width + "px",
                "display": "inline",
                "cursor": "pointer",
                "opacity": "0.0"
            });

            if ($.browser.mozilla) {
                if (/Win/.test(navigator.platform)) {
                    $(self).css("margin-left", "-142px");                    
                } else {
                    $(self).css("margin-left", "-168px");                    
                };
            } else {
                $(self).css("margin-left", settings.imagewidth - settings.width + "px");                
            };

            $(self).bind("change", function() {
                filename.val($(self).val());
            });
      
        });
        

    };
	
    
})(jQuery);

