var CoolHelper = {

	designer:'',
	manufacturer:'',
	category:'',
	urlHash:'',
	pagination:'',
        title:'',
	filterNeedsUpdate:true,
	lastHash:'',
    
	setDesigner:function(_designer) {
		if(_designer != this.designer){
			this.pagination = '';
		}
		this.designer = _designer;
	},

	setManufacturer:function(_manufacturer) {
		if(_manufacturer != this.manufacturer){
			this.pagination = '';
		}
		this.manufacturer = _manufacturer;
	},
	setCategory:function(_category) {
		if(_category != this.category){
			this.pagination = '';
		}
		this.category = _category;
	},
	setTitle:function(_title) {
		if(_title != this.title){
			this.pagination = '';
		}
		this.title = _title;
	},
	getLinkFilterPart:function(){
		var
			filterUri = '',
			params = [];

		if(this.category != '') {
			filterUri += this.category + '/';
		}
		if(this.manufacturer != '') {
			filterUri += this.manufacturer + '/';
		}

		if(this.designer != '') {
			filterUri += this.designer + '/';
		}
		if(this.pagination != '') {
                    params.push('n.pagenumber='+this.pagination);
		}
		if(this.title != '') {
                    params.push('title='+encodeURI(this.title));
		}
                if(params.length){
                    filterUri += '?' + params.join('&');
                }
		if(filterUri == ''){
                    filterUri = '#/';
		}
		return filterUri;

	},

	getLink:function() {
		if(lang == 'en') {
			products = '/products/';
		} else {
			products = '/produkty/';
		}
		uriStr = this.getLinkFilterPart();

	
		return base_web_dir + lang + products + uriStr;
	},

	setCallbacks:function() {

		sIFRreplace();
		bindList();
		bindDetail();
		bindProductsHover();
		$.scrollTo('#container',500);
	},
	updateFilterFromJSON:function(){
		$.getJSON(base_web_dir + lang + '/ajaxed/get-filter/', function(data) {
			if(typeof(data.category.coolUrl) != 'undefined' && data.category.coolUrl != null && data.category.coolUrl != '') {
				CoolHelper.setCategory(data.category.coolUrl);
					$('#product-categories li').removeClass('selected');
					$('#product-categories li#'+data.category.coolUrl).addClass('selected');
			} else {
					$('#product-categories li').removeClass('selected');
					$('#product-categories li').eq(0).addClass('selected');
			}

			if(typeof(data.designer.id) != 'undefined' && data.designer.id != null) {
				$('div#designer span:first').html('('+data.designer.name+')');
				CoolHelper.setDesigner(data.designer.coolUrl);
                                $('#designer-cancel').show();
			} else {
				$('div#designer span:first').html('('+allDesigners+')');
                                $('#designer-cancel').hide();
			}
			if(typeof(data.manufacturer.id) != 'undefined' && data.manufacturer.id != null) {
				$('div#maker span:first').html('('+data.manufacturer.name+')');
				CoolHelper.setManufacturer(data.manufacturer.coolUrl);
                                $('#maker-cancel').show();
			} else {
				$('div#maker span:first').html('('+allManufacturers+')');
                                $('#maker-cancel').hide();

			}
                        if($.trim(data.title)!=''){
                            $('#find-text').text(data.title);
                            $('#find-filter').show();
                        }else{
                            $('#find-filter').hide();
                        }
		});
	}

}