if( pos == undefined )
	var pos = -50;

var note_positions = [];
	note_positions[ 1 ] = -40;
	note_positions[ 2 ] = -30;
	note_positions[ 3 ] = -20;
	note_positions[ 4 ] = -10;
	note_positions[ 5 ] = 0;

$( document ).ready( function( ){
	$( "div.stars a" ).mouseover(function(){
		var note = new String( $( this ).attr( "class" ) );
		note = note.substr( 1, 1 );

		$( this ).parent( ).removeAttr( "class" ).addClass( "stars" );
		$(this).parent( ).css( "background-position", "0px "+ note_positions[ note ] +"px" );
	});

	$( "div.stars a" ).mouseout(function(){
		$(this).parent( ).css( "background-position", "0px "+ pos +"px" );
	} );

	 $(this).parent( ).css( "background-position", "0px "+ pos +"px" );

	 $( "div.stars a" ).click( function( ){
		 var note = new String( $( this ).attr( "class" ) );
		 note = note.substr( 1 );
		 $( this ).parent( ).children( "input" ).val( note );
		 pos = note_positions[ note ];

		 return false;
	 } );


	$("select").sexyCombo();
	$("#producer_info_more").hide();
	$("#producer_info_show").click(function() {
		$("#producer_info_more").slideToggle("slow");
		return false;
	});

	$( "form .changeDeliveryPrice" ).change( function( ){

		$.getJSON( "basket/getDeliveryPrice/" + $( "#type" ).val( ) + "/" + $( "#delivery" ).val( ),
				 function( json ){
					 $( "#delivery_price strong" ).html( json.delivery_price + " zł" );
					 $( "#price_zl" ).html( json.price_zl );
					 $( "#price_gr" ).html( json.price_gr );

					 get_discount( );
				 })
	} );

	$( "#do_kasy" ).hide( );
	$( "#submit_form" ).click( function( ){
		$( "#do_kasy" ).click( );

		return false;
	} );

	$( "#add_opinion" ).hide( );

	$( "#submit_comment" ).click( function( ){
		$( "#add_opinion" ).slideToggle( );

		return false;
	} );

	$("a.fancy").fancybox({
                            'zoomSpeedIn': 300,
                            'zoomSpeedOut': 300,
                            'overlayShow': false
    });

    $("a.iframe").fancybox({
                            'zoomSpeedIn': 300,
                            'zoomSpeedOut': 300,
                            'overlayShow': false,
					   'frameWidth': 580,
					   'frameHeight':360
    });

	$( ".producer_info span" ).hide( );
    $( "a#producer_info_show" ).click( function( ){

	    $( ".producer_info span" ).slideToggle( );

	    return false;
    } );

    $(".iframeask").fancybox({
                            'zoomSpeedIn': 300,
                            'zoomSpeedOut': 300,
                            'overlayShow': false,
					   'frameWidth': 770,
					   'frameHeight':240
    });

    $(".iframeask2").fancybox({
                            'zoomSpeedIn': 300,
                            'zoomSpeedOut': 300,
                            'overlayShow': false,
					   'frameWidth': 770,
					   'frameHeight':220
    });

    $( "#ask" ).attr( "href", $( "#ask" ).attr( "href" ) + "/fancy" );

    $( "#search_keyword" ).autocomplete( "product/names" );

    $( "#discount" ).keyup( function( ){
		if( $( this ).val( ).length >= 8 )
		{
			get_discount(  );
		}
		else
			$( "#discount_desc" ).html( "Podany kod zniżki jest niekompletny." );
    } );

    function get_discount(  )
    {
		$( "#discount_desc" ).html( "" );
		$.getJSON( "basket/getDiscount/" + $( "#discount" ).val( ),
		 function( json ){
			 $( "#discount_li" ).show( );
			 $( "#discount_li strong" ).html( json.discount + "%" );

			 var d_price = parseFloat( $.trim( $( "#delivery_price strong" ).html( ).replace( ",", "." ) ) );
			 var price = json.price;
			 price *= ( 1 - json.discount / 100 );
			 price = Math.round( ( price + d_price ) * 100 ) / 100;

			 price = new String( price );
			 price = price.split( "." );

			 if( price[ 1 ].length == 1 )
				 price[ 1 ] += "0";

			 $( "#price_zl" ).html( price[ 0 ] );
			 $( "#price_gr" ).html( price[ 1 ] );
		 });
    }

    if( $( "#discount" ).val( ) )
	    get_discount( );
});