function popup(url, width, height, options) {
	if (!url) return false;
	var optionsDefault = {
		width : 400,
		height : 400,
		windowName : "popup",
		scrollbars : true,
		resizable : true,
		onOpen : function(w){if (w && w.focus) return w.focus();}
	}
	if (options) {
		jQuery.extend(options, optionsDefault);
	} else {
		options = optionsDefault;
	}
	var windowFeatures = [];
	if (width) {
		windowFeatures.push('width='+width);
	} else {
		windowFeatures.push('width='+options.width);
	}
	if (height) {
		windowFeatures.push('height='+height);
	} else {
		windowFeatures.push('height='+options.height);
	}
	if (options.scrollbars) {
		windowFeatures.push('scrollbars=yes');
	} else {
		windowFeatures.push('scrollbars=no');
	}
	if (options.resizable) {
		windowFeatures.push('resizable=yes');
	} else {
		windowFeatures.push('resizable=no');
	}
	w = window.open(url, options.windowName, windowFeatures);
	if (options.onOpen) {
		options.onOpen(w);
	}
	return w;
}

(function(){
	$(document).ready(function() {
		$('#menu a.submenu').click(function(){
			s = $(this).parents('li').find('ul');
			$.cookie('productsSubmenuShow', null, {'path' : '/'});
			if ($(s).is(':visible')) {
				$(s).slideUp();
				$.cookie('productsSubmenuShow', '0', {'path' : '/'});
			} else {
				$(s).slideDown();
				$.cookie('productsSubmenuShow', '1', {'path' : '/'});
			}
			return false;
		});
		$('a[class*=popup]').click(function (e) {
			e.preventDefault();
			var a = $(this);
			var c = $(a).attr('class');
			var p = c.indexOf('popup_', 0);
			if (p != -1) {
				p += 6;
				if (c.indexOf(' ', p) != -1) {
					var d = c.substring(p, c.indexOf(' ', p));
				} else {
					var d = c.substring(p);
				}
				d = d.split('x');
				popup($(a).attr('href'), d[0], d[1]);
			} else {
				popup($(a).attr('href'));
			}
		});
		$('.goBack').click(function (e) {
			e.preventDefault();
			history.back();
		});
		$('.goToIndex').click(function (e) {
			e.preventDefault();
			location.href = 'index.php';
		});
		$('.windowClose').click(function (e) {
			e.preventDefault();
			window.close();
		});	
		$('.windowCloseUpdate').click(function (e) {
			e.preventDefault();
			if (window.opener) {
				window.opener.location.reload(true);
				window.close();
			}
		});
	});
})();
