var CoolHelper = {

	designer:'',
	manufacturer:'',
	category:'',
	urlHash:'',
	pagination:'',
	title:'',
	filterNeedsUpdate:true,
	lastHash:'',
	type:'',
    
	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;
	},
	setType:function(_type) {
		if(_type != this.type){
			this.pagination = '';
		}
		this.type = _type;
	},
	setTitle:function(_title) {
		if(_title != this.title){
			this.pagination = '';
		}
		this.title = _title;
	},
	getLinkFilterPart:function(){
		var
			filterUri = '',
			params = [];
		if(this.type != '') {
			filterUri += this.type + '/';
		}

		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() {
		bindList();
		bindDetail();
		bindProductsHover();
//@TODO coze?
//		$.scrollTo('#container',500);
	},
	updateFilterFromJSON:function(){
		//random cislo, pro pripad, ze se zavola vicekrat a prohlizec by chtel cachovat odpoved
		$.getJSON(base_web_dir + lang + '/ajaxed/get-filter/?'+Math.floor(Math.random()*10001), function(data) {
			if(typeof(data.chosenProducts) != 'undefined' && data.chosenProducts != null && data.chosenProducts != '') {
				showHideClipboardBar(data.chosenProducts);
			}

			if(typeof(data.type) != 'undefined' && data.type != null && data.type != '') {
				CoolHelper.setType(data.type);
				$('#product-types li').removeClass('selected');
				$('#product-types li#'+data.type).addClass('selected');

				var id = $('#product-types li#'+data.type).eq(0).attr('data-type');
				$('#product-categories li').css({'display':'none'});
				$('#product-categories li.categoryType-'+id).css({'display':'block'});
				$('#toolbar').show();
			}
			else{
				$('#toolbar').hide();
				if($('#requestForm').length == 0){
					$('#choosen-products').hide();
				}
			}
			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();
			}

			$('h4 span').each(function(){
				if($(this).text() == '('+allDesigners+')'){
					$(this).css('color','#fff');
				}
			});

			if($('#product-types .selected').length > 0){
				$('#product-types').removeClass('visiblehint');
			}else{
				$('#product-types').addClass('visiblehint');
			}
		});
	}

}
