function nav() { // hide/show top subnav 
 $("#nav ul ul").css({display: "none"});
 $("#nav ul li").hover(function(){
  $("ul li:last", this).css('background-image', 'none');
  $(this).addClass("hov");
  $(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(100);
 },function() {
  $(this).removeClass("hov");
  $(this).find('ul:first').css({visibility: "hidden"});
 });
}

function rotator() { // hp and datapage rotator init
 $('ul#rotate li').css({opacity: 0.0});
 $('ul#rotate li:first').addClass('show').css({opacity: 1.0});
 setInterval('rotate()',5000);
}

function rotate() { // hp and datapage rotator
 var current = ($('ul#rotate li.show')?  $('ul#rotate li.show') : $('ul#rotate li:first'));
 var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('ul#rotate li:first') :current.next()) : $('ul#rotate li:first'));
 next.css({opacity: 0.0, display: 'block'}).addClass('show').animate({opacity: 1.0}, 500);
 current.css({display: 'none'}).animate({opacity: 0.0}, 500).removeClass('show');
}

function oddrow() { // color odd rows in tables
 $("tr:odd, #cat div.item:even").css("background-color", "#f4f4f4");
}

function lblink() { // lightbox link
 $("a.lb").hover(function(){
  $(this).append("<div class=\"imgoverlay\"></div>");
  $(".imgoverlay").css('opacity', 0.8);
  $(".imgoverlay").width($("img", this).width());
  $(".imgoverlay").height($("img", this).height());
  var leftpos = ($(this).width() - $("img", this).width()) / 2;
  $(".imgoverlay").css({ 'left': leftpos+'px'});
 },function() {
  $('.imgoverlay').remove();
 }); 
}

function lb() { // lightbox
 if ($("a.lb").length != 0) $("a.lb").fancybox({
  overlayColor: "#000",
  overlayOpacity: 0.8,
  titlePosition: 'inside'
 });
}

function addToRqf(id, name) {
	$('#requestformcontainer').show();
	$.scrollTo('#requestform');
	if($('#rqfrow-'+id).length == 0) {
		$('#rqftable').append('<tr id="rqfrow-'+id+'"><td>'+name+'<input type="hidden" name="data[Catalog][Product][]" value="'+name+'" /></td><td><div class="input text"><input class="quantity" type="text" name="data[Catalog][Quantities][]" /></div></td><td><a href="#" id="rqfrm-'+id+'" class="btn-4">odebrat</a></td></tr>');
		$('#rqfrm-'+id).click(function(event) {
			event.preventDefault();
			$('#rqfrow-'+id).remove();
		});
	}
}

$(document).ready(function() {
 nav();
 rotator();
 oddrow();
 lblink();
 lb();
});
