var old = 0;
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var access = true;

FLIR.init();
FLIR.auto(['h3']);

$(document).ready(function(){
	
	$( "#opcjaTxt" ).change( function( )
	{
		var id = $(this).val( );
		var opcja = document.getElementById( "opcjaTxt" ).options[id].text;
		opcja = opcja.substr( 0, opcja.indexOf( "z" ) );
		
		$( "#kaska" ).html( opcja );
	});
						
	$( "#partyLink" ).mouseover( function( )
	{
		$( "#partyTab" ).show( );
		$( "#vis" ).hide( );	
	});
	
	$( "#artLink" ).mouseover( function( )
	{
		$( "#artTab" ).show( );
		$( "#vis" ).hide( );	
	});
	
	$( ".tab" ).mouseover( function( )
     {
          $( this ).show( );
          $( "#vis" ).hide( );
     });
	
	$( ".tab" ).mouseout( function( )
	{
		$( this ).hide( );
		$( "#vis" ).show( );	
	});
	
	$( "#navi a" ).mouseover( function( )
	{
		if( $( this ).attr( "id" ) == undefined )
		{
			$( "#tabs .tab" ).hide( );
			$( "#vis" ).show( );
		}		
	});
	
	$('#ASfotos a').lightBox({
								fixedNavigation:true,
								imageLoading: 'res/images/lightbox-ico-loading.gif',
								imageBtnClose: 'res/images/lightbox-btn-close.gif',
								imageBtnPrev: 'res/images/lightbox-btn-prev.gif',
								imageBtnNext: 'res/images/lightbox-btn-next.gif',
								txtImage: 'Zdjecie',
								txtOf: 'z'
							});
	$('#mainFoto').lightBox({
								fixedNavigation:true,
								imageLoading: 'res/images/lightbox-ico-loading.gif',
								imageBtnClose: 'res/images/lightbox-btn-close.gif',
								imageBtnPrev: 'res/images/lightbox-btn-prev.gif',
								imageBtnNext: 'res/images/lightbox-btn-next.gif'
							});
							
	$( "#gallery #fotos img" ).click( function( ){
		var href = $( this ).attr( "src" ); 
		$( "#mainFoto" ).attr( "href", href.substr( 0, href.length-2 ) + "org" );
		
		$( "#mainFoto img" ).attr( "src", 'res/images/lightbox-ico-loading.gif' ).attr( "width", 32 ).attr( "height", 32 );
		size( );
		
		var newSize = $( this ).attr( "rel" );
		newSize = newSize.split( "x" );
		
		img = new Image( );
		img.src = "http://www.strefaaktywnych.pl/" + href.substr( 0, href.length-2 ) + "big";
		img.onload = function ( ) {
			$( "#mainFoto img" ).attr( "src", href.substr( 0, href.length-2 ) + "big" ).attr( "width", newSize[0] ).attr( "height", newSize[1] );
			size();
		}

		var desc = $( this ).attr( "title" );
		
		if( desc != undefined )
			$( "#desc" ).text( desc );
		else
			$( "#desc" ).text( "" );
			
		 $( "#selected").removeAttr( "id" );
    	$( this ).parent( ).attr( "id", "selected" );
    	
    	size();
    	return false;
	} );
	
	$( "#gallery #fotos a" ).click( function( ){
		return false;
	} );
	
	$( "#nxt" ).click( function(){
		$( "#selected" ).next( ).find("img").click();
		return false;
	});
	
	$( "#prv" ).click( function(){
		$( "#selected" ).prev( ).find("img").click();
		return false;
	});
	
	$( "#extraFoto" ).click( function( ){
		var prv = $( this ).parent( ).prev( ).find( "input" ).val( );

		if( prv !== "" && prv !== null )
		{
			$(this).parent( ).before( "<p><label for=\"foto\">zdjęcie:</label><input name=\"foto[]\" id=\"foto\" type=\"file\" /><br style=\"clear: both;\" /><label for=\"z\">opis zdjęcia:</label><textarea name=\"fdesc[]\" id=\"z\" cols=\"20\" rows=\"3\"></textarea></p>" );
			size( );
		}
		
		return false;
	} );


    $( "#all" ).change( function( ){
            if( $( this ).attr( "checked" ) )
                $( "input[@type=checkbox]" ).attr( "checked", true );
            else
                $( "input[@type=checkbox]" ).removeAttr( "checked" );
        } );

    $( "#t_content tr" ).hover( function(){
                                            $( this ).addClass( "un" );
                                },
                                function( ){
                                            $( this ).removeClass( "un" );
                                });

    $( "#adresat" ).autocomplete( "poczta/users",
                                  { minChars:2,
                                    matchSubset:1,
                                    matchContains:1,
                                    cacheLength:10,
                                    selectOnly:1 } );

});

function size( )
{
	if( $("#left").height( ) > $("#right").height( ) )
	{		
		if( IE6 )
			$("#right").height( $("#left").height( ) + 39 );
		else
			$("#right").height( $("#left").height( ) );
	}
	else
	{
		if( IE6 )
			$("#left").height( $("#right").height( ) );
		else
			$("#left").height( $("#right").height( ) );
	}
}

size( );

$( document ).load( function( ){
    size( );
});
