var date = new Date();
swfobject.embedSWF("fileadmin/mga/flash/lui-banner.swf?_t="+date.getDate()+date.getTime()+date.getMilliseconds(), "flashContainer", "490", "75", "9.0.0", "expressInstall.swf");

var $j = jQuery.noConflict();

function rand(min,max){
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

$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('#topBanner').attr('src','fileadmin/mga/images/banner35-'+$j.cookie('header'));
    if(!$j.cookie('header') || !$j.cookie('logo')){
        $j.cookie('header',rand(0,1));
        $j.cookie('logo',rand(0,1));
    }

    $j('#topBanner').attr('src','fileadmin/mga/images/banner35-'+$j.cookie('header'));
    $j('#logo').attr('src','fileadmin/mga/images/mga-logo-'+$j.cookie('logo'));*/
    
    $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();
    /*
    $j('#cats').live('change',function(){
       var selected = $j(this).val();
       var form = $j('#searchform');
       $j.each('.sc-check',function(){
          form.remove($j(this));
       });
       if(selected != null){
            for(var i = 0;i<selected.length;i++){
                var check = $j('<input type="hidden" name="'+selected[i]+'" value="1" class="sc-check" />');
                check.appendTo(form);
            };
       }
    });*/
    /*
    $j('#options').live('change',function(){
       var selected = $j(this).val();
       var form = $j('#searchform');
       $j.each('.opt-check',function(){
          form.remove($j(this));
       });
       if(selected != null){
            for(var i = 0;i<selected.length;i++){
                var check = $j('<input type="hidden" name="'+selected[i]+'" value="1" class="opt-check" />');
                check.appendTo(form);
            };
       }
    });*/
});
