	 $("#menu_category").slideUp('slow');
	/**
	* filtersearch.js
	* @author  	   Business/Development: Adam Lee & Yaakov Albietz
	* @credit   	3rd Party Development: Seth Benjamin
	* @copyright   Copyright Eject Core 2009-2010. All rights reserved.
	* @license 	   end-user license agreements (EULAs)
	* @package     Filter Search Pro
	* @version 	   v1.7 Final
	*
	*/
	
	var productCountStore = -1;
	var setPage = 1;
	var filterSlideSpeed = 250;
	var timeLimit = 250;
	var prodCount = [];
	var actualProdCount = [];
	var newProdCount = [];
	var orgProdCount = productCount;
	var revertProductSearch = false;
	var haltRequest = true;
	var n = productsInPage;	
	var urlPrefix;
	var fullUrlPrefix;
	var idDelimiter;

	switch (filterSwitch) {
		case 'manufacturer':
			urlPrefix = '&id_manufacturer=';
			fullUrlPrefix = 'manufacturer.php?id_manufacturer=';
			idDelimiter = '_';
		break;
		case 'arrivals':
			urlPrefix = '&arrivals=';
			fullUrlPrefix = 'new-products.php';
			idDelimiter = '';
		break;
		case 'sales':
			urlPrefix = '&sales=';
			fullUrlPrefix = 'prices-drop.php';
			idDelimiter = '';
		break;
		default:
			urlPrefix = '&id_category=';
			fullUrlPrefix = 'category.php?id_category=';
			idDelimiter = '-';
		break;
	}
	
	$(function () {
		productSortBy();
		productsPerPage();
		productPaging(orgProdCount, 1, 'pageLoad', false);
		filterLimits();
		$('div#filterSearchBlock').css({
			opacity: 0,
			visibility: 'visible',
			height: 0
		}).animate({
			opacity: 1,
			height: '100%'
		},
		1000);

		$('.viewMoreOptions').toggle(function () {
			if($.browser.msie == true)
				$(this).parent().find('.viewMore').show();
			else	
				$(this).parent().find('.viewMore').slideToggle();
			$(this).html('- ' + viewLess);
		},
		function () {
			if($.browser.msie == true)
				$(this).parent().find('.viewMore').hide();
			else	
				$(this).parent().find('.viewMore').slideToggle();
			$(this).html('+ ' + viewMore);
		});
	
		$('#filterSearchBlock input[type=checkbox], #listingSearch input[type=checkbox]').bind('click', function () {
			if (!$(this).attr("checked") && $(this).attr("disabled") != "disabled") {
				$(this).attr("checked", true);
			} else {
				$(this).attr("checked", false);
			}
		});
	
		var doSearch = genParamUrl(null, null, false).split('&');
		var toClick = [];
	
		for (var i in doSearch) {
			if (i > 3 && doSearch[i].split('=')[0] != 'orderby' && doSearch[i].split('=')[0] != 'orderway') {
				toClick[i] = doSearch[i];
			}
		}
		
		for (var i in toClick) {
			if(typeof(toClick[i]) != 'function' && toClick[i].split('_')[1] != undefined) {
				if (toClick[i].split('_')[0] != 'r' && toClick[i].split('_')[0] != 'm') {
					var item = md5(toClick[i].split('_')[1].split('=')[0] + '_' + toClick[i].split('=')[1].split(';')[0]);
				} else {
					if (toClick[i].split('_')[0] == 'r') var item = toClick[i].replace(/r_\=/, '').replace(/[,.]/g, '');
					else var item = md5('Manufacturer_' + toClick[i].split('=')[1].split(';')[0]);
				}
				$('#filter_' + item).find('input[type=checkbox]').attr('checked', true).addClass('checked');
				if (i == parseInt(toClick.length - 1)) {
					performAjaxSearch();
				}
			}
		}
	
		// Ajax Search
		$('#filterSearchBlock ul li ul li').bind('click', function (index) {
			if ($(this).find('input[type=checkbox]').attr('disabled') == false) {
				var filteredStr = '';
				var filtered = Array();
				revertProductSearch = ($(this).find('input[type=checkbox]').attr('checked')) ? true : false;
	
				if (!$(this).hasClass('viewMoreOptions')) {
					if (!$(this).find('input[type=checkbox]').attr("checked") && $(this).find('input[type=checkbox]').attr("disabled") != "disabled") {
						$(this).find('input[type=checkbox]').attr("checked", true);
					} else {
						$(this).find('input[type=checkbox]').attr("checked", false);
					}
	
					if(document.location.href.match(/\?/) == true) {
						var pageDelimit = (rewrited_url == 1) ? location.pathname.split("/", 2)[1].split(idDelimiter)[0] : (document.location.href.split("?", 2)[1].split("#")[0] || "").split("=")[1];
					} else {
						var pageDelimit = '';
					}
	
					$("input[type=checkbox]").each(function (i) {
						if ($(this).attr("checked")) {
							var actualCount = $('#' + $(this).parent().attr('id') + ' span.actualCount').text().match(/\d+/g);
							var count = $('#' + $(this).parent().attr('id') + ' span.count').text().match(/\d+/g);
							$('#' + $(this).parent().attr('id') + ' span.actualCount').text('' + count + '');
							filtered[i] = (revertProductSearch == true ? actualCount : count) + '|' + encodeURIComponent($(this).attr("name")) + '=' + encodeURI($(this).attr("value"));
						}
					});
					sort(filtered, 'SORT_STRING');
					filtered = cleanArray(filtered);
					
					for (var i = 0; i < filtered.length; i++) {
						if(typeof(filtered[i]) != 'function') {
							filteredStr += '&' + filtered[i].split("|")[1];
						}
					}
					var obj = $(this);
					var getURI = revertProductSearch == true ? document.location.hash.split('&') : filteredStr.split('&');
					var grepURI = $.grep(getURI, function (val) {
						if (revertProductSearch == true) {
							return obj.find('input[type=checkbox]').val() != val.split('=')[1];
						} else return true;
					});
					filteredStr = grepURI.join('&').replace(/\#/, '');
	
					if ($('input[type=checkbox]:checked').size() == 0) filteredStr = '';
	
					if (filteredStr == '') {
						$.ajax({
							url: baseDir + "modules/filtersearchpro/filtersearch.ajax.php",
							data: 'do=search' + genParamUrl(revertProductSearch),
							success: function (products) {
								$("#product_list").html(products);
								$("input[type=checkbox]").each(function (i) {
									if ($(this).attr("checked")) {
										var count = $('#' + $(this).parent().attr('id') + ' span.count').text().match(/\d+/g);
										$('#' + $(this).parent().attr('id') + ' span.actualCount').text('' + count + '');
									}
								});
							}
						});
					}

					var queryId = window.location.search.split('=')[1] != undefined ? window.location.search.split('=')[1] : '';
					document.location.href = (rewrited_url == 1) ? window.location.pathname + '#' + filteredStr : fullUrlPrefix + queryId + pageDelimit + '#' + filteredStr;	
	
					var toScrollPos = window.scrollY;
					if (filteredStr.length < 1) {
						scrollTo(window.scrollX, toScrollPos);
					}
					performAjaxSearch();
				}
			}
		});
	
		$('#clearAll').click(function () {
			$('#filterSearchBlock input[type=checkbox]').each(function () {
				$(this).attr('checked', false)
			});
			window.location.href = window.location.href.split('#')[0] + '#';
			revertProductSearch  = true;
			performAjaxSearch();
		});
	
	});
	
	function performAjaxSearch() {
		$.ajax({
			url: baseDir + "modules/filtersearchpro/filtersearch.ajax.php",
			data: 'do=search' + genParamUrl(revertProductSearch),
			beforeSend: function () {
				$("#product_list").fadeTo(300, .3);
				$("#filterSearchBlock input[type=checkbox]").attr('disabled', 'disabled');
			},
			complete: function () {
				setTimeout(function () {
					$("#product_list").fadeTo(300, 1);
					$.ajax({
						url: "modules/filtersearchpro/filtersearch.ajax.php",
						data: 'do=filter' + genParamUrl(revertProductSearch),
						beforeSend: function() {
							$('.filterSearch.ajaxLoading').show();
						},
						success: function (filters) {
							$('.filterSearch.ajaxLoading').hide();						
							setTimeout(function () {
								$("#filterSearchBlock input[type=checkbox]").removeAttr('disabled', '');
							},
							1000);
	
							var sets = filters.split("|");
							$('.filterSearch ul li').removeClass('shown');

							$(sets).each(function (key, value) {
								var keyVal = value.split("=");
								var rKeyVal = (keyVal[1]) ? keyVal[1].split(':') : [];
								var itemID = md5(keyVal[0] + "_" + str_replace('__', '&', keyVal[1]));
								var rItemID = str_replace('.', '', str_replace(',', '', rKeyVal[0] + "_" + rKeyVal[1]));
								
								$('#filter_' + itemID).addClass('shown');
								
								if (rKeyVal[2] > 0) {
									$('#filter_' + rItemID).addClass('shown');
								} else {
									$('#filter_' + rItemID).removeClass('shown');
								}
	
								$('#filter_' + itemID + ' span.count').text('(' + keyVal[2] + ')');
								$('#filter_' + rItemID + ' span.count').text('(' + rKeyVal[2] + ')');
							});
	
							var checkedCount = [];
							$("input[type=checkbox]:checked").each(function (i) {
								checkedCount[i] = $(this).parent().find('.count').text().match(/\d+/);
							});
							
							var newProdCount = checkedCount.sort(compareNumbers);
							
							if (checkedSize < 1) {
								repCount = productCount;
							} else {
								repCount = newProdCount.reverse()[0];
							}
							
							repCount = ((repCount != null) ? repCount : productCount);
							
							plural = (repCount < 2) ? ' Product' : ' Products';
							var checkedSize  = $('#filterSearchBlock input[type=checkbox]:checked').size();
							$('h2.category_title span').text(((checkedSize < 1) ? productCount : repCount) + plural);
							orgProdCount = repCount;
							
							productsPerPage(repCount);
							productPaging(repCount, 1, 'onCountChange');
							if(checkedSize < 1)
								$('#subcategories, #scenes').show();
							else
								$('#subcategories, #scenes').hide();
	
							$('.filterSearch ul li,.filterRangeSearch ul li').each(function () {
								if (!$(this).hasClass("shown") && !$(this).hasClass("viewMoreOptions")) {
									$(this).slideUp(filterSlideSpeed);
								} else {
									if (!$(this).hasClass("viewMoreOptions")) {
										$(this).slideDown(filterSlideSpeed);
									}
								}
							});
	
							$('.filterSearch .showGroup').removeClass('showGroup');
							$('.filterSearch li div').each(function (index) {
								var shownSelector = '.shown';
								var curGroup = $(this).text();
								var listSet = $(this).parents().find('ul');
								var fullList = listSet.get(0);
								var nestList = listSet.get(1);
								var counts = [$(fullList).children(shownSelector).size(), Math.abs($(fullList).children(shownSelector).size() - $(nestList).children(shownSelector).size()), $(nestList).children(shownSelector).size()];
	
								if (counts[0] == counts[2]) {
									counts[1] += 1;
								}
	
								if (counts[0] < filterLimits(curGroup) && counts[1] > 0) {
									if ($(this).next().find('ul').children().size() > 0) {
										for (var i = 0; i < counts[1]; i++) {
											if($(fullList).children(shownSelector).length < filterLimits(curGroup)) {
												$($(nestList).children('.shown').eq(index)).insertBefore($(nestList));
											}
										}
										if ($(this).next().children('.shown').size() < filterLimits(curGroup)) {
											$($(nestList).children('.shown').eq(0)).insertBefore($(nestList));
										}
									}
								}
								
								if (counts[0] > filterLimits(curGroup)) {
									for (var i = 0; i < Math.abs(filterLimits(curGroup) - counts[0]); i++) {
										$($(fullList).children().eq(Math.abs(i - (counts[0] - 1)))).prependTo($(nestList));
									}
								}
	
								if ($(this).next().find('.viewMore').children('.shown').size() < 1) {
									$(this).next().children('li.viewMoreOptions').hide();
									$('.toggleLimit a').hide();
								} else {
									$(this).next().children('li.viewMoreOptions').show();
									$('.toggleLimit a').show();
								}
								$(this).parent().find('ul .shown').parent().prev().parent().addClass('showGroup');
							});
	
							$('.filterSearch .filterGroup').each(function () {
								if (!$(this).hasClass('showGroup')) {
									$(this).hide();
								} else {
									$(this).show();
								}
							});
						}
					});
				},
				timeLimit);
			},
			success: function (products) {
				$("#product_list").html(products);
			}
		});
	
	}
		
	function genParamUrl(revertProductSearch, page, group, _orderBy, _orderWay) {
		var sGroup, sValue, incGroup = 0, curGroup = '',
			pURL = '', url = document.location.href, _params,
			pageDelmit, page = ((page != '' && page != undefined) ? page : 1),
			sortBy = $('#selectPrductSort option:selected').val();
		
		if(rewrited_url == 0) {
			_params     = url.match(/\?/) == true ? (url.split("?", 2)[1].split("#")[1].split("&") || "") : (url.match(/\#/) ? (url.split("#")[1].split("&") || "") : '');
			pageDelimit = url.match(/\?/) == true ? (document.location.href.split("?", 2)[1].split("#")[0] || "").split("=")[1] : '';
		} else {
			_params     = url.match(/\#/) ? (url.split("#")[1].split("&") || "") : '';
			pageDelimit = location.pathname.split("/", 2)[1].split(idDelimiter)[0];
		}
			
		for(var i = 0; i < _params.length; i++) {
			sGroup   = _params[i].split("=")[0];
			sValue   = _params[i].split("=")[1];
			incGroup = (curGroup != sGroup ? 1 : 0);
			curGroup = sGroup;
			
			if(sValue != undefined) {
				if (group == undefined) {
					pURL += (incGroup == 1 ? '&' + sGroup + '=' : '') + (sValue != '' ? sValue : '') + ';';
				} else {
					pURL += '&' + sGroup + '=' + sValue;
				}
			}
		}
		
		orderBy  = _orderBy != undefined ? _orderBy : orderBy;
		orderWay = _orderWay != undefined ? _orderWay : orderWay;
		
		if(sortBy != undefined) {
			var sort = sortBy.replace(/(&|&amp;)id_lang=\d+/, '').split('&', 3);
			if (sort.length < 3) {
				var orderBy = sort[0].split('?')[1];
				var orderWay = sort[1];
			} else {
				var orderBy = sort[1];
				var orderWay = sort[2];
			}
		}
		
		sortBy = '&' + orderBy + '&' + orderWay;
		pURL   = pURL.replace(/(&|&amp;)id_lang/g, '');
		return urlPrefix + currentId + '&revertSearch=' + (revertProductSearch ? 1 : 0) + '&page=' + page + '&n=' + n + sortBy + pURL;
	}
	
	function productSortBy() {
		$('#selectPrductSort').removeAttr('onchange');
		$('#selectPrductSort').change(function () {
			$('#selectPrductSort option:selected').each(function () {
				var value = $(this).val();
				var sort = value.split('&', 3);
				if (sort.length < 3) {
					var orderBy = sort[0].split('?')[1];
					var orderWay = sort[1];
				} else {
					var orderBy = sort[1];
					var orderWay = sort[2];
				}
				$.ajax({
					url: baseDir + "modules/filtersearchpro/filtersearch.ajax.php",
					data: 'do=search' + genParamUrl(revertProductSearch, setPage),
					beforeSend: function () {
						$("#product_list").fadeTo(300, .3);
					},
					success: function (data) {
						$("#product_list").fadeTo(300, 1).html(data);
					}
				});
			});
		});
	}

	function productsPerPage(filterPage) {
		$('.pagination .button_mini').hide();
		$('#nb_item option').each(function () {
			if($(this).val() > filterPage)	{
				$(this).remove();		
			}
		})
		if($("#nbAll").html() == null)
			$('#nb_item').append($('<option id="nbAll"></option>').val(productCount).html(showAll));	
		
		$('#nb_item').change(function () {
			$('#nb_item option:selected').each(function () {
				n = $(this).val();
				$.ajax({
					url: baseDir + "modules/filtersearchpro/filtersearch.ajax.php",
					data: 'do=search' + genParamUrl(revertProductSearch, 1, undefined),
					beforeSend: function () {
						$("#product_list").fadeTo(300, .3);
					},
					success: function (data) {
						$("#product_list").fadeTo(300, 1).html(data);
						productPaging(false, 1, false, false, Math.ceil(productCount/n));
					}
				});					
				
			})
		});
	}
	
	function productPaging(filterPage, curPage, calledBy, search, superPage) {
		if(superPage == undefined) {
			var checkedSize  = $('#filterSearchBlock input[type=checkbox]:checked').size();
			pageCount = Math.ceil(parseFloat((filterPage == undefined ? parseInt(((checkedSize < 1) ? productCount : orgProdCount)) : filterPage) / n));
		} else {
			pageCount = superPage;
		}
		
		if (filterPage != undefined) {
			haltRequest = true;
			$('ul.pagination').pager({
				pagenumber: 1,
				pagecount: pageCount,
				buttonClickCallback: PageClick
			});
			PageClick = function (pageclickednumber) {
				$('ul.pagination').pager({
					pagenumber: pageclickednumber,
					pagecount: pageCount,
					buttonClickCallback: PageClick
				});
				haltRequest = false;
			}
		}
	
		if (curPage != undefined && haltRequest == false) {
			$.ajax({
				url: baseDir + "modules/filtersearchpro/filtersearch.ajax.php",
				data: 'do=search' + genParamUrl(revertProductSearch, curPage, undefined),
				beforeSend: function () {
					$("#product_list").fadeTo(300, .3);
				},
				success: function (data) {
					$("#product_list").fadeTo(300, 1).html(data);
				}
			});
		}
		haltRequest = false;
	}
	
	function filterLimits(getLimit) {
		if (getLimit == undefined) {
			$('.filterGroup').each(function () {
				var groupSelectors = $(this).get();
				var groupName = $(groupSelectors).find('div').text();
				for (var i in groupLimits) {
					if(groupLimits[i] != ':' && typeof(groupLimits[i]) != 'function') {
						var spl = groupLimits[i].split(':');
						var group = spl[0];
						var limit = spl[1];
						if (group == groupName) {
							var childCount = $(groupSelectors).find('ul.jsfix_view').children('li').size();
							if (childCount > limit) {
								var iniWrap = $(groupSelectors).find('ul.jsfix_view').children('li');
								var toWrap = iniWrap.slice(limit, iniWrap.length);
								$(toWrap).wrapAll('<ul class="vm_' + i + ' viewMore"></ul>');
								//$('<li class="viewMoreOptions">+ ' + viewMore + '</li>').insertAfter('ul.vm_' + i);
								if($('.viewMoreOptions', this).text() == '' || $('.viewMoreOptions', this).text() == undefined)
									$('ul.jsfix_view', this).prepend('<li class="viewMoreOptions">+ ' + viewMore + '</li>');
							} else {
								$(groupSelectors).find('.toggleLimit a').remove();
							}
						}
					}
				}
			});
		} else {
			for (var i in groupLimits) {
				if (typeof(groupLimits[i]) != 'function' && groupLimits[i].split(':')[0] == getLimit) {
					return groupLimits[i].split(':')[1];
				}
			}
		}
	}
	
	/**************** Very Useful JS Functions ******************/
	
	function cleanArray(actual) {
		var newArray = new Array();
		for (var i = 0; i < actual.length; i++) {
			if (actual[i]) {
				newArray.push(actual[i]);
			}
		}
		return newArray;
	}
	
	function compareNumbers(a, b) {
		if (a < b) {
			return -1;
		}
		if (a > b) {
			return 1;
		}
		return 0;
	}
	
	function str_replace(search, replace, subject, count) {
		var i = 0,
		j = 0,
		temp = '',
		repl = '',
		sl = 0,
		fl = 0,
		f = [].concat(search),
		r = [].concat(replace),
		s = subject,
		ra = r instanceof Array,
		sa = s instanceof Array;
		s = [].concat(s);
		if (count) this.window[count] = 0;
		for (i = 0, sl = s.length; i < sl; i++) {
			if (s[i] === '') continue;
			for (j = 0, fl = f.length; j < fl; j++) {
				temp = s[i] + '';
				repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
				s[i] = (temp).split(f[j]).join(repl);
				if (count && s[i] !== temp) {
					this.window[count] += (temp.length - s[i].length) / f[j].length;
				}
			}
		}
		return sa ? s : s[0];
	}
	
	function urlencode(str) {
		var histogram = {},
		unicodeStr = '',
		hexEscStr = '';
		var ret = (str + '').toString();
		var replacer = function (search, replace, str) {
			var tmp_arr = [];
			tmp_arr = str.split(search);
			return tmp_arr.join(replace);
		};
		histogram["'"] = '%27';
		histogram['('] = '%28';
		histogram[')'] = '%29';
		histogram['*'] = '%2A';
		histogram['~'] = '%7E';
		histogram['!'] = '%21';
		histogram['%20'] = '+';
		histogram['\u00DC'] = '%DC';
		histogram['\u00FC'] = '%FC';
		histogram['\u00C4'] = '%D4';
		histogram['\u00E4'] = '%E4';
		histogram['\u00D6'] = '%D6';
		histogram['\u00F6'] = '%F6';
		histogram['\u00DF'] = '%DF';
		histogram['\u20AC'] = '%80';
		histogram['\u0081'] = '%81';
		histogram['\u201A'] = '%82';
		histogram['\u0192'] = '%83';
		histogram['\u201E'] = '%84';
		histogram['\u2026'] = '%85';
		histogram['\u2020'] = '%86';
		histogram['\u2021'] = '%87';
		histogram['\u02C6'] = '%88';
		histogram['\u2030'] = '%89';
		histogram['\u0160'] = '%8A';
		histogram['\u2039'] = '%8B';
		histogram['\u0152'] = '%8C';
		histogram['\u008D'] = '%8D';
		histogram['\u017D'] = '%8E';
		histogram['\u008F'] = '%8F';
		histogram['\u0090'] = '%90';
		histogram['\u2018'] = '%91';
		histogram['\u2019'] = '%92';
		histogram['\u201C'] = '%93';
		histogram['\u201D'] = '%94';
		histogram['\u2022'] = '%95';
		histogram['\u2013'] = '%96';
		histogram['\u2014'] = '%97';
		histogram['\u02DC'] = '%98';
		histogram['\u2122'] = '%99';
		histogram['\u0161'] = '%9A';
		histogram['\u203A'] = '%9B';
		histogram['\u0153'] = '%9C';
		histogram['\u009D'] = '%9D';
		histogram['\u017E'] = '%9E';
		histogram['\u0178'] = '%9F';
		ret = encodeURIComponent(ret);
		for (unicodeStr in histogram) {
			hexEscStr = histogram[unicodeStr];
			ret = replacer(unicodeStr, hexEscStr, ret);
		}
		return ret.replace(/(\%([a-z0-9]{2}))/g, function (full, m1, m2) {
			return "%" + m2.toUpperCase();
		});
	}
	
	function utf8_encode(argString) {
		var string = (argString + '').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
		var utftext = "";
		var start, end;
		var stringl = 0;
		start = end = 0;
		stringl = string.length;
		for (var n = 0; n < stringl; n++) {
			var c1 = string.charCodeAt(n);
			var enc = null;
			if (c1 < 128) {
				end++;
			} else if ((c1 > 127) && (c1 < 2048)) {
				enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
			} else {
				enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
			}
			if (enc !== null) {
				if (end > start) {
					utftext += string.substring(start, end);
				}
				utftext += enc;
				start = end = n + 1;
			}
		}
		if (end > start) {
			utftext += string.substring(start, string.length);
		}
		return utftext;
	}
	
	function md5(str) {
		var xl;
		var rotateLeft = function (lValue, iShiftBits) {
			return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
		};
		var addUnsigned = function (lX, lY) {
			var lX4, lY4, lX8, lY8, lResult;
			lX8 = (lX & 0x80000000);
			lY8 = (lY & 0x80000000);
			lX4 = (lX & 0x40000000);
			lY4 = (lY & 0x40000000);
			lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
			if (lX4 & lY4) {
				return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
			}
			if (lX4 | lY4) {
				if (lResult & 0x40000000) {
					return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
				} else {
					return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
				}
			} else {
				return (lResult ^ lX8 ^ lY8);
			}
		};
		var _F = function (x, y, z) {
			return (x & y) | ((~x) & z);
		};
		var _G = function (x, y, z) {
			return (x & z) | (y & (~z));
		};
		var _H = function (x, y, z) {
			return (x ^ y ^ z);
		};
		var _I = function (x, y, z) {
			return (y ^ (x | (~z)));
		};
		var _FF = function (a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var _GG = function (a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var _HH = function (a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var _II = function (a, b, c, d, x, s, ac) {
			a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac));
			return addUnsigned(rotateLeft(a, s), b);
		};
		var convertToWordArray = function (str) {
			var lWordCount;
			var lMessageLength = str.length;
			var lNumberOfWords_temp1 = lMessageLength + 8;
			var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
			var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
			var lWordArray = new Array(lNumberOfWords - 1);
			var lBytePosition = 0;
			var lByteCount = 0;
			while (lByteCount < lMessageLength) {
				lWordCount = (lByteCount - (lByteCount % 4)) / 4;
				lBytePosition = (lByteCount % 4) * 8;
				lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount) << lBytePosition));
				lByteCount++;
			}
			lWordCount = (lByteCount - (lByteCount % 4)) / 4;
			lBytePosition = (lByteCount % 4) * 8;
			lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
			lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
			lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
			return lWordArray;
		};
		var wordToHex = function (lValue) {
			var wordToHexValue = "",
			wordToHexValue_temp = "",
			lByte, lCount;
			for (lCount = 0; lCount <= 3; lCount++) {
				lByte = (lValue >>> (lCount * 8)) & 255;
				wordToHexValue_temp = "0" + lByte.toString(16);
				wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
			}
			return wordToHexValue;
		};
		var x = [],
		k,
		AA,
		BB,
		CC,
		DD,
		a,
		b,
		c,
		d,
		S11 = 7,
		S12 = 12,
		S13 = 17,
		S14 = 22,
		S21 = 5,
		S22 = 9,
		S23 = 14,
		S24 = 20,
		S31 = 4,
		S32 = 11,
		S33 = 16,
		S34 = 23,
		S41 = 6,
		S42 = 10,
		S43 = 15,
		S44 = 21;
		str = this.utf8_encode(str);
		x = convertToWordArray(str);
		a = 0x67452301;
		b = 0xEFCDAB89;
		c = 0x98BADCFE;
		d = 0x10325476;
		xl = x.length;
		for (k = 0; k < xl; k += 16) {
			AA = a;
			BB = b;
			CC = c;
			DD = d;
			a = _FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
			d = _FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
			c = _FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
			b = _FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
			a = _FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
			d = _FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
			c = _FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
			b = _FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
			a = _FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
			d = _FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
			c = _FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
			b = _FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
			a = _FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
			d = _FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
			c = _FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
			b = _FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
			a = _GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
			d = _GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
			c = _GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
			b = _GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
			a = _GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
			d = _GG(d, a, b, c, x[k + 10], S22, 0x2441453);
			c = _GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
			b = _GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
			a = _GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
			d = _GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
			c = _GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
			b = _GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
			a = _GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
			d = _GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
			c = _GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
			b = _GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
			a = _HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
			d = _HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
			c = _HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
			b = _HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
			a = _HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
			d = _HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
			c = _HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
			b = _HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
			a = _HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
			d = _HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
			c = _HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
			b = _HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
			a = _HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
			d = _HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
			c = _HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
			b = _HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
			a = _II(a, b, c, d, x[k + 0], S41, 0xF4292244);
			d = _II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
			c = _II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
			b = _II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
			a = _II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
			d = _II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
			c = _II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
			b = _II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
			a = _II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
			d = _II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
			c = _II(c, d, a, b, x[k + 6], S43, 0xA3014314);
			b = _II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
			a = _II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
			d = _II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
			c = _II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
			b = _II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
			a = addUnsigned(a, AA);
			b = addUnsigned(b, BB);
			c = addUnsigned(c, CC);
			d = addUnsigned(d, DD);
		}
		var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
		return temp.toLowerCase();
	}
	
	function i18n_loc_set_default(name) {
		this.php_js = this.php_js || {};
		this.php_js.i18nLocales = {
			en_US_POSIX: {
				sorting: function (str1, str2) {
					// Fix: This one taken from strcmp, but need for other locales; we don't use localeCompare since its locale is not settable
					return (str1 == str2) ? 0 : ((str1 > str2) ? 1 : -1);
				}
			}
		};
	
		this.php_js.i18nLocale = name;
		return true;
	}
	
	function i18n_loc_get_default() {
		this.php_js = this.php_js || {};
		return this.php_js.i18nLocale || (i18n_loc_set_default('en_US_POSIX'), 'en_US_POSIX');
		// Ensure defaults are set up
	}
	
	function sort(inputArr, sort_flags) {
		var valArr = [],
		keyArr = [];
		var k = '',
		i = 0,
		sorter = false,
		that = this;
	
		for (k in inputArr) {
			valArr.push(inputArr[k]);
			delete inputArr[k];
		}
	
		switch (sort_flags) {
		case 'SORT_STRING':
			sorter = function (a, b) {
				return that.strnatcmp(a, b);
			};
			break;
		case 'SORT_LOCALE_STRING':
			var loc = this.i18n_loc_get_default();
			sorter = this.php_js.i18nLocales[loc].sorting;
			break;
		case 'SORT_NUMERIC':
			sorter = function (a, b) {
				return (a - b);
			};
			break;
		case 'SORT_REGULAR':
		default:
			sorter = function (a, b) {
				if (a > b) {
					return 1;
				}
				if (a < b) {
					return -1;
				}
				return 0;
			};
			break;
		}
		valArr.sort(sorter);
	
		for (i = 0; i < valArr.length; i++) {
			inputArr[i] = valArr[i];
		}
		return true;
	}
	
	function strcmp(str1, str2) {
		return ((str1 == str2) ? 0 : ((str1 > str2) ? 1 : -1));
	}
	
	function strnatcmp(f_string1, f_string2, f_version) {
		var i = 0;
	
		if (f_version == undefined) {
			f_version = false;
		}
	
		var __strnatcmp_split = function (f_string) {
			var result = [];
			var buffer = '';
			var chr = '';
			var i = 0,
			f_stringl = 0;
	
			var text = true;
	
			f_stringl = f_string.length;
			for (i = 0; i < f_stringl; i++) {
				chr = f_string.substring(i, i + 1);
				if (chr.match(/[0-9]/)) {
					if (text) {
						if (buffer.length > 0) {
							result[result.length] = buffer;
							buffer = '';
						}
	
						text = false;
					}
					buffer += chr;
				} else if ((text == false) && (chr == '.') && (i < (f_string.length - 1)) && (f_string.substring(i + 1, i + 2).match(/[0-9]/))) {
					result[result.length] = buffer;
					buffer = '';
				} else {
					if (text == false) {
						if (buffer.length > 0) {
							result[result.length] = parseInt(buffer, 10);
							buffer = '';
						}
						text = true;
					}
					buffer += chr;
				}
			}
	
			if (buffer.length > 0) {
				if (text) {
					result[result.length] = buffer;
				} else {
					result[result.length] = parseInt(buffer, 10);
				}
			}
	
			return result;
		};
	
		var array1 = __strnatcmp_split(f_string1 + '');
		var array2 = __strnatcmp_split(f_string2 + '');
	
		var len = array1.length;
		var text = true;
	
		var result = -1;
		var r = 0;
	
		if (len > array2.length) {
			len = array2.length;
			result = 1;
		}
	
		for (i = 0; i < len; i++) {
			if (isNaN(array1[i])) {
				if (isNaN(array2[i])) {
					text = true;
	
					if ((r = this.strcmp(array1[i], array2[i])) != 0) {
						return r;
					}
				} else if (text) {
					return 1;
				} else {
					return -1;
				}
			} else if (isNaN(array2[i])) {
				if (text) {
					return -1;
				} else {
					return 1;
				}
			} else {
				if (text || f_version) {
					if ((r = (array1[i] - array2[i])) != 0) {
						return r;
					}
				} else {
					if ((r = this.strcmp(array1[i].toString(), array2[i].toString())) != 0) {
						return r;
					}
				}
	
				text = false;
			}
		}
	
		return result;
	}
