	function buy(link)
	{
		$.get( link,
		function( sData )
		{
			if( sData == 'error' )
			{
				alert('Wystapil blad');
				return false;
			}

			$('#basket-count').html(sData);

			return true;

		});
}

function msg( sText )
{
	$('#msg').html( sText ).show("slow");

	setTimeout( function(){
		$('#msg').hide('slow');
	},
	5000);
}

function sumq()
{
	total = 0;
	$('.info-total').each( function() {
		total = total + new Number( $(this).html() );
	})

	$('.delivery input').each(function() {
		if( $(this).is(":checked") )
		{
			total = total + 150;
		}
	});

	$('.basket-total-price').html(total);

}


$(document).ready(function()
{
	$('.buy-link').click(function(){
		
		buy( $(this).attr('href') );
		$(this).effect("transfer", {to: $('#basket-count')}, 1000);
		return false;
	})


	$('#content-more-link').click( function() {
		
		$('#content-more').show('normal');
		$('#content-more-link').remove();
		
	})


	$("input.ab").each(function() {
		if( !$(this).is(":checked") )
		{
			$(this).parent('.bselect').children('.no-ab').toggle();
			$(this).parent('.bselect').children('div.ab').toggle();			
		}
	})

	if( $("input.ab").is(":checked") )
	{
		$(this).parent('.bselect').children('.no-ab').toggle();
		$(this).parent('.bselect').children('div.ab').toggle();
	}



	$("input.ab").click( function() {
//alert('n');
		$(this).parent('.bselect').children('.no-ab').toggle();
		$(this).parent('.bselect').children('div.ab').toggle();
//		$(this).next('.no-ab').hide();
	});

	$(".ab select").each( function() {
		suma = 0;
		s = 0;
			$(this).parent('span').parent('div.ab').children('span').children('select').each( function() {
				suma = suma + new Number( $(this).val() );
			})
			s = new Number($('.no-ab select').val() );

			if( !$("input.ab").is(":checked") )
			{
				suma = s;
			}

			$(this).parents('tr').find('.quantity').html(suma);

			price = new Number( $(this).parents('tr').find('.info-total').attr('title') );
			$(this).parents('tr').find('.info-total').html( price * suma );

			total = 0;
			$('.info-total').each( function() {
				total = total + new Number( $(this).html() );
			})

			$('.delivery').children('input').each(function() {
				if( $(this).is(":checked") )
				{
					total = total + 150;
				}
			});

			$('.basket-total-price').html(total);
	});


	



	$('.delivery input').click( function() {
		sumq();
	});




	$(".ab select").change( function() {
		suma = 0;
			$(this).parent('span').parent('div.ab').children('span').children('select').each( function() {
				suma = suma + new Number( $(this).val() );
			})
			$(this).parents('tr').find('.quantity').html(suma);

			price = new Number( $(this).parents('tr').find('.info-total').attr('title') );
			$(this).parents('tr').find('.info-total').html( price * suma );

			sumq();

		}
	);


	$(".no-ab select").change( function() {
			$(this).parents('tr').find('.quantity').html($(this).val());

			price = new Number( $(this).parents('tr').find('.info-total').attr('title') );
			$(this).parents('tr').find('.info-total').html( price * $(this).val() );

			sumq();
		}
	);







//	$('#form-basket').submit( function() {
//		if( new Number( $('.basket-total-price').html() ) > 0 )
//		{
//			return true;
//		}
//		else
//		{
//			alert('Musisz wybrac ilosc w koszyku');
//			return false;
//		}
//	});



  $("#tabs").tabs();

	$('.lb').lightBox();

	$(".thumb").click(function() {
		$('#big_thumb img').attr('src', imgFldr+'_'+this.id);
		$('#big_thumb a').attr('href', imgFldr+this.id);
	});	

});



$(document).ready(function()
{
	if( !$("input[name='send_address']").is(":checked") )
	{
		$("#address").toggle();
	}

	$("input[name='send_address']").click( function() {

		if( $("#address").css('display') == 'none' )
			$("#address").show();
		else
			$("#address").hide();
	});

	$('.delete').click( function() {
	title = $(this).attr('href');
		jqDialog.confirm("Radera?",
			function() {window.location.href=title},		// callback function for 'YES' button
			function() {}		// callback function for 'NO' button
		);
			return false;
	} )











	$( '.randoms' ).each(
        function()
        {
            //var images = $( this ).find( 'img' );
            var images = new Array();
            var $this = $( this );
            for( var i = 0, l = window.randomimages.length; i < l; i++ )
            {
                var img = new Image();
                img.src = window.randomimages[i];
                img = $( img );
                images[images.length] = img;
                img.css( 'opacity', 0 );
                $this.append( img );

                //preloadImages( window.randomimages[i] );
            }

            setTimeout(
                function()
                {
                    var x = 0;
                    for( var i = 0, l = window.randomimages.length; i < l; i++ )
                    {
                        var img = new Image();
                        img.src = window.randomimages[i];
                        img = $( img );
                        images[images.length] = img;
                        img.css( 'opacity', 0 );
                        $this.append( img );

                        setTimeout( function() { preloadImages( window.randomimages[x] ); x++; }, i * 3000 );
                    }
                },
                1000
            );

            if( images.length < 2 ) return false;

            var fadetimer = false;
            var switchtimer = false;
            var currentimage = false;
            var nextimage = false;

            currentimage = images[0];
            currentimage.css( 'opacity', 1 );

            var duration = 5000;

            nextimage = currentimage.next( 'img' );

            switchtimer = setTimeout( switchImages, duration );

            function switchImages()
            {
                fade();
            }

            function fade()
            {
                if( parseFloat( currentimage.css( 'opacity' ) ) > 0 && parseFloat( nextimage.css( 'opacity' ) ) < 1 )
                {
                    var op1 = parseFloat( currentimage.css( 'opacity' ) ) - 0.1;
                    currentimage.css( 'opacity', op1 );

                    var op2 = parseFloat( nextimage.css( 'opacity' ) ) + 0.1;
                    nextimage.css( 'opacity', op2 );

                    fadetimer = setTimeout( fade, 50 );
                }
                else
                {
                    currentimage = nextimage;
                    nextimage = nextimage.next( 'img' );
                    if( !nextimage.length ) { nextimage = $( images[0] ); }

                    clearTimeout( fadetimer );
                    switchtimer = setTimeout( switchImages, duration );
                }
            }
        }
    );

    function preloadImages()
    {
        var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

    }













});














