// JavaScript Document
$(document).ready(function() {
	

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 10, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 50, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);

  $("#attach1").click(function(){
    $(".tabbottom1").toggleClass("tabbottom1c");
	$(".ws").toggleClass("ws1");				 
	});				
$("#attach2").click(function(){
    $(".tabbottom2").toggleClass("tabbottom2c");
	$(".kp").toggleClass("kp1");
  });	
$("#attach3").click(function(){
    $(".tabbottom3").toggleClass("tabbottom3c");
	$(".ns").toggleClass("ns1");
  });


    $('#slideshow').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 7000,
        pager:  '#slider_nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#slider_nav li:eq(' + (idx) + ') a';
        }
    });
	    $('#sliderbig').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 5500,
    });
			    $('#slidermin').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 6500,
    });
		$(function() {
		$( "#accordion" ).accordion();
	});
	$(function() {
		$( "#accordion2" ).accordion({
			autoHeight: false,
			navigation: true,
			collapsible: true
									 });
	});


		$('#prods .prod').bind({
			mouseenter: function() {
				$(this).children('div.i').fadeIn('fast');
			},
			mouseleave: function() {
				$(this).children('div.i').fadeOut('fast');
			}
		});
				$('#text .prod').bind({
			mouseenter: function() {
				$(this).children('div.i').fadeIn('fast');
			},
			mouseleave: function() {
				$(this).children('div.i').fadeOut('fast');
			}
		});


$("a#single_image").fancybox();
$("a#single_image1").fancybox();
$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});

							  
  $("#wymiary .flip").click(function(){
    $("#wymiaryinfo").slideToggle("slow");
  });
    $("#kolory .flip").click(function(){
    $("#koloryinfo").slideToggle("slow");
  });
  $("#itemopis .flip").click(function(){
    $("#opis").slideToggle("slow");
  });
    $("#itemprestige .flip").click(function(){
    $(".prestigeopis").slideToggle("slow");
  });
	});

