var jCarousel = null;
//var lang_code = 'en';

$(document)
		.ready(
				function() {
					$e('skeywords').onkeypress = function(event) {
						 
					 	var escape_event;
					  
					 	if(navigator.appName == 'Netscape')
						{
					  		escape_event = event.keyCode;
					 	}
						else
						{
					  		escape_event = window.event.keyCode;
					  	}
					 	
						if(escape_event == 13) 
						{
					  		SearchSubmit(lang_code);
					 	}
					 }
					
					$('#cart').hover( function() {
						$(this).addClass('on');
					}, function() {
						$(this).removeClass('on');
					});
					
					jQuery.fn.fadeToggle = function(speed, easing, callback) {
						return this.animate( {
							opacity :'toggle'
						}, speed, easing, callback);
					};
					
					// imagever
					$('.imagever').bind('click', function() {
							this.src = this.src + '?' + Math.random();
						}	
					);

					aidi = (document.location.hash || window.location.hash);
					$(".extraFilterMainButtons a").css("cursor", "pointer");

					$(".extraFilterMainButtons a.filterMainButtons")
							.bind(
									'click',
									function() {

										var link = $(this);

										$(
												"div.extraFilterScroll div#extraFilterScrollContent")
												.html(
														$(
																"#"
																		+ $(
																				link)
																				.attr(
																						'id')
																		+ "List")
																.html());

										$(".extraFilterScroll").css( {
											top :$(link).offset().top,
											left :($(link).offset().left + 100)
										});
										$("div.extraWrapper").css('display',
												'block');
										$(".extraFilterScroll ").fadeIn('fast');
										$(".extraFilterScroll a").css("cursor",
												"pointer");
										$(".extraFilterScroll ul li a")
												.bind('click', function() {

													// $(link).parent().find("a.removeFilterClass").remove();
														// $(link).parent().prepend("<a
														// class='removeFilterClass'
														// rev='"+$(link).attr('id')+"'
														// style='cursor:pointer;'
														// href='javascript:void(0);'>x
														// </a> " );
														$(link)
																.parent()
																.addClass(
																		'static')
																.find('a')
																.addClass(
																		'remove');

										
														if ($(link)
																.parent()
																.find(
																		"a.removeFilterClass:visible"))
															$(link)
																	.parent()
																	.find(
																			"a.removeFilterClass")
																	.bind(
																			'click',
																			function() {
																				$(link).parent().removeClass('static');

																				if ($(
																						this)
																						.attr(
																								'rev') == "filterProducts") {
																					filterLink = filterLink
																							.replace(
																									/_s[0-9]+_/,
																									"_s0_");
																					filterLink = filterLink
																							.replace(
																									/_ss[0-9]+_/,
																									"_ss0_");

																					$(
																							link)
																							.html(
																									$(
																											link)
																											.next(
																													"span.invisibleData")
																											.html());
																					// $(link).parent().find("a.removeFilterClass").remove();
																				}

																				else if ($(
																						this)
																						.attr(
																								'rev') == "filterManufacturers") {
																					filterLink = filterLink
																							.replace(
																									/_m[0-9]+_/,
																									"_m0_");

																					// $(link).parent().find("a.removeFilterClass").remove();
																					$(
																							link)
																							.html(
																									$(
																											link)
																											.next(
																													"span.invisibleData")
																											.html());
																				}

																				else if ($(
																						this)
																						.attr(
																								'rev') == "filterDesigners") {
																					filterLink = filterLink
																							.replace(
																									/_d[0-9]+_/,
																									"_d0_");

																					// $(link).parent().find("a.removeFilterClass").remove();
																					$(
																							link)
																							.html(
																									$(
																											link)
																											.next(
																													"span.invisibleData")
																											.html());
																				}

																				else if ($(
																						this)
																						.attr(
																								'rev') == "filterThemes") {
																					filterLink = filterLink
																							.replace(
																									/_t[0-9]+_/,
																									"_t0_");

																					// $(link).parent().find("a.removeFilterClass").remove();
																					$(
																							link)
																							.html(
																									$(
																											link)
																											.next(
																													"span.invisibleData")
																											.html());
																				}
																			});

														$(link).html(
																$(this).text());
														$("div.extraWrapper")
																.trigger(
																		'click');
													});

										if (!$.browser.opera) {
											$("#extraFilterScrollContent")
													.jScrollPane( {
														animateTo :false
													});
										}
									});

					$("form#search").bind(
							"submit",
							function() {
								searchValue = $(this).find("input#search3")
										.attr('value');
								if (searchValue == undefined)
									searchValue = '0';

								return setUrl("/filter/" + filterLink);
							});

					$("div.extraWrapper").click( function() {
						$("div.extraFilterScroll").fadeOut('fast');
						$(this).css('display', 'none');
					});

					$(".advSearch ul li").Tooltip( {
						track :true,
						delay :0
					});

					$(".item .item_name").Tooltip( {
						showURL :false,
						track :true,
						delay :0
					});

					$("#my_downloads_profile_link").Tooltip( {
						showURL :false,
						track :true,
						delay :0
					});

					// front
					jsPrepareNodes();

					// init selected left menu items
					getSelectedMenuElements();
				});

