/* <![CDATA[ */


function filtersetter(operator, setter, catid){
    
   var $operator =  $('#'+operator+'select');
    
   if(setter == 'all'){
       $operator.html('');
   } else {
  
 $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {AjaxRequestAction : 'getproducts', type: operator, catid: catid},
        dataType: "html",
        timeout: 5000,
        beforeSend: function(xhr) {
            $operator.addClass('load');
            $('#start_filter').addClass('disabeld');
           
            xhr.setRequestHeader("Ajax-Request", "true");
        },
        success: function(response) {
            $operator.removeClass('load');
            $('#start_filter').removeClass('disabeld');
             $operator.html(response);
                $('#prozspezial').tzSelect({
                        render : function(option){
                                return $('<li>',{
                                        html:	'<span>'+option.text()+'</span>',
                                        id: option.val()
                                });
                        },
                        className : 'prozdetail',
                        click: function(){
                            detailview('proz');
                        }
                });
            
        }
 });    
    
  }    
   
}

function detailview(op){

$operator = $('#'+op+'spezial');
selected = $operator.val();

   if($operator.val() == 'all'){
       $('#'+op+'flt').find('.detail').remove();
   } else {
         $.ajax({
                type: "POST",
                url: "ajax.php",
                data: {AjaxRequestAction : 'getproductsdetails', id: selected, operator: op},
                dataType: "html",
                timeout: 5000,
                beforeSend: function(xhr) {
                    $('#start_filter').addClass('disabeld');
                    $('#prozselect').append('<div class="load"></div>');
                    xhr.setRequestHeader("Ajax-Request", "true");
                   
                },
                success: function(response) {
                    $('#prozselect').find('.load').remove();
                    $('#start_filter').removeClass('disabeld');
                    $('#'+op+'flt').find('.detail').remove();
                    $(response).insertAfter('#'+op+'spezial_tz');
                     $('#prozdetail').tzSelect({
                            render : function(option){
                                    return $('<li>',{
                                            html:	'<span>'+option.text()+'</span>',
                                            id: option.val()
                                    });
                            },
                            className : 'hasDetails'
                    });
$('#prozdetail_tz').css({'margin-top': '3px'});
                }
         });    
  }  

}


$(function() {
   
	
	$('#sorting').tzSelect({
		render : function(option){
			return $('<li>',{
				html:	'<span>'+option.text()+'</span>'
			});
		},
		className : 'sorting',
                click: function(){
                            
                        }
	});

	$('#graka').tzSelect({
		render : function(option){
			return $('<li>',{
				html:	'<span>'+option.text()+'</span>'
			});
		},
                className : 'hasDetails'
	});

	// Calling the default version of the dropdown
	$('select.regularSelect').tzSelect();
        
        
   //fallback if js dis.
   
  
   $('#prozflt select:first').attr('checked', 'checked');
   
   $( "#slider-range" ).slider({
			range: true,
			min: 0,
			max: 2000,
                        step: 50,
			values: [ 0, 2000 ],
			slide: function( event, ui ) {
				$( "#min" ).val( ui.values[ 0 ] );
                                $( "#max" ).val( ui.values[ 1 ] );
                               
                               $( "#pricerange" ).html( $( "#min" ).val() +
                                                        "&euro; bis " + $( "#max" ).val() + '&euro;');
			}
		});
                               $( "#pricerange" ).html( $( "#min" ).val() +
                                                        "&euro; bis " + $( "#max" ).val() + '&euro;');

   
});    

