function log(e) {
	//return false;
	if(typeof(console)=='object') console.log(e);
	//else alert(e);
};

//--------------------------------------------------------------------------

$(document).ready(function() {
	Cufon.replace('.cufon, h1, h2, h3 span:not(.name)');
	Cufon.replace('#quickLinks a, #topCart .overview .link, .productRow .category a span.title1', { fontFamily: 'MyriadPro', hover: true });

	// header cart
	var cartLink = $('#topCart .overview .link');
	if(cartLink.length) {
		var cartContent = $('#cartContent');
		cartContent.hide().addClass('active');
		cartLink.click(function(){
			cartContent.toggle(200);
			$('#topCart').toggleClass('expanded');
			return false;
		});
  	}
/*
	$('.productRow .category a').hover(function(){
		$(this).children('span.title1').show();
	},function(){
		$(this).children('span.title1').hide();
	});
*/
	$('#aboutBox .plusIcon a').click(function(){
		if($(this).parents("#aboutBox").children("span").attr("class") == "plusIcon") {
			$(this).parents("#aboutBox").children("div").children("div.whiteBlock").css('opacity', '0');
			var h = $(this).parents("#aboutBox").children("div").children('.textOpened').height();

			$("#aboutBox").children("div").animate({ 'height': h, 'padding-bottom' : '20px' }, 500, function () {
				$(this).parents("#aboutBox").children("span").removeClass('plusIcon');
				$(this).parents("#aboutBox").children("span").addClass('minusIcon');
      		});
		} else {
			$(this).parents("#aboutBox").children("div").children("div.whiteBlock").css('opacity', '1');
			$("#aboutBox").children("div").animate({ 'height': 97, 'padding-bottom' : '40px' }, 500, function () {
				$(this).parents("#aboutBox").children("span").removeClass('minusIcon');
				$(this).parents("#aboutBox").children("span").addClass('plusIcon');
      		});
		}

		return false;
	});

	if($('#slides').length) {
		$('#slides').slides({
			preload: true,
			preloadImage: '/public/js/slides/img/loading.gif',
			play: 5000,
			pause: 2500,
			hoverPause: true
		});
	}

	// carousel
	//if(!($.browser.msie && parseInt($.browser.version) <= 6))
	{
		$('#carousel .outer').after('<span class="controlPrev prev"><!-- --></span><span class="controlNext next"><!-- --></span><span id="selectorCenter"><!-- --></span>');
		$('#carousel .outer').scrollable({ size: 4}).circular(); //.autoscroll({interval: 5000});
		$('#carousel .item').unbind('click');
	}

	// autosubmit filter
	$('.filter.autosubmit').hover(function(){
		autosubmit_changed = false;
		$(this).find('input').change(function(){ autosubmit_changed = true; });
	},function(){
		if(autosubmit_changed) {
			$(this).parents('form').submit();
		}
	});

	function callback(e) {
		var parent = $(this).parents('form:first');
		var ida = $("input[name='pl_sb_ida']:hidden", parent).val();
		var idi = $("input[name='pl_sb_idi']:hidden", parent).val();
		var uoin = $("input[name='pl_sb_uoin']:hidden", parent).val();
		var amount = $("input[name='pl_sb_amount']", parent).val();

		var obj = document.getElementById('cartContent');
		var oScript = document.createElement('script');
		oScript.setAttribute('type','text/javascript');
		
		oScript.setAttribute('src','/AspService/_service_FurnitureComponents_01.asp?AddBasket=1&rChWR=' + ($("#rChWR").html()) + '&pl_sb_ida=' + ida + '&pl_sb_idi=' + idi + '&pl_sb_uoin=' + uoin + '&pl_sb_amount=' + amount + '&add=1&RND=' + Math.random());
		obj.appendChild(oScript);

		setTimeout(function(){
			$(".effects-transfer").css({border: "2px dotted #a3238e"});
		}, 100);
	};

	$(".basket").click(function (e) {
		var options = { to: "#topCart", className: 'effects-transfer', easing: 'easeInQuint' };
		$(this).effect("transfer", options, 550, callback);

		$('#cartContent').hide();
      		$('#topCart').removeClass('expanded');

		return false;
	});
	
	$("#amountPlus").click(function (e) {
		var obj = document.getElementById('pl_sb_amount');
		var amount = parseInt(obj.value);

		if (!isNaN(amount)) {
			if (amount < 9999 ) amount ++;
			obj.value = amount;
		}

		return false;
	});
	$("#amountMinus").click(function (e) {
		var obj = document.getElementById('pl_sb_amount');
		var amount = parseInt(obj.value);

		if (!isNaN(amount)) {
			if (amount > 1) amount --;
			obj.value = amount;
		}

		return false;
	});

	$("#sn a[title]").tooltip({
		tip: '#tooltip',
		offset: [-3, 0],
		onBeforeShow: function() {
			$("#emailForm").stop().stop(true, true).hide();
			return true;
		}

	});
	$("#aBlock a[title]").tooltip({
		tip: '#tooltip',
		offset: [3, 0],
		onBeforeShow: function() {
			$("#emailForm").stop().stop(true, true).hide();
			return true;
		}

	});
	$("#sn1>a[title]").tooltip({
		tip: '#tooltip',
		offset: [-3, 0],
		onBeforeShow: function() {
			var boo = $("#emailForm").is(":hidden");
			return boo;
		}

	});
	
     if($('#ppy1').length) {
     	var options1 = {
			caption:    'hover',
			navigation: 'permanent',
			direction:  'left',
			zindex: 100
		}
		$('#ppy1').popeye(options1);
	}
});

