$(document).ready(function(){
	
	$("a.fbox").colorbox({ previous: '{{$colorbox_previous}}', next: '{{$colorbox_next}}', close: '{{$colorbox_close}}', current: '{{$colorbox_imageof}}', opacity: 0.5 });
  
  $("div#flashbox").livequery(function(){
		$(this).colorbox({inline:true, open: true,  href: "div#flashbox", opacity: 0.5});
	});
	
	$("div#flashbox a.fboxlink").live('click', function() {
		$.colorbox.close()
	});
	
	$("div#flashbox a:not(a.fboxlink)").live('click', function() {
		$(window.location).attr('href', this.href);
	});
  
  $("ul.menu_body li ul li:even a").addClass("alt");
  
  $('ul.menu_body li').hover(  
        function () {  
        		$(this).parents().css('z-index', 100);
            $('ul', this).slideDown(100);  
        },   
        function () {  
            $('ul', this).slideUp(100);   
						$(this).parents().css('z-index', 10);        
        }  
    ); 
	
	$("div[id^='snippet-']").addClass('inline');
	
	var spamvalue = $("input.spamProtection").attr("title");
	$("input.spamProtection").val(spamvalue);

	
	$('a.nicebutton:not(div.product_catalogue a.addtobasket, div.relatives_product a.addtobasket), a.jsbtn:not(div.product_catalogue a.addtobasket, div.relatives_product a.addtobasket)').livequery(function(){
		$(this).each(function(){
			var b = $(this);
			var tt = b.text() || b.val();

			b.text('').append($('<strong>').text(tt)).prepend($('<i></i>')).prepend($('<u></u>'));
		});
	});
	
	$('a.nicebutton_dual').livequery(function(){
		$(this).each(function(){
			var b = $(this);
			var tt = b.text() || b.val();

			b.prepend($('<i></i>')).prepend($('<u></u>'));
		});
	});
	
	if($.browser.msie && ($.browser.version=="6.0" || $.browser.version=="7.0")) {
	} else {
		$('form input:submit:not(form input.submitAttrs, form.nofx *)').livequery(function(){
			$(this).each(function(){
				
				var b = $(this);
				var tt = b.text() || b.val();
				var butt = $('<button>').attr('id', b.attr('id')).attr('name', b.attr('name')).addClass('nicebutton');
				butt.append($('<strong>').text(tt)).prepend($('<i></i>')).prepend($('<u></u>'));
				
				$($(this).parent()).append(butt);
				$(this).remove();
			});
		});
	}
	
	$('a.popup, a.giftpopup').live('mouseover', function() {
		var linkid = this.id;
		var popid = $(this).attr('rel');
		$('a.popup, a.giftpopup').removeBubbletip([$('#' + popid)]);
		$('#' + linkid).bubbletip('#' + popid, { deltaDirection: 'right', delayHide: 150 }).trigger('mouseover');
	});
	
	$('a.giftpopup').mouseover(function() {
		var linkid = this.id;
		var popid = $(this).attr('rel');
		if (($('#' + popid).length == 0) || ($('#' + popid).eq(0).closest('table.bubbletip').length > 0)) {
		} else {
			$('#' + linkid).bubbletip('#' + popid, { deltaDirection: 'right', delayHide: 150 }).trigger('mouseover');
		}
	});
	
	
	$('#quickchoicepopuplink').bubbletip('#quickchoicepopup', { deltaDirection: 'down', delayHide: 150 });
	
	$('form.fastchoice select').change(function() {
		$('form.fastchoice').submit();
	});
	
	//$.scrollTo( '#banner_splitted', 800 );
	
	$('#mapacr').append("<span id=\"jquerytestspan\">JS Test</span>"); 
	var bgtestspan=$('#jquerytestspan').css('backgroundColor'); 
	if (bgtestspan===('rgb(170, 170, 170)')||bgtestspan===('#aaaaaa')) {  
		var mapaimage=$('#mapa-cr-img').attr("src"); 
		$('#mapa-cr-img').attr("src", "http://alensis.cz/globalfiles/mailing/" + mapaimage); 
	};
	$('#jquerytestspan').remove();
	
	$('.shipping_form dl dt .info_text').livequery(function() {
		$(this).qtip({
			content: $(this).find('.info_text_body').text(),
			style: {
				width: 300,
				padding: 5,
				background: '#fef3c6',
				color: '#bf5a24',
				'font-size': '0.9em',
				'line-height': '1.4em',
				name: 'cream'
			},
		});
	});
	
	$('.shipping_form dl dd .info_text').livequery(function() {
		$(this).qtip({
			content: $(this).find('.info_text_body').text(),
			style: {
				width: 300,
				padding: 5,
				background: '#fef3c6',
				color: '#bf5a24',
				'font-size': '0.9em',
				'line-height': '1.4em',
				name: 'cream'
			},
			position: {
				corner: {
					target: 'bottomLeft',
					tooltip: 'topRight'
				}
			}
		});
	});
	 
});

	function mapa(kraj) {
		if(kraj < 15) {
			pozice = "-"+(kraj*167)+"px 0px "; // v�po�et posunut� rolloveru
			$('#mapacr').css('backgroundPosition', pozice); // p�esunut� rolloveru na vypo�tenou pozici
		}
	}

$(function () {
	$("form.ajax_attributes input:submit").hide();
});

(function ($) {

$.topZIndex = function (selector) {

	return Math.max(0, Math.max.apply(null, $.map($(selector || "body *"), 
		function (v) {
			return parseInt($(v).css("z-index")) || null;
		}
	)));
};

$.fn.topZIndex = function (opt) {

	if (this.length === 0) {
		return this;
	}
	
	opt = $.extend({increment: 1, selector: "body *"}, opt);

	var zmax = $.topZIndex(opt.selector), inc = opt.increment;

	return this.each(function () {
		$(this).css("z-index", zmax += inc);
	});
};

})(jQuery);