function initLogButtons(counter) {
	
	$("div.userHistory div.logMonth a").toggle( function() {
								 
		var thisDT = $(this).parent('div.logMonth');
		
		$(thisDT).find('.sign').html('&#150;');
		
		$(this).parent('div.logMonth').next('div.logMonthContent').animate( {
			"opacity" :"show"
		}, "fast", function() {
			if (!$.browser.opera)
				$("#scrolledContent").jScrollPane( {
					animateTo :false
				});
		});
		

	}, function() {
		
		$(this).parent('div.logMonth').find('.sign').html('+');
		$(this).parent('div.logMonth').next('div.logMonthContent').animate( {
			"opacity" :"hide"
		}, "fast", function() {
			if (!$.browser.opera)
				$("#scrolledContent").jScrollPane( {
					animateTo :false
				});
		});
	});
	$('#date_'+counter).trigger('click');
	//$('#sign_'+counter).trigger('click');
	
	//$("div.userHistory div.logMonth .sign").trigger('click');
}

function initElementInUserSpaceButtons() {
	// за листване на ресурс-пакетите
	$("a.rpsInUserAccount").bind("click", function() {
		$(this).nextAll('.historyResourcePackages:first').slideToggle('fast');
	});
}

function showModal(modal_id) {
	$('.modal-login').hide();
	$('#' + modal_id).show();

	// focus login field
	if (modal_id == 'modal-login') {
		$('#modal-login').find('#username').focus();
	}
}

function hideModal(modal_id) {
	$('#' + modal_id).hide();
}

