$(document).ready(function(){
	//alert( 'dd' );
	
	//Сохраняем дату посещения (с задержкой на час)
	if( typeof server_timespamp != "undefined" && server_timespamp > 0 ) {
		var prev_visit = $.cookie( "prev_visit" );
		if( !parseInt( prev_visit ) || ( server_timespamp - prev_visit ) > 3600 ) {
			$.cookie( "prev_visit" , server_timespamp );
			}
		}
			
	$works_container = $( "div.works_container" );
	if( $works_container.length > 0 ) {
		$works_list = $( "div.works_list" , $works_container ); 
		
		$works = $( "a.work" , $works_list );
		$works.live( "click" , function() {
			$( "a.active" , $works_list ).removeClass( "active" );
			$(this).addClass( "active" ); 
			
			location.hash = this.id;
			$works_image_container = $( ".works_image_container" , $works_container );
			$( "img" , $works_image_container ).fadeTo( "fast" , 0.3 );
			$works_container.load( "/klarnetCMSlocal/modules/contest_works/reload.php?work_id=" + this.id );
			return false;
			} );
		
		
		/*$works = $( "img.work" , $works_list );
		$works.live( "mouseover" , function() {
			//alert( 'ddd' );
			$(this).fadeTo( "fast" , 1 );
			} );
		$works.live( "mouseout" , function() {
			$(this).fadeTo( "fast" , 0.3 );
			} );	
		$works.live( "click" , function() {
			location.hash = this.id;
			$works_image_container = $( ".works_image_container" , $works_container );
			$( "img" , $works_image_container ).fadeTo( "fast" , 0.3 );
			$works_container.load( "/klarnetCMSlocal/modules/contest_works/reload.php?work_id=" + this.id );
			return false;
			} );*/
			
		//alert( location.hash );
		
		if( parseInt( location.hash.substr( 1 ) ) > 0 ) {
			$( "img#" + location.hash.substr( 1 ) , $works_list ).click();
			//alert( location.hash );
			}
		}
	});