showMailForm = function(obj) {
	var tt = $("#tooltip");
	tt.hide();

	var f = $(obj).parent().parent().find("form");
	$(f).stop().stop(true, true).slideDown('fast').show();
	//$(f).css('display','block');

	//var inp = $("#sn1 .fst");
	//inp.focus();

	return false;
};
hideMailForm = function(obj) {
	var f = $(obj).parent();
	$(f).stop().stop(true, true).hide();
	//$(f).css('display','none');
	return false;
};

function updateBasket(ida, idi, uoin, obj1) {
	var amount = parseInt(obj1.value);

	if (!isNaN(amount)) {
		var obj = document.getElementById('cartContent');
		var oScript = document.createElement('script');
		oScript.setAttribute('type','text/javascript');
		oScript.setAttribute('src','/AspService/_service_FurnitureComponents_01.asp?AddBasket=1&rChWR=' + ($("#rChWR").html()) + '&pl_sb_ida=' + ida + '&pl_sb_idi=' + idi + '&pl_sb_uoin=' + uoin + '&pl_sb_amount=' + amount + '&pl_sb_oins=0&add=1&RND=' + Math.random());
		obj.appendChild(oScript);
	}
};

function deleteBasket(ida, idi) {
	var obj = document.getElementById('cartContent');
	var oScript = document.createElement('script');
	oScript.setAttribute('type','text/javascript');
	oScript.setAttribute('src','/AspService/_service_FurnitureComponents_01.asp?AddBasket=1&rChWR=' + ($("#rChWR").html()) + '&pl_sb_ida=' + ida + '&pl_sb_idi=' + idi + '&pl_sb_uoin=-1&pl_sb_amount=0&pl_sb_oins=0&add=1&RND=' + Math.random());
	obj.appendChild(oScript);

	return false;
};

function changeBasketTxt (str, str1) {
	var obj1 = $("#cartSum").html(str1);
	var obj2 = $("#cartContent").html(str);
	$(".effects-transfer").fadeOut();

	var boo = $('#topCart').hasClass('expanded');
	if (!boo) {
		$('#cartContent').show(200);
		$('#topCart').addClass('expanded');
	}
}
function closeCart() {
      	$('#cartContent').hide(200);
      	$('#topCart').removeClass('expanded');
       return false;
};

try {
	DD_belatedPNG.fix('#content,.png,.button,.button span,#brands img,.brand img,.specialProduct,#page,.product,.buy .overlay,#sidebar,#sideMenu li a,#sideMenu li ul li,.zoom,#carousel .item img,.contact,.contact img,.textContent .textA,.textContent .textB, #logo img, .bFB img, p.pager');
} catch(e){}

function AddToFavorites(url, title) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
		return false;
	} else if (window.external) { // IE Favorite
		window.external.AddFavorite( url, title);
		return false;
	} else if (window.opera) { // Opera 7+
		$("#productInfo a.iconFav").attr("href",url);
		$("#productInfo a.iconFav").attr("title",title);
		$("#productInfo a.iconFav").attr("rel","sidebar");
	} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
		alert('Bohužel, tento prohlížeč nepodporuje požadovanou akci, přidejte si prosím stránku do oblíbených položek ručně.');
		return false;
	}
}