function jsPrepareNodes() {
	if (readCookie('layer')) {
		var clicks = readCookie('quiz');

		if (clicks == 2) {
			if ($.browser.msie) {
				$("div.userQuiz").fadeTo('fast', 0.95, function() {
					$(this).css("display", "block");
					// showUserTabs();
					});
			} else {
				$("div.userQuiz").fadeIn('fast', function() {
					$(this).css("display", "block");
					// showUserTabs();
					});
			}

			$("div#screen").show();
			Set_Cookie('quiz', 0, 1, '/');
		} else {
			var num_clicks = parseInt(clicks) + 1;
			Set_Cookie('quiz', num_clicks, 1, '/');
		}
	}

	$(".button_userAccount").click( function() {
		LoadingData();

		if (readCookie('layer')) {
			var current = readCookie('layer');

			if (current == 'account') {
				ajaxRPC.call('profile/viewprofile');
			}
			if (current == 'favorites') {
				ajaxRPC.rpc('profile/myfavorites');
			}
			if (current == 'downloads') {
				ajaxRPC.call('cart/incart');
			}
			if (current == 'messages') {
				ajaxRPC.call('profile/messages');
			}
			if (current == 'dhistory') {
				ajaxRPC.call('profile/mydownloads');
			}
			if (current == 'phistory') {
				ajaxRPC.call('profile/paymentdata');
			}
		} else {
			ajaxRPC.call('cart/incart');
		}

		if ($.browser.msie) {
			$("div.userAccount").fadeTo('fast', 0.95, function() {
				$(this).css("display", "block");
				// showUserTabs();
				});
		} else {
			$("div.userAccount").fadeIn('fast', function() {
				$(this).css("display", "block");
				// showUserTabs();
				});
		}

		$("div#screen").show();
	});

	$(".button_userSendFriend").click( function() {
		$("div#screenSendFriend").show();return;
		if ($.browser.msie) {
			$("div.userSendFriend").fadeTo('fast', 0.95, function() {
				$(this).css("display", "block");
				// showUserTabs();
				});
		} else {
			$("div.userSendFriend").fadeIn('fast', function() {
				$(this).css("display", "block");
			});
		}
	
		//$("div#screenSendFriend").find('#review_text').attr('value', '');
		$("div#screenSendFriend").show();
	});

	$(".button_userWriteReview").click( function() {
		
		if (ulin < 1)
		{
			showModal('login-alert');
			return;
		}
		
		if ($.browser.msie) {
			$("div.userWriteReview").fadeTo('fast', 0.95, function() {
				$(this).css("display", "block");
				// showUserTabs();
				});
		} else {
			$("div.userWriteReview").fadeIn('fast', function() {
				$(this).css("display", "block");
			});
		}

		$("div#screenWriteReview").find('#review_text').attr('value', '');
		$("div#screenWriteReview").show();
	});

	$(".button_userReportBug").click( function() {
	
		if (ulin < 1)
		{
			showModal('login-alert');
			return;
		}
		
		if ($.browser.msie) {
			$("div.userReportBug").fadeTo('fast', 0.95, function() {
				$(this).css("display", "block");
				// showUserTabs();
				});
		} else {
			$("div.userReportBug").fadeIn('fast', function() {
				$(this).css("display", "block");
			});
		}

		$("div#screenReportBug").find('#message').attr('value', '');
		$("div#screenReportBug").show();
	});

	$("#screen").click( function() {
		$("div.userAccount").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screen").hide();
		});
	});

	$("div.closeCart a").click( function() {
		$("div.userAccount").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screen").hide();
		});
	});

	$("div.closeQuiz a").click( function() {
		$("div.userQuiz").fadeOut('fast', function() {
			$("#screen").hide();
		});
	});

	$("#screenSendFriend").click( function() {
		$("div.userSendFriend").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screenSendFriend").hide();
		});
	});

	$("#report_bug_button_submit").click( function() {
		$("#screenReportBug").fadeOut('fast', function() {
			$("#screenReportBug").hide();
		});
	});

	$("#screenReportBug").click( function() {
		$("div.userReportBug").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screenReportBug").hide();
		});
	});

	$("div.closeWriteReview a").click( function() {
		$("div.userWriteReview").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screenWriteReview").hide();
		});
	});

	$("#screenWriteReview").click( function() {
		$("div.userWriteReview").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screenWriteReview").hide();
		});
	});

	$("div.closeSendFriend a").click( function() {
		$("div.userSendFriend").fadeOut('fast', function() {
			$(".cartContent:visible").empty();
			$("#screenSendFriend").hide();
		});
	});

	var hack = {
		ltie7 :$.browser.msie && $.browser.version < 7,
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod='crop',src='"
					+ src + "')";
			// return
			// "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod='scale');";
		}
	};

	$(".homeFreshConnections .smallImage")
			.mouseover(
					function() {

						var $$ = $(this).parent().parent().find(".bigImage");

						if (hack.ltie7) {
							var base = "http://dconnected.dev.bgmiracle.com";
							var source = (base && $$.attr('src')
									.substring(0, 1) != '/') ? base
									+ $$.attr('src') : $$.attr('src');
							if ($$.attr('src') != '/img/px.gif') {
								$$.css( {
									filter :hack.filter(source),
									width :$$.width(),
									height :$$.height()
								}).attr( {
									src :'/img/px.gif'
								});
							}

							$$.css( {
								display :'block'
							});
						} else {
							// filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/templates/default/site/images/promo_bgr.png',sizingMethod='scale');

							$$.fadeIn('fast');
						}
					});

	$(".homeFreshConnections .smallImage").mouseout( function() {
		var $$ = $(this).parent().parent().find(".bigImage");
		if (hack.ltie7) {
			$$.css( {
				display :'none'
			});
		} else {
			$$.fadeOut('fast');
		}
		// alert($(this).parent().parent().find(".bigImage").css('filter'));
			// $(this).parent().parent().find(".bigImage").css({display:'none'});
		});

	/* Product view - similar products slider */
	function mycarousel_initCallback(carousel) {
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});

		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover( function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	}
	;

	jQuery(document).ready( function() {
		jQuery('#mycarousel').jcarousel( {
			auto :5,
			scroll :4,
			wrap :'last',
			initCallback :mycarousel_initCallback
		});
	});
	
	/* Home page - image slider */
	function home_slider_initCallback(carousel) {
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});

		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover( function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	}
	;

	jQuery(document).ready( function() {
		jQuery('#home_slider').jcarousel( {
			auto :5,
			scroll :4,
			wrap :'last',
			initCallback :home_slider_initCallback
		});
		$('#home_slider').show();
	});

	if ($.browser.msie) {
		$("div.product-list>.item").hover( function() {
			$(this).find(".details").css("display", "block");
		}, function() {
			$(this).find(".details").css("display", "none");
		});
	} else {
		$("div.product-list>.item").hover( function() {
			$(this).find(".details").fadeIn('fast');
		}, function() {
			$(this).find(".details").fadeOut('fast');
		});
	}
}

