function folding(divId)
{
	if(!divId) divId = "";
	
	jQuery(divId + ' .eshop-comparsion .eshop-chead')
		.click(	function() 
		{
			jQuery(this).find('span.eshop-closeOneElement, span.eshop-openOneElement').toggle()
			jQuery(this).parents('.eshop-comparsion').children('.eshop-cbody').toggle();
			return false;
		})
		.each(function()
		{
			this.onselectstart = function() {
				return false;
			};
			this.unselectable = "on";
			this.style.MozUserSelect = "none";
			this.style.cursor = "pointer";
		})
	
			
	jQuery(divId + ' .eshop-comparsions .eshop-openAllElements')
		.click(function() 
		{
			c = jQuery(this).parents('.eshop-comparsions');
			c.find('.eshop-closeOneElement').show();
			c.find('.eshop-openOneElement').hide();
			c.find('.eshop-cbody').show();
			return false;
		});
		
	jQuery(divId + ' .eshop-comparsions .eshop-closeAllElements')
		.click(function() 
		{
			c = jQuery(this).parents('.eshop-comparsions');
			c.find('.eshop-openOneElement').show();
			c.find('.eshop-closeOneElement').hide();
			c.find('.eshop-cbody').hide();
			return false
		});
}


function adons()
{
	jQuery('.eshop-adon .eshop-ahead input').checkbox()
		.click(function() {
			jQuery(this).parents('.eshop-adon').toggleClass("eshop-selected").children('.eshop-abody').slideToggle(100);
		})
		.each(function() {
			if(!this.checked){
				jQuery(this).parents('.eshop-adon').children('.eshop-abody').hide();
			}else{
				jQuery(this).parents('.eshop-adon').addClass("eshop-selected");
			}				
		});
	
	jQuery('.eshop-adon .eshop-ahead label').click(function() {
			jQuery(this).parents('.eshop-ahead').find('input').click();
			return false;
		});
};


function formatPrice(value)
{
	price = value.toString();
	if(Math.abs(value) >= 1000)
		price = price.substr(0, price.length-3) + '.' +  price.substr(price.length-3)
	return price;
}

function startSlider(slider, input, sliderprice, slidersum, min, max, coefficient, originalPrice, price, key)
{
	jQuery(slider +" .ui-slider-1")
	.slider(
		 {
			 max: max,
			 min: min,
			 startValue: min,
			 slide: function(event, ui)
			 {
			 	paymentSliders[key].selectedValue = Math.round(Math.floor(ui.value) * coefficient);
			 	paymentSliders[key].originalValue = Math.floor(ui.value);
			 	refreshSliderPrices();
			 },
			 change: function(event, ui) 
			 {
			 	paymentSliders[key].selectedValue = Math.round(Math.floor(ui.value) * coefficient);
			 	paymentSliders[key].originalValue = Math.floor(ui.value);
			 	refreshSliderPrices();
			 	recountSliders(slider);
			 }
		 }
	);
	paymentSliders[key].originalPrice = originalPrice;
	jQuery(input).keyup(function () {												
		jQuery(slider +" .ui-slider-1").slider( "moveTo", parseInt(jQuery(this).attr('value')), 0 );
	});									
}

function recountSliders(sliderId) {
	var totalDiscount = 0;
	var slider = null;
	jQuery.each (paymentSliders, function () {
		totalDiscount += parseInt(this.selectedValue);
		if (this.id == sliderId) slider = this;
	});
	var leftPrice = paymentSlidersOriginalPrice - totalDiscount;
	jQuery('#totalDiscount').text(totalDiscount);
	if (leftPrice < 0 && (parseInt(slider.selectedValue)+leftPrice) >= 0) {
		jQuery(slider.id +" .ui-slider-1").slider( "moveTo", Math.round((parseInt(slider.selectedValue)+leftPrice)/slider.coefficient), 0 );
	}
}

