;(function(){

	// banner top
	/*$( '#homeSlider header' ).append( '<div class="contents"></div><div class="navPrevNext"><img width="25" height="25" alt="poprzedni" title="poprzedni" src="/skins/user/shoper_red_1/images/arrLeftGrey1.png"class="prev"/><img width="25" height="25" alt="następny" title="następny" src="/skins/user/shoper_red_1/images/arrRightGrey1.png"class="next"/></div>' );
       	$( '#homeSlider' ).cycle( {
		pager		: '#homeSlider .contents',
		prev		: '#homeSlider .navPrevNext .prev',
		next		: '#homeSlider .navPrevNext .next',
		slideExpr	: '.slides li',
		timeout		: 5000,
		speed		: 1500,
		pause		: 1
	} );*/

	// products slideshow
	$( '#boxProductsOfTheDay header' ).append( '<div class="contents"></div><div class="navPrevNext"><img width="20" height="21" alt="poprzedni" title="poprzedni" src="/skins/user/shoper_red_1/images/arrLeftWhite1.png"class="prev"/><img width="20" height="21" alt="następny" title="następny" src="/skins/user/shoper_red_1/images/arrRightWhite1.png"class="next"/></div>' );
       	$( '#boxProductsOfTheDay' ).cycle( {
		pager		: '#boxProductsOfTheDay .contents',
		prev		: '#boxProductsOfTheDay .navPrevNext .prev',
		next		: '#boxProductsOfTheDay .navPrevNext .next',
		slideExpr	: '.slides li',
		timeout		: 5000,
		speed		: 1500,
		pause		: 1
	} );

	// product voting
	function sendMark(){
		var form = this.form;

		$.get( form.action + this.value, function( data ){
				if ( data == 1 ){
					$( form ).remove();
				}
			} );

		return false;
	}
	$( '.formMark input[type=image]' ).click( sendMark );

	// calculating order cost
	function calculateOrderCost(){
		var totalCost,
		    totalCostContainer = $( '#totalValue' ),
		    /* itemsValue = $( '#itemsValue' ).html(), */
		    itemsValue = $( '#sum' ).val(),
		    shippingCost = $( this ).closest( 'label' ).find( '.shippingCost' ).html();

		totalCost =	parseInt( itemsValue.replace( /[^0-9]*/g, '' ) );
		totalCost +=	parseInt( shippingCost.replace( /[^0-9]*/g, '' ) );
		totalCost =	( '' + totalCost ).replace( /([0-9]{2})$/, ',$1 zł' );

		totalCostContainer.html( totalCost );
	}

	$( '#formShipping input[type=radio]' ).click( calculateOrderCost );

	// shipping and payment
	function selectPayment(){
		setTimeout( function(){$( '#formPayment div:not(.disabled) input' ).eq(0).click();}, 10 );
	}

	$( '#formShipping input[type=radio]' ).click( selectPayment );
})();