function SwitchCustomModelHomePage() {
	ajaxRPC.call('/home/get_random_custom_model');
}

function setRandomModelHomePage(par) {
	$('#custom_set_rand_home').html(par);
}

function ShowFeedback() 
{
	$('#modal-feedback').find('#person_name').attr('value', '');
	$('#modal-feedback').find('#person_email').attr('value', '');
	$('#modal-feedback').find('#comments').attr('value', '');
	showModal('modal-feedback');
}

function afterFeedback() 
{
	$("#modal-feedback").fadeOut('fast', function() {
		$("#modal-feedback").hide();
	});
}

// PACKAGES PAYMENT
function SelectPoints(value) 
{
	document.location = '/payment/details/points/' + value;
}

function CallMF(member_id, type) 
{
	var count = 0;
	INTERVAL = setInterval( function() {
		if (count > 1) {
			clearInterval(INTERVAL);
			if ($.browser.msie) {
				$("div.userMF").fadeTo('fast', 0.95, function() {
					$(this).css("display", "block");
					// showUserTabs();
					});
			} else {
				$("div.userMF").fadeIn('fast', function() {
					$(this).css("display", "block");
				});
			}

			var offset = jQuery('#mf_' + member_id).offset();
			// jQuery('div.userMF').css(offset);
			jQuery('div.userMF').css( {
				left :(offset.left - 650) + 'px',
				top :(offset.top - 250) + 'px'
			});

			$("div#screenMF").show();

			ajaxRPC.call('catalog/listmodels/' + type + '/' + member_id);
		}
		count++;
	}, 200);
}

function CloseMF() {
	clearInterval(INTERVAL);
	if (jCarousel != null) {
		jCarousel.stopAuto();
		$("div.userMF").fadeOut('fast', function() {
			$("#mycarousel2").remove();
		});
	}
}

/* Home Page Slider */
function showHomebox()
{
	$('#home_gallery').fadeToggle();
	$('.imgBox').fadeToggle();
}

/* Payment Packages */

function CheckForPoints() {
	var points = document.getElementById('points').innerHTML;

	if (points < 1)
		return;

	document.location = '/catalog/productslist/checkforproducts/' + points;
}

function SetPoints() {
	points_div = $e('points_plans');
	points_radios = points_div.getElementsByTagName('input');

	for (i = 0; i < points_radios.length; i++) {
		var elem = points_radios[i];
		obj_type = elem.getAttribute('type');
		obj_id = elem.getAttribute('id');

		if (obj_type == 'radio') {
			if ($e(obj_id).checked == true) {
				var points = $e('points_' + obj_id).innerHTML;

				if (points == 0) {
					document.getElementById('goButton').disabled = true;
				} else {
					document.getElementById('goButton').disabled = false;
				}

				document.getElementById('points').innerHTML = points;
			}
		}
	}
}

