$(function(){
	var $pin = $( '#page-index' ).val();
	$(window).load( function () {
		$( '#main-wrap' ).fadeIn( 500, function(){
			if ( $pin == 'contacts' ){
				AddMap();
			}
			setTimeout( function(){ changeSL(); }, 1000 );
		});
	} );
	$( '.slider-button' ).click( function(){
		if ( $( '#slider' ).attr( 'off' ) != '1' ){
			$( '#slider' ).attr( 'off', 1 );
			var cur = $( '#slider' ).attr( 'num' ),
				th = $( this ).attr( 'rel' );
			$( '#slider' ).attr( 'num', th );
			$( '.slider-button' ).removeClass( 'thisslide' );
			$( this ).addClass( 'thisslide' );
			$( '.slider-content:[rel="'+cur+'"]' ).fadeOut( function(){
				$( '.slider-content:[rel="'+th+'"]' ).fadeIn();
				$( '#slider' ).attr( 'off', 0 );
			} );
			$( '#timeline' ).val( 5 );
		}
	} );
	/*$( '.nav-el' ).click( function(){
		if ( $( '#news-block' ).attr( 'off' ) != '1' ){
			$( '#news-block' ).attr( 'off', 1 );
			var cur = $( '#news-block' ).attr('cur'),
				th = $( this ).attr( 'rel' );
			$( '#news-block' ).attr( 'cur', th );
			$( '.nav-el' ).removeClass( 'thisnews' );
			$( this ).addClass( 'thisnews' );
			$( '.news-el:[rel="'+cur+'"]' ).fadeOut( function(){
				$( '.news-el:[rel="'+th+'"]' ).fadeIn();
				$( '#news-block' ).attr( 'off', 0 );
			} );
		}
	} );*/
	$( '.hoverbob' ).hover( function(){
		$( this ).removeClass( 'hoverbob' ).addClass( 'selebob' );
	}, function (){
		if ( $( this ).attr( 'rel' ) != 'this' )
			$( this ).removeClass( 'selebob' ).addClass( 'hoverbob' );
	});
} );
function changeSL(){
	var tl = $( '#timeline' ),
		cur = $( '#slider' ).attr('num'),
		max = $( '#slider' ).attr('cnt');
	if ( tl.val()*1 == 0 ){
		if ( cur*1+1 <= max*1 ){
			$( '#slider' ).attr( 'num', cur*1+1 );
			$( '.slider-button' ).removeClass( 'thisslide' );
			$( '.slider-button:[rel="'+(cur*1+1)+'"]' ).addClass( 'thisslide' );
			$( '.slider-content:[rel="'+cur+'"]' ).fadeOut( function(){
				$( '.slider-content:[rel="'+(cur*1+1)+'"]' ).fadeIn();
			} );
		} else {
			$( '#slider' ).attr( 'num', 1 );
			$( '.slider-button' ).removeClass( 'thisslide' );
			$( '.slider-button:[rel="1"]' ).addClass( 'thisslide' );
			$( '.slider-content:[rel="'+cur+'"]' ).fadeOut( function(){
				$( '.slider-content:[rel="1"]' ).fadeIn();
			} );
		}
		tl.val( 5 );
		setTimeout( function(){ changeSL(); }, 1000 );
	} else {
		tl.val( tl.val()-1 );
		setTimeout( function(){ changeSL(); }, 1000 );
	}
}
