hov=new Image(260,40);
hov.src="/Data/879/Skins/WebyshoppingMain/img/add_button_hover.png";


$(document).ready(function(){
	/* vygenerovanie head-menu z foot-menu */
	$('#head-menu').html($('#foot-menu-in').html());
	/* /vygenerovanie head-menu z foot-menu */
	
	$('.SEOContent').append('<a href="#top" class="hore">Návrat hore &uarr;</a>');

	$('.hore').click(function() {
		 goToByScroll("top");
     	return false;
     });
	
	$(".addon-col table tr:nth-child(odd)").addClass('odd');
  	$(".addon-col table tr:nth-child(even)").addClass('even');
	
	if(!$("#details ul.pagination").length){
		$("#details").css('padding-bottom','100px');
	}
	/* funkcionalita popup menu v head-menu */
	objhide = objshow = objshowtimer = objhidetimer = null;

	$('#head-menu-over ul.menu > li').hover(function() {
		if (objhide) {
			if ($(this).attr('class') == objhide.attr('class')) {
				clearTimeout(objhidetimer);
			} else {
				checkHover();
			}
		}
		
		objshow = $(this);
		objshowtimer = setTimeout('delayedShow()', 200);
	}, function() {
		clearTimeout(objshowtimer);
		objhide = $(this);
		objhidetimer = setTimeout('checkHover()', 500);
	});
	/* /funkcionalita popup menu v head-menu */
	
	$('#sjm-s-kategorie li.item-down').hover(
		function() {$('ul', this).show();},
		function() { $('ul', this).hide();}
	);
	
	/* galery */
	$('.gallery a').lightBox({
			overlayOpacity: 0.5,
			imageLoading: '/Data/879/Skins/WebyshoppingMain/images//lightbox-ico-loading.gif',
			imageBtnClose: '/Data/879/Skins/WebyshoppingMain/images/lightbox-btn-close.gif',
			imageBtnPrev: '/Data/879/Skins/WebyshoppingMain/images/lightbox-btn-prev.gif',
			imageBtnNext: '/Data/879/Skins/WebyshoppingMain/images/lightbox-btn-next.gif',
			txtImage: 'Foto',
			txtOf: 'z',
			fixedNavigation:true
		});
	
	/* /galery */
	
	/* inline label pre query */
	input_query = $('#query');
	if(input_query.attr('value')=='')
	{
		input_query.attr('value', input_query.attr('title'));
		input_query.bind('focus', function(){
			if (input_query.attr('value') == input_query.attr('title')) {
				input_query.attr('value', '').removeClass('empty');
			}
		}).bind('blur', function(){
			if ((input_query.attr('value') == '') || (input_query.attr('value') == input_query.attr('title'))) {
				input_query.attr('value', input_query.attr('title')).addClass('empty');
			}
		});
	}
	else
		input_query.removeClass('empty');
	
	$('#search-box form').submit(function() {
      if ($("#query").val() == "Sem napíšte hľadaný tovar") {
        $("#query").val('')
      }
    });
	/* /inline label pre query */
	

	/* overlay */
	
	$("#categories a[rel]").overlay({
		start: {
			top: 'center',
			left: 'center'
		},
		finish: {
			top: 'center',
			left: 'center'
		},		
		expose: {
			color: '#000',
			opacity: 0.5,
			loadSpeed: 0,
			closeSpeed: 0
		},
		speed: 'fast',
		zoomType: 'div',
		boxColor: '#fff',
		boxRadius: 5
	});
	
	/* custom overlay */	

	$("a.custom[rel]").overlay({
		start: {
			top: 'center',
			left: 'center'
		},
		finish: {
			top: 'center',
			left: 'center'
		},
		expose: {
			color: '#000',
			opacity: 0.5,
			loadSpeed: 0,
			closeSpeed: 0
		},
		speed: 'fast',
		zoomType: 'div',
		boxColor: '#fff',
		boxRadius: 5,
		onBeforeLoad: function() {
			if (this.getTrigger().attr('rel') == '#card-overlay') {
				
				regheader = 'VIRTUÁLNA WEBYSHOPPING BONUS CARD';
				regtext = '<div align="center"><a href="/moje-vyhody-nakupovania.xhtml">ďalšie výhody</a></div>';			
				
				if(!this.getTrigger().attr('title')) $('.bonus-row').html('');
				else
				{
					if (document.getElementById('logged-user-name')!=null)
					{
						$('#card-overlay p.title').html(regheader);
						$('#card-overlay #card-text').html(regtext);
						$('#card-overlay .bonus-card span').html($("#logged-user-name").html());
					}
					$('#bonus-item').html(this.getTrigger().attr('title'));
				}
			} else if (this.getTrigger().attr('rel') == '#contact-overlay') {
				contact = '#' + this.getTrigger().attr('id') + '-contact';
				$('#contact-overlay .content').html($(contact).html());
			}			
        }
	});
	
	$("a.deliveryconditions-overlay").overlay({
		start: {
			top: 'center',
			left: 'center'
		},
		finish: {
			top: 'center',
			left: 'center'
		},
		expose: {
			color: '#000',
			opacity: 0.5,
			loadSpeed: 0,
			closeSpeed: 0
		},
		speed: 'fast',
		zoomType: 'div',
		boxColor: '#fff',
		boxRadius: 5,
		target: '#deliveryconditions-overlay',
		onBeforeLoad: function() {			
			$('#deliveryconditions-overlay .content').html('<p style="margin: 180px 0px 0px 370px;"><img src="/Data/879/Skins/WebyshoppingMain/images//lightbox-ico-loading.gif" alt="Načítavam..." title="Načítavam" />');
			var myUrlData = this.getTrigger().attr('name');
			var myUrl = "http://" + myUrlData.replace(/---/g, '/');
			$('#deliveryconditions-overlay .content').load(myUrl);
        }
	});
	/* /custom overlay */
	/* /overlay */
	
	$('a.sort, a.asc, a.desc').click(function(){
	   var myUrlData = $(this).attr('name');
	   var myUrl = "http://" + myUrlData.replace(/---/g, '/');
	   document.location = myUrl;
	   return false;
	 });
	
	
	if($('#submit-query').attr('name')=='advancedsearchsubmit'){
		$('#advanced-search-trigger').addClass('active');
		$('#advanced-search-box').show();		
	}
	
	$('#advanced-search-trigger').click(function(){
		 if ($(this).hasClass('active')) {
			 $(this).removeClass('active');
			 $('#advanced-search-box').hide();
			 $('#submit-query').attr('name','searchsubmit');
		}
	    else {
		    $('#advanced-search-box').show();
			$(this).addClass('active');
			$('#submit-query').attr('name','advancedsearchsubmit');
		}
		return false;
	});

	
	/* stránkovanie položiek */
	if ($('div.scrollable').attr('class')) {
		scrollapi = $('div.scrollable').scrollable({ 
			size: Number($('div.scrollable').attr('class').charAt(0)),
			interval: Number($('div.scrollable').attr('class').charAt(2)) * 1000,
			loop: true,
			api: true,
			speed: 500,
			navi: '.navi-1',
			keyboard: false
		});
	}
	
	$('div.navi-1').css('margin-left', -$('div.navi-1').width()/2).click(function(){
		scrollapi.getConf().interval = 0; 
	});
	
	if ($('div.scrollable-sale').attr('class')) {
		$('div.scrollable-sale').scrollable({ 
			size: Number($('div.scrollable-sale').attr('class').charAt(0)),
			navi: '.navi-2',
			keyboard: false
		});
	}
	
	$('div.navi-2').css('margin-left', -$('div.navi-2').width()/2);
	
	if ($('div.scrollable-search').attr('class')) {
		$('div.scrollable-search').scrollable({ 
			size: Number($('div.scrollable-search').attr('class').charAt(0)),
			navi: '.navi-3',
			keyboard: false
		});
	}
	
	$('div.navi-3').css('margin-left', -$('div.navi-3').width()/2);
	
	if(document.getElementById('question-button')!=null)
	{
		var producturl = (window.location.href).replace(/\//g,'@').replace(/.xhtml/g,'');
		var linkbutton = '<a href="'+($('#question-button a').attr('href'))+'" onclick="location.href=\''+($('#question-button a').attr('href'))+'?Mam otazku k produktu: '+($('#question-button a').attr('title'))+' na adrese '+producturl+'\';return false;">Mám otázku</a>';
		$('#question-button').html(linkbutton);
	}

	if(document.getElementById('page12996')!=null && (window.location.href).indexOf('?')!=-1 && (window.location.href).indexOf('?a=send')==-1)
	{
		var curenturl = window.location.href;
		var textareatext = curenturl.substr(curenturl.indexOf('?')+1).replace(/@/g,'/')+'.xhtml';
		textareatext = textareatext.replace(/%20/g,' ');
		$('#page12996 #content form').find('textarea').html(textareatext+"\n\n... sem dopiste vasu otazku");
	}
	
	if(location.hash) {
	 if (location.hash == '#NoProdFnd')
	  $('#ErrorMessageId').html('<p class="ErrorMessage" id="NoProdFnd">Produkt, ktorý hľadáte sa v našej ponuke už nenachádza.</p>');
	 if (location.hash == '#NoCtProdFnd')
	  $('#ErrorMessageId').html('<p class="ErrorMessage" id="NoCtProdFnd">Kategória produktov, ktorú hľadáte už nie je zaradená v našej ponuke.</p>');
	 if (location.hash == '#NoProdFndAftSrch')
	  $('#ErrorMessageId').html('<p class="ErrorMessage" id="NoProdFndAftSrch">Produkty, ktoré hľadáte sa v našej ponuke už nenachádzajú. Skúste zmeniť vyhľadávané slová.</p>');
	}
	
	/* /stránkovanie položiek */
	
	/* pridanie do košíka */
	/*
	$('.shopping-cart').viewable(function(event, percent){
		percent == 0 ? cartvisible = false: cartvisible = true;
	});
	
	$('.basket img').live('click', function(){
		$.ajax({
			type: 'GET',
			url: '/request.php',
			data: 'rid=basket.add',
			dataType: 'json',
			success: function(json) {
				// experimental 
				if (!cartvisible) {
					viewTop = self.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop;
					
					$('.clone').remove();
					
					var cartnotify = $('.shopping-cart').clone().addClass('clone').appendTo('#container').css({
						'position': 'absolute',
						'left': '720px', 
						'top': '140px',
						'z-index': '999',
						'-moz-box-shadow': '3px 5px 9px rgba(0,0,0,0.5)',
						'-webkit-box-shadow': '3px 5px 9px rgba(0,0,0,0.5)'
					}).animate({
						top: viewTop
					}, function(){
						$('.cart-price, .cart-items').animate({
							marginRight: 35
						}, 200, function(){
							$('.cart-price').html(json.price);
							$('.cart-items').html(json.items);
						}).animate({
							marginRight: '0'
						}, 1000, 'easeOutBounce', function(){
							cartnotify.fadeOut('slow', function(){
								cartnotify.remove();
							})
						});
					});
				} else {
					$('.cart-price, .cart-items').animate({
						marginRight: 35
					}, 200, function(){
						$('.cart-price').html(json.price);
						$('.cart-items').html(json.items);
					}).animate({
						marginRight: '0'
					}, 1000, 'easeOutBounce');
				}
				// experimental 
			}
		});
	});
	*/
	/* /pridanie do košíka */
	
	/* pridanie do porovnania */
	/*
	$('.compare-trigger').live('click', function(){
		$.ajax({
			type: 'GET',
			url: '/request.php',
			data: 'rid=compare.add&pid=' + $(this).parents('.item').attr('id'),
			dataType: 'html',
			success: function(html) {
				if (html) {
					if ($('#compare').hasClass('hidden')) {
						$('#compare').css('position', 'relative').show('slow', function(){
							$(html).appendTo('#compare').hide().fadeIn();
							$('#compare').removeClass('hidden');
						}).css('position', 'fixed');
					} else {
						$(html).appendTo('#compare').hide().fadeIn();
					}
				}
			}
		});
		return false;
	});
	*/
	/* /pridanie do porovnania */
	
	/* odstránenie z porovnania */
	/*
	$('#compare span.remove').live('click', function(){
		icon = $(this).parents('.icon');
		$.ajax({
			type: 'GET',
			url: '/request.php',
			data: 'rid=compare.remove&pid=' + icon.attr('id'),
			dataType: 'text',
			success: function(msg) {
				if (msg) {
					icon.fadeOut(function(){
						icon.remove();
						if (msg == 2) {
							$('#compare').hide('slow').addClass('hidden');
						}
					});
				}
			}
		});
	});
	*/
	/* /odstránenie z porovnania */
	
	/* nastavovanie cenového rozsahu */
	/*
	objlisting = objlistingtimer = minprice = maxprice = null;
	
	if ($('#slider-range').attr('id')) {
		$('#slider-range').slider({
			range: true,
			animate: true,
			min: Number($('#min-price').val()),
			max: Number($('#max-price').val()),
			values: [$('#min-price').val(), $('#max-price').val()],
			slide: function(event, ui) {
				$('#amount').val(ui.values[0] + ' € - ' + ui.values[1] + ' €');
			},
			start: function(event, ui) {
				if (objlisting) {
					clearTimeout(objlistingtimer);
				}
			},
			stop: function(event, ui) {
				objlisting = true;
				minprice = ui.values[0];
				maxprice = ui.values[1];
				objlistingtimer = setTimeout('updateListing("filter-price", "")', 1000);
			}
		});
		$('#amount').val($('#slider-range').slider('values', 0) + ' € - ' + $('#slider-range').slider('values', 1) + ' €');
	}
	*/
	/* /nastavovanie cenového rozsahu */

	/* inicializácia záložiek */
	$('ul.tabs').tabs('div.panes > div');
	/* /inicializácia záložiek */ 
	
	/* filter pre výber dodávateľa alebo typu produktu */
	/*
	$('ul.filter li').click(function(){
		if (!$(this).hasClass('selected')) {
			$(this).addClass('selected').siblings().removeClass('selected');
			objlisting = true;
			updateListing($(this).parent().attr('id'), $(this).attr('id'));
		}
	});
	*/
	/* /filter pre výber dodávateľa alebo typu produktu */
	
	/* stránkovanie */
/*	$('ul.pagination a').live('click', function(){
		objlisting = true;
		updateListing('pagination', $(this).attr('class'));
		return false;
	});*/
	/* /stránkovanie */

	/* triedenie */
/*	sortingtype = null;
	
	$('ul.sorting a').click(function(){
		if ($(this).parent().parent().hasClass('asc')) {
			sortingtype = 'asc';
			changesortingtype = 'desc';
			stimg = '/img/arrow_up_small.png';
			chstimg = '/img/arrow_down_small.png';
		} else {
			sortingtype = 'desc';
			changesortingtype = 'asc';
			stimg = '/img/arrow_down_small.png';
			chstimg = '/img/arrow_up_small.png';
		}
		
		if ($(this).hasClass('selected')) {
			$(this).parent().parent().removeClass(sortingtype).addClass(changesortingtype);
			$(this).next('img').attr('src', chstimg);
		} else {
			$(this).parent().parent().find('a').removeClass('selected').next('img').remove();
			$(this).addClass('selected').after(' <img src="' + stimg + '" />');
		}

		objlisting = true;
		updateListing('sorting', $(this).attr('id'));
		return false;
	});
	/* /triedenie */
	
	/* skryt prazdny pravy stlpec na index stranke */
	
	var pathname = window.location.pathname;
	
	var urlparams = window.location.search.substr(1).split("&"); 

	var urlHttpGetVars = new Array(); 
	for(i = 0; i < urlparams.length; i++){
		urlHttpGetVars[urlparams[i].split("=")[0]] = unescape(urlparams[i].split("=")[1]); 
	}	

	if((pathname=='/' || pathname=='/webyshopping.xhtml') && urlHttpGetVars["searchstring"]==null)
		$('.side-column').css({'display' : 'none'});	
	
	/*  *** */
	
	/* oprava png s alpha kanálom pre IE5.5 a IE6 */
	if ($.browser.msie && $.browser.version < 7) {
		$(this).find('*').each(function() {
			
			b = $(this).css('background-image');
			if (b.indexOf('.png') != -1) {
				var f = b.split('url("')[1].split('")')[0];
				$(this).css('background-image', 'none');
			}
	
			if ($(this).is('[src$=.png]')) {
				var f = $(this).attr('src');
				$(this).attr({
					src: '../img/blank.gif',
					width: $(this).width(),
					height: $(this).height()
				});
			}
	
			if (f) $(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + f + "',sizingMethod='crop')";
		});
	}
	/* /oprava png s alpha kanálom pre IE5.5 a IE6 */
});

/* funkcie pre popup menu v head-menu */
function checkHover() {
	if (objhide) {
		objhide.find('ul').hide();
		objhide = null;
	}
}

function delayedShow() {
	if (objshow) {
		objshow.find('ul').show();	
	}
}
/* /funkcie pre popup menu v head-menu */

/* funkcie pre popup menu v head-menu */
/*
function updateListing(t, v) {
	if (objlisting) {
		switch (t) {
			case 'filter-company':
				datastring = 'type=' + t + '&value=' + v;
				break;
			case 'filter-price':
				datastring = 'type=' + t + '&min=' + minprice + '&max=' + maxprice;
				break;
			case 'filter-type':
				datastring = 'type=' + t + '&value=' + v;
				break;
			case 'pagination':
				datastring = 'type=' + t + '&value=' + v;
				break;
			case 'sorting':
				datastring = 'type=' + t + '&sortby=' + v + '&sorttype=' + sortingtype;
				break;
		}
		
		$.ajax({
			type: 'GET',
			url: '/request.php',
			data: 'rid=listing.update&' + datastring,
			dataType: 'html',
			async: false,
			beforeSend: function(html) {
				$('#listing-container').append('<div id="loader"><!----></div>');
			},
			success: function(html) {
				$('#loader').fadeOut('fast', function(){
					$('#listing-container').html(html).fadeTo('fast', 1, function(){
						if (t == 'filter-company' || t == 'filter-type') {
							$('#slider-range').slider('option', 'min', Number($('#min-price').val()));
							$('#slider-range').slider('option', 'max', Number($('#max-price').val()));
							$('#slider-range').slider('values', 0, Number($('#min-price').val()));
							$('#slider-range').slider('values', 1, Number($('#max-price').val()));
							$('#amount').val($('#slider-range').slider('values', 0) + ' € - ' + $('#slider-range').slider('values', 1) + ' €');
						}
						
						//$('html, body').animate({
							//scrollTop: $(".shopping-cart").offset().top
						//}, 700);
						
					});
				});
			}
		});
		objlisting = null;
	}
}
*/
/* /funkcie pre popup menu v head-menu */

function CreateBookmarkLink(url,title) {
	if (window.sidebar) window.sidebar.addPanel(title, url,"");
	else if( window.external ) window.external.AddFavorite( url, title);
}

function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},1000);
}