/* Favorites 
 * 
 * 
 * 
 * 
 * 
 * */

function ShowHideFavorites() 
{
	$("#in_favorites").toggle('fast');
}

function AddToFavorites(model_id)
{
	if (ulin < 1)
	{
		showModal('login-alert');
		return;
	}

	if($('#pss').html() == '1')
	{
		$('#JustAdded_'+model_id).show();

		$('#action_type').val('add');
		$('#pbookmarkremove_'+model_id).show();
		$('#pbookmark_'+model_id).hide();
	}
	document.favorites.model_id.value = model_id;
	ajaxRPC.validate('favorites');
}

function removeFromFavorites(model_id)
{
	if($('#pss').html() == '1')
	{
		$('.JustAdded_'+model_id).hide();
		$('#action_type').val('del');
		$('#pbookmarkremove_'+model_id).hide();
		$('#pbookmark_'+model_id).show();
	}
	document.favorites.model_id.value = model_id;
	ajaxRPC.validate('favorites');
}

/* Top Menu
 * 
 * 
 * 
 * 
 */

function SetMenuLettersDes() 
{
	document.getElementById('letters_des').style.display = 'block';
	document.getElementById('letters_man').style.display = 'none';
	document.getElementById('menuinit').style.display = 'none';
	document.getElementById('category').style.display = 'none';
	document.getElementById('theme').style.display = 'none';
	Set_Cookie('submenucookie', '', 1, '/');
	ShowSubcat(0);
	document.getElementById('button_products').className = '';
	document.getElementById('button_designers').className = 'mainNaviStep0Checked';
	document.getElementById('button_manufacturers').className = '';
	document.getElementById('button_themes').className = '';
	Set_Cookie('menucookie', 'designer', 1, '/');
	Set_Cookie('mainmenu', 'designers', 1, '/');
}

function SetMenuLettersMan() 
{
	document.getElementById('letters_des').style.display = 'none';
	document.getElementById('letters_man').style.display = 'block';
	document.getElementById('menuinit').style.display = 'none';
	document.getElementById('category').style.display = 'none';
	document.getElementById('theme').style.display = 'none';
	Set_Cookie('submenucookie', '', 1, '/');
	ShowSubcat(0);
	document.getElementById('button_products').className = '';
	document.getElementById('button_designers').className = '';
	document.getElementById('button_manufacturers').className = 'mainNaviStep0Checked';
	document.getElementById('button_themes').className = '';
	Set_Cookie('menucookie', 'manufacturer', 1, '/');
	Set_Cookie('mainmenu', 'manufacturer', 1, '/');
}

function SetMenuThemes() 
{
	document.getElementById('letters_des').style.display = 'none';
	document.getElementById('letters_man').style.display = 'none';
	document.getElementById('menuinit').style.display = 'none';
	document.getElementById('category').style.display = 'none';
	document.getElementById('theme').style.display = 'block';
	Set_Cookie('submenucookie', '', 1, '/');
	ShowSubcat(0);
	document.getElementById('button_products').className = '';
	document.getElementById('button_designers').className = '';
	document.getElementById('button_manufacturers').className = '';
	document.getElementById('button_themes').className = 'mainNaviStep0Checked';
	Set_Cookie('menucookie', 'theme', 1, '/');
	Set_Cookie('mainmenu', 'themes', 1, '/');
}

function SetMenuProductsCats() 
{
	document.getElementById('letters_man').style.display = 'none';
	document.getElementById('letters_des').style.display = 'none';
	document.getElementById('menuinit').style.display = 'none';
	document.getElementById('category').style.display = 'block';
	document.getElementById('theme').style.display = 'none';
	document.getElementById('button_products').className = 'mainNaviStep0Checked';
	document.getElementById('button_designers').className = '';
	document.getElementById('button_manufacturers').className = '';
	document.getElementById('button_themes').className = '';
	Set_Cookie('menucookie', 'category', 1, '/');
	Set_Cookie('mainmenu', 'products', 1, '/');
}

function ClearMenuCookies() 
{
	Set_Cookie('menucookie', '', 1, '/');
	Set_Cookie('mainmenu', '', 1, '/');
	Set_Cookie('menu1step', '', 1, '/');
	Set_Cookie('menu2step', '', 1, '/');
	Set_Cookie('submenucookie', '', 1, '/');
}

