/*
 * Usunięcie "mrówek" po kliknięciu w linka
 */
function removeBlur(){
     $("a").unbind('focus').bind('focus',function(){
          if(this.blur)
               this.blur();
     });
}

/*
 * Kliknięcie w przycisk, który ma atrybut rel="ajax"
 */	
var s = '';
var url = '';
var h = '';
var left = '';
var right = '';
var leftc = '';
var rightc = '';
var id = '';
var ax = false;
var c = '#cIn';

function ajax(){
     $('a[rel!=noa]').unbind('click').click(function(){
          if( ($(this).attr('rel')=='noajax') || ($(this).attr('rel')=='prettyPhoto'))
            return true;
          if( typeof(ax) == 'object')
               ax.abort();
          url = $(this).attr('href');
		
          if( url.substring( 0, 7)=='http://' )
          {
               window.open(url).focus()
               return false;
          }

          $('.nb a').each( function(){
               $(this).removeClass('active')
          })
          $('#menuB a').each( function(){
               $(this).removeClass('active')
          })
          

          urlM = url;
          url = url.substring( 0, (url.length-5) );

          if(url.substring(0,5)=='news,')
          {
               id = url.substring(5).split(',').shift();
               url = 'news&id='+id;
          }
          if(url.substring(0,8)=='kariera,')
          {
               urlM = url.substring(0,7)+'.html';
               id = url.substring(8).split(',').shift();
               url = 'kariera&id='+id;
          }
          if(url.substring(0,7)=='uslugi,')
          {
               urlM = url.substring(0,6)+'.html';
               id = url.substring(7).split(',').shift();
               url = 'uslugi&id='+id;
          }
          if(url.substring(0,9)=='services,')
          {
               urlM = url.substring(0,7)+'.html';
               id = url.substring(9).split(',').shift();
               url = 'services&id='+id;
          }
          if(url.substring(0,7)=='career,')
          {
               urlM = url.substring(0,6)+'.html';
               id = url.substring(7).split(',').shift();
               url = 'career&id='+id;
          }
          if(url.substring(0,8)=='kontakt-')
          {
               urlM = url.substring(0,7)+'.html';
               id = url.substring(8).split('-').shift();
               url = 'kontakt&t='+id;
          }
          if(url.substring(0,8)=='contact-')
          {
               urlM = url.substring(0,7)+'.html';
               id = url.substring(8).split('-').shift();
               url = 'contact&t='+id;
          }


          if( $('.nb a[href='+ urlM +']').length == 1 )
          {
               $('a[href='+ urlM +']').addClass('active');
          }

          $('#cLeft').empty().append('<div class="LoadingContent">'+info+'</div>');
          ax = $.ajax({
               url: "content.php",
               data: 's='+url,
               success: function(msg,txt)
               {
                    $('#cIn').empty().html(msg);
                    /*left = leftc = $('#cLeft').height('auto').height();
                    right = rightc = $('#cRight').height('auto').height();
                    if( left < right )
                    {
                         $('#cLeft').animate({
                              height: right + 'px'
                         },100);
                         $('#cRight').animate({
                              height: right + 'px'
                         },100);
                    }else{
                         $('#cLeft').animate({
                              height: left + 'px'
                         },100);
                         $('#cRight').animate({
                              height: left + 'px'
                         },100);
                    }*/
				
                    ajax();
                     $("a[rel^='prettyPhoto']").prettyPhoto({
                        animationSpeed: 'normal', /* fast/slow/normal */
                        padding: 40, /* padding for each side of the picture */
                        opacity: 0.35, /* Value betwee 0 and 1 */
                        showTitle: true, /* true/false */
                        allowresize: true, /* true/false */
                        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
                        theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
                        callback: function(){}
                    });
                    removeBlur();
               }
          });
          return false;
     })
}
/*
 * Dokument załadowany.
 */
$(document).ready( function(){

    $('#down').click(function(e){
        e.preventDefault();
        if($('#down_blok').css('display')=='none'){ //blok rozwijanego menu w pliku opinie_klientow.html
            $('#down').html('... zwiń listę'); //przycisk zwiń listę
            $('#down').removeClass('down').addClass('up'); //podmiana list
        }
        else{
            $('.up').html('Pokaż więcej...'); //przycisk rozwiń listę
            $('.up').removeClass('up').addClass('down');
        }
        $('#down_blok').slideToggle();
    });

    // ajax();
     $("a[rel^='prettyPhoto']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 40, /* padding for each side of the picture */
				opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: true, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
				callback: function(){}
			});


    var searchText = $("#searchForm").val();

	$("#searchForm").focus(function(){
		if( $(this).val()==searchText )
			$(this).val('');
	}).blur(function(){
		if( $(this).val()=='' )
			$(this).val(searchText);
	});
    /*
     left = ($('#cLeft').height('auto').outerHeight({
          margin: true
     })+30);
     right = ($('#cRight').height('auto').height()+30);

     if( left < right )
     {
          $('#cLeft').animate({
               height: right + 'px'
          },50);
          $('#cRight').animate({
               height: right + 'px'
          },50);
     }else{
          $('#cLeft').animate({
               height: left + 'px'
          },50);
          $('#cRight').animate({
               height: left + 'px'
          },50);
     }
    */
     if ( $.trim( window.location.pathname.substring(1) ) !='' )
     {
         $('a[href='+ window.location.pathname.substring(1) +']').addClass('active');
     }else{
        //  $('.nb a:first').addClass('active');
        //  $('#menuB a:first').addClass('active');
     }
});

