// no conflict mode
jQuery.noConflict();

var Site = {
    
    // retrieve products through ajax
    getProductList: function() {
    	
    	// set class to wrapper div
    	jQuery('#product-list-wrp').addClass('loading');
        
        // get extra params
        var params = new Array();
        params[params.length] = 'a=gr';
        params[params.length] = 'l=' + encodeURIComponent(jQuery('input[name="l"]').val());
        params[params.length] = 'ol=' + encodeURIComponent(jQuery('select[name="ol-t"]').val());
        params[params.length] = 'oo=' + encodeURIComponent(jQuery('input[name="oo"]').val());
        params[params.length] = 'p=' + encodeURIComponent(jQuery('input[name="p"]').val());
        params[params.length] = 'sf=' + encodeURIComponent(jQuery('input[name="sf"]').val());
        params[params.length] = 'so=' + encodeURIComponent(jQuery('input[name="so"]').val());
        params[params.length] = 'ss=' + encodeURIComponent(jQuery('input[name="ss-t"]').val());

        // product filter?
        jQuery('input[name^="pf"]:checked').each(function(){params[params.length] = 'pf[]=' + jQuery(this).attr('value')});
        
        // get results
        jQuery.ajax({
                type: 'GET',
                url: '/assets/bin/services.php',
                data: params.join('&'),
                success: function(html) {
                	
                	// set html
                	jQuery('#product-list-wrp').html(html);
                	
			    	// remove class from wrapper div
			    	jQuery('#product-list-wrp').removeClass('loading');
			    	
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) { }
        });

    },
    
    // set some options for the selector and get results
    setSelector: function(f, p) {
        
    	// depending on f, we have to do some stuff
    	
    	switch(f) {
    	
			case 'sf':
				jQuery('input[name="sf"]').attr('value',p);
				break;
		    	
			case 'so':
				jQuery('input[name="so"]').attr('value',p);
				break;
				
			case 'oo':
			   	jQuery('input[name="oo"]').attr('value', ((p == 'l') ? parseInt(jQuery('input[name="oo"]').val()) - 1 : parseInt(jQuery('input[name="oo"]').val()) + 1));
				break;
    			
    		default:
    		
		        // define var
		        var pn = (p == 't') ? 'b' : 't';
		        
		        // set value
		        switch(f) {
		        	case 'ol':
			        	jQuery('select[name="' + f + '-' + pn + '"]').attr('value', jQuery('select[name="' + f + '-' + p + '"]').val());
			        	break;
			        	
		        	case 'ood':
			        	jQuery('select[name="' + f + '-' + pn + '"]').attr('value', jQuery('select[name="' + f + '-' + p + '"]').val());
			        	jQuery('input[name="oo"]').attr('value', jQuery('select[name="' + f + '-' + p + '"]').val());
			        	break;
			        	
		        	case 'ss':
			        	jQuery('input[name="' + f + '-' + pn + '"]').attr('value', jQuery('input[name="' + f + '-' + p + '"]').val());
			        	break;
		        }
    		
    			break;
    	}
        
        // get results
        Site.getProductList();

        // jump to top
        //location.hash = '#product-list-top';
        scrollTo(0,270);

    },
    
    // did we hit enter?
    toggleSubmit: function(e) {
    	if(e.which == 13) Site.getProductList();
    },
    
    // toggle interests on contact page
    toggleInterests: function(f) {
        
        // display or hide checkboxes in sublevel
        if(jQuery('input#chk-'+f+':checked').length) {
        	
        	// show sub
        	jQuery('div.'+f+'.sub').show();
        	
        }
        else {
        	
        	// hide sub
        	jQuery('div.'+f+'.sub').hide();
        	
        	// uncheck everything
        	jQuery('input[id^=chk-'+f+']').attr('checked', false);
        	
        }
        
    },
    
    getCompareList: function(c,l,b) {

    	// set class to wrapper div
    	jQuery('#product-list-wrp').addClass('loading');

    	// get results
        jQuery.ajax({
                type: 'GET',
                url: '/assets/bin/services.php',
                data: 'a=gcl&c='+c+'&l='+l+'&b='+b,
                success: function(html) {

                	// set html
                	jQuery('#content-c-right').html(html);

                	// remove class from wrapper div
			    	jQuery('#content-c-right').removeClass('loading');

        		},
                error: function(XMLHttpRequest, textStatus, errorThrown) { }
        });

    }

};

jQuery(document).ready(function () {

	// toggle topmenu
	jQuery('div#top-hnav li.l1,div#top-hnav li.l2').hover(function(){jQuery('ul:first', this).show();},function(){jQuery('ul',this).hide();});

	// fancybox
	jQuery('a.fb').fancybox({overlayColor:'#333',overlayOpacity:'0.5'});

});