function setStep2(cat_id) 
{
	$e(cat_id).className = 'mainNaviStep2Checked';
	Set_Cookie('menu2step', cat_id, 1, '/');
}

function Step1Fix(cat_name) 
{
	var contentDiv = $e("mainNaviStep1");
	var allContainedElements = contentDiv.getElementsByTagName("li");

	for ( var i = 0; i < allContainedElements.length; i++) {
		if (cat_name == allContainedElements[i].id) {
			allContainedElements[i].className = 'mainNaviStep1Checked';
		} else {
			allContainedElements[i].className = '';
		}
	}
}

function Step2Fix(cat_id) 
{
	var contentDiv = $e("mainNaviStep2");
	var allContainedElements = contentDiv.getElementsByTagName("li");

	for ( var i = 0; i < allContainedElements.length; i++) {
		if (cat_id == allContainedElements[i].id) {
			allContainedElements[i].className = 'mainNaviStep2Checked';
		} else {
			allContainedElements[i].className = '';
		}
	}
}

function ShowSubcat(cat_id, cat_name) 
{
	Set_Cookie('menu1step', cat_name, 1, '/');
	Step1Fix(cat_name);

	var submenus = $e('mainNaviStep2').getElementsByTagName("div");

	for ( var i = 0; i < submenus.length; i++) {
		submenus[i].style.display = 'none';
	}

	if (cat_id > 0) {
		$e('subcats_' + cat_id).style.display = 'block';
	}
}

function setMenuEl(masterEl, elid, mode, elem_id) {
	if (elid == null)
		return;

	var elmastertop = $(masterEl).parent();
	$(masterEl).remove();

	var title = escape(elid.innerHTML.replace(/(<([^>]+)>)/ig, ""));

	$("#"+elid.id).find('a').attr('href', '/catalog/productslist/filter/' + title + '_' + mode + elem_id);

	elmastertop.prepend(elid.innerHTML).addClass('static').find('a').addClass(
			'remove').attr(
			"href",
			"javascript:removeFilterElem('" + mode + "','" + elem_id + "','"
					+ elid.id + "')");

}

function removeFilterElem(mode, elem_id, elid) 
{
	if (elid == null)
		return;

	var t = String(window.location);

	tmpstr = '/catalog/productslist/filter/';

	interm = t.substring(t.indexOf(tmpstr, 0) + tmpstr.length - 1, t.length);
	var s = interm.split('/');

	if (s < 0)
		return;

	window.location = '/catalog/productslist/filter' + doParseParams(s, mode,
			elem_id);
}

function getSelectedMenuElements() 
{
	var t = String(window.location);

	tmpstr = '/catalog/productslist/filter/';

	interm = t.substring(t.indexOf(tmpstr, 0) + tmpstr.length - 1, t.length);
	var s = interm.split('/');

	if (s < 0) { return; }

	doParseParams(s, '', 0);
}

