var resizeTimer = null;
var resizeInterval = 444;

$( window ).resize( function() {
	if( resizeTimer != null ) {
        clearTimeout( resizeTimer );
        resizeTimer = null;
    }
    resizeTimer = setTimeout( resizeHandler, resizeInterval );
} );

// RESIZE HANDLER

function resizeHandler() {
	// Set new images for new dimention
	if( document.documentElement.clientWidth > 1440 ) {
		$( 'div.content' ).filter( '.fixpr850' ).addClass( 'fixpr1020' );
		$( 'div.content' ).filter( '.fixw850' ).addClass( 'fixw1020' );
		bg_imgs.each( function() {
			this.src = this.src.replace( '850', '1020' );
		} );

		// For MSIE
		$( '#slides' ).css( { left: 0 } )
	} else {
		$( 'div.content' ).filter( '.fixpr850' ).removeClass( 'fixpr1020' );
		$( 'div.content' ).filter( '.fixw850' ).removeClass( 'fixw1020' );
		bg_imgs.each( function() {
			this.src = this.src.replace( '1020', '850' );
		} );
	}
}

// DOCUMENT READY

$( document ).ready( function() {
	// START SCROLL HANDLER
	$( window ).scroll( function() {
		$( '#slides' ).css( { left: - $( this ).scrollLeft() + 'px' } )
	} )

	// START RESIZE HANDLER
	bg_imgs = $( '#slides' ).children();
	resizeHandler();	
} );