var $j = jQuery.noConflict();
var active = false;

$j(function(){
	$j('.nextPage,.prevPage').click(function(){
    	var f = $j('#searchform');
    	f.attr('action',$j(this).attr('href'));
    	f.submit();
    	return false;
    });
    
    $j('#submitter').click(function(){
    	var f = $j('#searchform');
    	var uri = f.attr('action');
    	uri = uri.replace(/\&p=\d/,"");
    	uri = uri.replace(/\&ps=\d/,"");
    	f.attr('action',uri);
    	f.submit();
    	return false;
    });
    $j('.special-menu li').stop(true,true).hover(function(){
        $j(this).animate({
            backgroundColor: '#696969'
        },500);
    },function(){
        $j(this).stop(true,true).animate({
            backgroundColor: '#FFFFFF'
        },500);
    });
    /*
    $j('#l339').live('click',function(){
        var obj = $j(this).next();
        if(obj.css('display') != 'block'){
            obj.slideDown();
        }
        else{
            obj.slideUp();
        }
        return false;
    }).next().hide();*/
    $j('.right-menu a').live('click',function(){
        var url = $j(this).attr('href');
        window.open(url,'neu','width=1000, height=700, scrollbars=yes,locationbar=yes,menubar=yes,toolbar=yes');
        return false;
    });
    $j('#show-all').live('click',function(){
        var o = $j('#leftnav');
        var ul = o.find('ul:first');
        if(active != true){
            o.animate({
                height: ul.height()+20
            },'fast');
            $j(this).text('weniger Kategorien anzeigen');
            active = true;
        }
        else{
            o.animate({
                height: 185
            },'fast');
            $j(this).text('alle Kategorien anzeigen');
            active = false;
        }
       $j(this).parent().toggleClass('act');
       return false;
    });
    $j('#brand').live('click',function(){
       if($j(this).val() == 'Welche Marke suchen Sie?'){
           $j(this).val('');
       }
    });
    $j('.print-order').corner('bottom');
    $j('.search-header').corner('top');
    $j('.search-field').corner('bottom');
    $j('#query').click(function(){
        $j(this).val('');
    });
    $j('a[rel=external]').click(function(){
        window.open($(this).attr('href'),'Fenster','width=900,height=700,scrollbars=yes,menubar=yes,toolbar=yes');
        return false;
    });

    $j('.show-result-details').live('click',function(){
       var expander = $j(this).parent().prev();
       $j(this).toggleClass('button-active');
       if(expander.css('display') != 'none'){
            $j(this).html('mehr &raquo;');
            expander.slideUp('slow');
       }
       else{
           expander.slideDown('slow');
           $j(this).html('&laquo; weniger');
       }
       return false;
    });

    $j('.show-search-mask').live('click',function(){
       var expander = $j(this).parent().next();
       $j(this).toggleClass('button-active');
       if(expander.css('display') != 'none'){
            $j(this).html('Suche verfeinern &raquo;');
            expander.slideUp('slow');
       }
       else{
           expander.slideDown('slow',function(){
               //$j('.chzn-select').chosen();
           });

           $j(this).html('Suche verfeinern &raquo;');
       }
       return false;
    });
    $j('.result-details').live('click',function(){
       var expander = $j(this).parent().parent().next();
       if(expander.css('display') != 'none'){
           expander.next().find('.show-result-details:first').toggleClass('button-active');
            expander.next().find('.show-result-details:first').html('mehr &raquo;');
            expander.slideUp('slow');
       }
       else{
           expander.next().find('.show-result-details:first').toggleClass('button-active');
           expander.next().find('.show-result-details:first').html('&laquo; weniger');
           expander.slideDown('slow');
       }
       return false;
    });

    $j('.multiselect').multiselect({
        noneSelectedText: '-- egal --'
    });
    $j('.jq-select').selectBox();
});