function doParseParams(s, removeElemType, removeElemId) 
{
	var remove_removed = '';

	for (i = 1; i < s.length; i++) {
		workpart = s[i];

		// Category
		var reCategory = new RegExp(/.*_c[0-9]*/i);
		var Category = reCategory.exec(workpart);
		
		if (Category != null) {
			var CategoryId = reCategory.exec(workpart)[0].substring(reCategory
					.exec(workpart)[0].indexOf('_c', 0) + 2, reCategory
					.exec(workpart)[0].length);
			if (CategoryId > 0) {
				if (removeElemId < 1) {
					setMenuEl('#filterProducts', document.getElementById('menu_category_' + CategoryId),
							'c', CategoryId);
				} else if ((removeElemId == CategoryId)
						&& (removeElemType == 'c')) {
					continue;
				} else {
					remove_removed += '/' + workpart;
				}

			}

			continue;
		}

		// Manufacturer
		var reManufacturer = new RegExp(/.*_m[0-9]*/i);
		var Manufacturer = reManufacturer.exec(workpart);

		if (Manufacturer != null) {
			var ManufacturerId = reManufacturer.exec(workpart)[0].substring(
					reManufacturer.exec(workpart)[0].indexOf('_m', 0) + 2,
					reManufacturer.exec(workpart)[0].length);
			if (ManufacturerId > 0) {
				if (removeElemId < 1) {
					setMenuEl(
							'#filterManufacturers',
							document.getElementById('menu_manufacturer_' + ManufacturerId),
							'm', ManufacturerId);
				} else if ((removeElemId == ManufacturerId)
						&& (removeElemType == 'm')) {
					continue;
				} else {
					remove_removed += '/' + workpart;
				}
			}
			continue;
		}

		// Designer
		var reDesigner = new RegExp(/.*_d[0-9]*/i);
		var Designer = reDesigner.exec(workpart);

		if (Designer != null) {
			var DesignerId = reDesigner.exec(workpart)[0].substring(reDesigner
					.exec(workpart)[0].indexOf('_d', 0) + 2, reDesigner
					.exec(workpart)[0].length);
			if (DesignerId > 0) {
				if (removeElemId < 1) {
					setMenuEl('#filterDesigners', document
							.getElementById('menu_designer_' + DesignerId),
							'd', DesignerId);
				} else if ((removeElemId == DesignerId)
						&& (removeElemType == 'd')) {
					continue;
				} else {
					remove_removed += '/' + workpart;
				}
			}
			continue;
		}

		// Theme
		var reTheme = new RegExp(/.*_t[0-9]*/i);
		var Theme = reTheme.exec(workpart);

		if (Theme != null) {
			var ThemeId = reTheme.exec(workpart)[0].substring(reTheme
					.exec(workpart)[0].indexOf('_t', 0) + 2, reTheme
					.exec(workpart)[0].length);
			if (ThemeId > 0) {
				if (removeElemId < 1) {
					setMenuEl('#filterThemes', document
							.getElementById('menu_theme_' + ThemeId), 't',
							ThemeId);
				} else if ((removeElemId == ThemeId) && (removeElemType == 't')) {
					continue;
				} else {
					remove_removed += '/' + workpart;
				}
			}
			continue;
		}

		// Material
		var reMaterial = new RegExp(/.*_a[0-9]*/i);
		var Material = reMaterial.exec(workpart);

		if (Material != null) {
			var MaterialId = reMaterial.exec(workpart)[0].substring(reMaterial
					.exec(workpart)[0].indexOf('_a', 0) + 2, reMaterial
					.exec(workpart)[0].length);
			if (MaterialId > 0) {
				if (removeElemId < 1) {
					setMenuEl('#filterMaterials', document
							.getElementById('menu_material_' + MaterialId),
							'a', MaterialId);
				} else if ((removeElemId == MaterialId)
						&& (removeElemType == 'a')) {
					continue;
				} else {
					remove_removed += '/' + workpart;
				}
			}
			continue;
		}
	}

	return remove_removed;
}

/* Searching 
 * 
 * 
 * 
 */

function SearchSubmit(lang_code) 
{
	if ($e('skeywords').value.length < 1) return;
	
	document.location = '/' + lang_code + '/catalog/productslist/search/'
			+ urlencode_string($e('skeywords').value);
}

function mycarousel_initCallback2(carousel) 
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover( function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});

	jCarousel = carousel;
};



/*
function uncheckGroup(model_id) {
	if (model_id > 0) {
		if ($e('model_' + model_id)) {
			all_checks = document.getElementsByTagName('input');

			if (all_checks == null)
				return;

			for (i = 0; i < all_checks.length; i++) {

				var elem = all_checks[i];
				obj_type = elem.getAttribute('type');
				obj_id = elem.getAttribute('id');

				if (obj_type == 'checkbox') {
					$e(obj_id).checked = false;
				}
			}
		}
	} else {
		all_checks = document.getElementsByTagName('input');

		if (all_checks == null)
			return;

		for (i = 0; i < all_checks.length; i++) {
			var elem = all_checks[i];
			obj_type = elem.getAttribute('type');
			obj_id = elem.getAttribute('id');
			if (obj_type == 'checkbox') {
				$e(obj_id).checked = false;
			}
		}
	}
}
*/