function cab_requestData() {
    if($("a.switch_thumb").hasClass('swap')){
        switchTemplate('list');
        return false;
    } else {
    var prozdata = new Array();

    prozdata[0] = new Object();
    prozdata[0]["filtercat"] = $("#prozflt input:checked").val();
    prozdata[0]["filterchild"] = $("#prozflt select").val();    
    prozdata[0]["detail"] = $("#prozflt #prozdetail").val();  
    
 
    $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {AjaxRequestAction: 'filter' , min : $("#min").val(), max: $("#max").val(), cpath: $("#cpath").val(), sorting:$("#sorting").val(), proz:prozdata , graka: $('#graka').val()},
        dataType: "html",
        cache: false,
        timeout: 5000,
        beforeSend: function(xhr) {
            $("#filtercontent").empty();
            $("#filtercontent").addClass('loader');   
        },
        success: function(response) {
            $("#filtercontent").removeClass('loader');
            $("#filtercontent").html(response).fadeIn();
            $('.thickbox').colorbox({
                    width: '50%',
                    height: '50%'
            });
        },
        statusCode: {
            404: function() {
              $("#filtercontent").empty();
              $("#filtercontent").removeClass('loader');
              $("#filtercontent").html('Oops. Ein fehler ist aufgetreten. Fehler 404.');
            }
          },
          error: function(){
              $("#filtercontent").empty();
              $("#filtercontent").removeClass('loader');
              $("#filtercontent").html('Ein fehler ist aufgetreten.');           
          }

    });
    }
    return false;
} 

$(function() {



$('#start_filter').bind('click', function(){
   
   if($(this).hasClass('disabeld')){
       return false;
   } else {
       cab_requestData();
       return false;
   }
   
});

  $('#prozessor_manufactors').bind('change', function(){
        
        if($('#prozessor_manufactors').val() == 'all'){
            $('#proz_sorting').css({
                'display': 'none'
            });
        } else {
                
                $.ajax({
                    type: "POST",
                    url: "ajax.php",
                    data: {prozessor_manufactors : $('#prozessor_manufactors').val()},
                    dataType: "html",
                    timeout: 5000,
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader("Ajax-Request", "true");
                        xhr.setRequestHeader("Ajax-Request-Action", "getProzessorbymanufactor");

                    },
                    success: function(response) {
                        $('#proz_sorting').css({
                            'display': 'inline'
                        });
                    },
                    statusCode: {
                        404: function() {
                       
                        }
                      },
                      error: function(){
                         
                      }

                });
    
            
        }
    

   });
     
    $("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        
        $("#filtercontent").fadeOut("fast", function() {
            switchTemplate('list');
            $(this).fadeIn("fast");
            
        });
        
    }, function () {
        $(this).removeClass("swap");
        
        $("#filtercontent").fadeOut("fast", function() {
            switchTemplate('gatter');
            $(this).fadeIn("fast");
            
        });
        
    }); 

});
function switchTemplate(typ){
    
    var prozdata = new Array();

    prozdata[0] = new Object();
    prozdata[0]["filtercat"] = $("#prozflt input:checked").val();
    prozdata[0]["filterchild"] = $("#prozflt select").val();    
    prozdata[0]["detail"] = $("#prozflt #prozdetail").val();  
    
     $.ajax({
        type: "POST",
        url: "ajax.php",
        data: {AjaxRequestAction: 'switchdisplay', min : $("#min").val(), max: $("#max").val(),cpath: $("#cpath").val(), typ: typ, templatefile: 'product_listing_list.html', sorting:$("#sorting").val(), proz:prozdata , graka: $('#graka').val()},
        dataType: "html",
        timeout: 5000,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Ajax-Request", "true");
            xhr.setRequestHeader("Ajax-Request-Action", "switchdisplay");
            $("#filtercontent").empty();
            $("#filtercontent").addClass('loader');
        },
        success: function(response) {
            $("#filtercontent").removeClass('loader');
            $("#filtercontent").html(response);   
        },
        statusCode: {
            404: function() {
              $("#filtercontent").empty();
              $("#filtercontent").removeClass('loader');
              $("#filtercontent").html('Oops. Ein fehler ist aufgetreten. Fehler 404.');
            }
          },
          error: function(){
              $("#filtercontent").empty();
              $("#filtercontent").removeClass('loader');
              $("#filtercontent").html('Oops. Ein fehler ist aufgetreten. Fehler 404.');           
          }

    });   
  
}
/* ]]> */