function refreshSliderPrices() {
    var discount = 0;
	for (slider = 0; slider < paymentSliders.length; slider++) {
		jQuery(paymentSliders[slider].inputField).attr('value', paymentSliders[slider].originalValue)
		jQuery(paymentSliders[slider].price).text( formatPrice(Math.round(paymentSliders[slider].selectedValue)) )
		jQuery(paymentSliders[slider].sum).text(formatPrice(Math.max(paymentSliders[slider].originalPrice - discount - Math.round(paymentSliders[slider].selectedValue), minimalPrice)))

		discount += parseInt(paymentSliders[slider].selectedValue);
	}
}

function setupTooltips()
{
	jQuery('*[title]:not(*[tooltipText])').tooltip();
	jQuery(document).bind('ajaxupdate', setupTooltips);
}

function hideLabels()
{
	var hideLabelsFocus = function()
	{
		jQuery('.eshop-hideable').hide();
		jQuery(this).parents('.eshop-line').find('.eshop-hideable').show();
	}
	var hideLabelsEvent = function(){
		jQuery('.eshop-hideable').hide();
		jQuery("input[type='text'], input[type='password']")
			.unbind('focus', hideLabelsFocus)
			.focus(hideLabelsFocus);
	};
	hideLabelsEvent();
	jQuery(document).bind('ajaxupdate', hideLabelsEvent);
}


function popUpWindowCenter(targetURL, windowName, width, height, windowParams, returnVal) {
  if (typeof(newWin) == "object" && newWin != null && newWin.close) {
    newWin.close();
  }
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str = str + "," + windowParams + ",resizable";
  }
  newWin = window.open(targetURL, windowName, str, returnVal);
  newWin.focus();
  return returnVal;
}


function showMenus()
{
	/*
	 * LJU - nastavi class hovered pri hover akcii na polozky li
	*/
	
	// save tab that is selected - it has 'current' style
	var selectedTab = jQuery("#navigationmenu li.current");
	
	// if none of tabs is selected, mark first as selected
	if (selectedTab == null) selectedTab = jQuery("#navigationmenu li.first");
	jQuery(selectedTab).addClass("current");
	
	// if any of first level menu items is hovered
	jQuery("#navigationmenu").children("li").hover(
		function() {
			// show selected submenu 
			jQuery(this).children("ul").css("visibility", "visible");
			// if selected submenu is not a highlighted current, disable highlighting of current
			jQuery(selectedTab).removeClass("current");
		},function(){
			// hide hide selected submenu
			jQuery(this).children("ul").css("visibility", "hidden");
			// highlight current
			jQuery(selectedTab).addClass("current");
		}
	);
	
	// if any of summenu is hovered, mark parent li as current
	jQuery("#navigationmenu li ul").hover(
		function() {
			// highlight tab of submenu
			jQuery(this).parent().addClass("current");
		}, function(){
			// disable highlighting of submenu
			jQuery(this).parent().removeClass("current");
		}
	)
	
	// 2nd level submenu 
	jQuery("#navigationmenu li ul li").hover(
		function() {
			// highlight selected row
			jQuery(this).css("background-color", "#EEEEEE");
			// show selected submenu
			jQuery(this).children("ul").css("visibility", "visible");
			jQuery(this).children("ul").css("margin-left", jQuery(this).width());
			jQuery(this).children("ul").css("margin-top", jQuery(this).position().top - jQuery(this).height());
		}, function () {
			// remove highlighting of selected row			
			jQuery(this).css("background-color", "white");
			// hide all submenus
			jQuery(this).children("ul").css("visibility", "hidden");
		}
	)
	
	jQuery("#navigationmenu li ul li ul").hover(
		function() {
			jQuery(this).parent().addClass("current");
		} , function() {
			jQuery(this).parent().removeClass("current");
		}
	)
}




function EshopEmbedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn) 
{
	if (heightStr > 0)
		jQuery('#' + replaceElemIdStr).wrap(
	    	jQuery('<div></div>').css('height', heightStr + 'px'));
	
	return swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn)
}







