/* sIFR inicializace */
var ffont = { src: '/gfx/euromode.swf',ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16] };
/**/
sIFR.delayCSS  = true;
sIFR.activate(ffont);
/**/

var slowEffectTime = 900;
var fastEffectTime = 300;

var formValues = new Array();

function finishUserBox()
{

  // přidat odkaz Zapomenuté heslo
  $('.unknownUser #user .info').append('<p id="linkForgottenPass"><a href="#forgottenPassword" id="linkPassword" class="link lMore" title="Chci zaslat zapomenuté heslo do Klubu Rock Point.">Zapomenuté heslo<'+'/a><'+'/p>');
  // přidat odkaz Přihlásit
  $('.unknownUser #user .info').after('<div id="linkLogInOut" class="cleaned"><p class="links"><a href="#userLogin" id="linkLogin" class="link lLogin" title="Přihlášení uživatele do Klubu Rock Point.">Přihlásit se<'+'/a><'+'/p><'+'/div>');
  // nemá se zobrazit formulář Přihlásit
  if ( !$('#userLogin').hasClass('show') )
  {
    // schovat formulář Přihlásit
    $('#userLogin').hide();
  }
  else
  {
    // schovat odkaz Přihlásit
    $('#linkLogInOut').hide();
  }
  // nemá se zobrazit formulář Zapomenuté heslo
  if ( !$('#forgottenPassword').hasClass('show') )
  {
    // schovat formulář Zapomenuté heslo
    $('#forgottenPassword').hide();
  }
  else
  {
    // schovat odkaz Zapomenuté heslo
    $('#linkForgottenPass').hide();
  }

  // v IE6 zlobí následující box
  if ( $.browser.msie && jQuery.browser.version <= 6 )
  {
    $('#user').after('<div class="ie6Attack"><!-- --><'+'/div>');
  }

  $('#user').addClass('enabledJS');

  // všechny vysvětlivky
  $('#user .explanation').each(
    function()
    {
      // přidat pojem
      $(this).after('<a href="#" class="explain">Více informací</a>');
      // přidat vysvětlivku k pojmu
      $(this).next().append($(this));
      // skrýt vysvětlivku
      $(this).hide();
    }
  );

  finishExplanations();

}

function finishExplains()
{

  // všechny vysvětlivky
  $('.explanation').each(
    function()
    {
      // třída vysvětlivky
      var eClass = $(this).attr('class').replace('explanation ', '');
      // přidat směr vysunutí
      $(this).addClass('downward');
      // skrýt vysvětlivku
      $(this).hide();
      // skrýt titulek vysvětlivky
      $(this).parent().addClass('hidden');
      // přidat vysvětlivku k pojmu
      $('.explain.'+eClass).append($(this));
//       $(this).appendTo($('.explain.'+eClass));
//       $('.explain.'+eClass.' .icon').after($(this));
//       console.log($(this).parent().attr('class'));
      // zrušit vysvětlivku
//       $(this).parent().remove();
    }
  );

  finishExplanations();

}

function finishExplanations()
{

  // pojem nebude klikací
  $('.explain a, a.explain').click(
    function()
    {
      return false;
    }
  );

  // po najetí na pojem
  $('.explain').hover(
    function()
    {
      // zobrazit vysvětlivku
      $(this).parent().css('z-index', '10' );
      $(this).children('.explanation').fadeIn(fastEffectTime);
    },
    function()
    {
      // skrýt vysvětlivku
      $(this).parent().css('z-index', '0' );
      $(this).children('.explanation').fadeOut(100);
    }
  );

}

function hidePhotoInfo()
{
  $('.photogallery #latestPhotosVideos .item .info').hide();
}



  $(function() {
  	$('.lightbox a, a.lightbox').lightBox({fixedNavigation:false, txtImage:'Obrázek', txtOf:'z' });
  });  
  
// hodnoceni ajaxem  
function ajaxRating(wrapperElement)
{
    
  $(wrapperElement).find('a').click(function(){
  
    // http://www.rockpoint.cz/fotografie/?fid=1430&rfid=1430&rgroup=photos&rating=3 //mirit odkazem
    // http://www.rockpoint.cz/include/ajax/rating.php?rfid=1430&rgroup=photos&rating=4 //mirit ajaxem
    var urlAhref = $(this).attr('href');
    var urlFull = urlAhref.split("?");
    var url = 'http://www.rockpoint.cz/include/ajax/rating.php?'+urlFull[1];
    
    // ajax - hlasovani
    $.ajax({
	     type: "GET",   
	     url: url,
	     timeout: 10000,
	     success: function(data)
	     {
          // uzivatel neprihlasen    	     
					if(data=='0')
					{
					   alert('Pro hlasování se musíte přihlásit.');
					}
					// vicenasobne hlasovani
					else if(data=='1')
					{
					   alert('Nelze hlasovat vícekrát.');
					}
					// hlasovani probehlo
					else
					{
            $(wrapperElement).replaceWith(data);
          }
		   },
			 error: function()
			 {
          // presmerovat v pripade chyby ajaxu
          //window.location(urlAhref);
          window.location.href = urlAhref;
  		 }
    }); 
    return false;
  });
  
}  

function log(e)
{
  //return false;
  if(typeof(console)=='object') console.log(e);
  //else alert(e);  
};

function openNewWin(url)
{
  isNewWin = window.open(url);
  return (typeof(isNewWin)=='object') ? true : false;
}

/*******************************************
 *
 *  on DOM ready
 *
 ********************************************/
$(document).ready(function()
{

  // fix eolas
  /*
  var objects = document.getElementsByTagName("object");
  for (var i=0; i<objects.length; i++)
  {
    if( objects[i].className != 'flashPlayerObject' )
      objects[i].outerHTML = objects[i].outerHTML;
  }
  */
  

  $('.photogallery #latestPhotosVideos .photoVideo').hover(
    function()
    {
      $(this).children().children('.info').fadeIn(fastEffectTime);
    },
    function()
    {
      $(this).children().children('.info').fadeOut(slowEffectTime);
    }
  );


  // Ajax Rating
  ajaxRating('.rating');


  jQuery.easing.def = 'easeOutCubic';

  // schovat tlačítka pro řazení výpisů
  $('.printoutOption .button').hide();

  // NOVINKY NA TITULNÍ STRÁNCE
  // zobrazit první novinku, ostatní schovat
//   $('.news:first').addClass('open');
  $('#homepage .news:not(:first)').addClass('close');
  $('#homepage .news:not(:first) .hide').hide();
  // najeti mysi na nadpis novinky
  $('#homepage .news .title a').hover(
    function ()
    {

//       // novinka rozbalená
//       if ( $(this).parent().parent().hasClass('open') )
//       {
//         // sbalit rozbalenou novinku
//         $(this).parent('.title').next().next('.hide').slideUp(slowEffectTime);
//         $(this).parent('.title').parent('.news').removeClass('open');
//       }
//       // novinka sbalená
//       else
//       {
//         // sbalit všechny novinky
//         $('.news').removeClass('open');
//         $('.hide').slideUp(fastEffectTime);
//         // rozbalit požadovanou novinku
//         $(this).parent('.title').next().next('.hide').slideDown(slowEffectTime);
//         $(this).parent('.title').parent('.news').addClass('open');
//       }

      // novinka sbalená
      if ( $(this).parent().parent().hasClass('close') )
      {
        // sbalit všechny novinky
        $('.hide').slideUp(fastEffectTime);
        $('.news').addClass('close');
        // rozbalit sbalenou novinku
        $(this).parent('.title').parent('.news').removeClass('close');
        $(this).parent('.title').next().next('.hide').slideDown(fastEffectTime + 100).queue(
          function() {
            $(this).dequeue();
          }
        );
      }
      // novinka rozbalená
      else
      {
        // sbalit všechny novinky
        $('.hide').slideUp(fastEffectTime);
        $('.news').addClass('close');
      }
      return false;
    },
    function () {
    }
  );

  // klik na text rozbalené novinky
  $('#homepage .news .text').click(
    function ()
    {
      // sbalit novinku
      $(this).parent('.hide').slideUp(slowEffectTime);
      $('.news').addClass('close');
    }
  );


  // ZPRÁVY
  $('#userPrintout th.check').append('<input id="checkAll" name="checkAll" type="checkbox" title="Označit/odznačit všechny zprávy." /><label for="checkAll" class="hidden">Vše</label>');

  if ( $.browser.msie && jQuery.browser.version <= 6 )
  {
    $('#messagesList tr').hover(
      function()
      {
        $(this).addClass('hover');
      },
      function()
      {
        $(this).removeClass('hover');
      }
    );
  }

  $('#checkAll').click(
    function()
    {
      $('#userPrintout td input[type=checkbox]').attr('checked', $(this).attr('checked') );
    }
  );

  // SUBMENU
  // zobrazit první kontinent, ostatní schovat
//   $('.sublevel:not(:first)').addClass('close');
//   $('.sublevel:not(:first) ul').hide();
  // schovat nerozbalené položky
  $('#club #submenu .close .sublevel').hide();

  // ikona pro rozbalení/sbalení položek
  $('#club #submenu .head').append('<a href="#" class="switch"><!-- --></a>');

  // klik ikonu v položce
  $('#club #submenu .switch').click(
    function ()
    {
      // položka není rozbalená
      if ( $(this).parent('.head').parent('li').hasClass('close') )
      {
        $('.sublevel').slideUp(slowEffectTime);
        $('.sublevel').parent('li').addClass('close');
        $(this).parent('.head').next('.sublevel').slideDown(slowEffectTime);
        $(this).parent('.head').parent('li').removeClass('close');
      }
      return false;
    }
  );

  // FORMULÁŘE V UŽIVATELSKÉM BOXU


  // klik na odkaz Přihlásit
  $('#linkLogin').click(
    function ()
    {
      // zobrazit odkaz Zapomenuté heslo
      $('#linkForgottenPass').show();
      // schovat formulář Zapomenuté heslo
      $('#forgottenPassword').hide();
      // zobrazit formulář Přihlásit
      $('#userLogin').show();
      // schovat odkaz Přihlásit
      $('#linkLogInOut').hide();
      return false;
    }
  );
  
  // klik na odkaz Zapomenuté heslo
  $('#linkPassword').click(
    function ()
    {
      // zobrazit odkaz Přihlásit
      $('#linkLogInOut').show();
      // schovat formulář Přihlásit
      $('#userLogin').hide();
      // zobrazit formulář Zapomenuté heslo
      $('#forgottenPassword').show();
      // schovat odkaz Zapomenuté heslo
      $('#linkForgottenPass').hide();
      return false;
    }
  );

//   // PŘIHLÁŠENÍ
//   $('#discussion #mainLogin').append('<p class="hideLogin"><a href="#discussion" class="link lDelete">Skrýt formulář</a></p>');
//
//   if ( !$('#discussion #mainLogin').hasClass('show') )
//   {
//     $('#discussion #mainLogin').hide();
//   }
//   else
//   {
//     $('.unknownUser .lNewPost').hide();
//     $('.unknownUser .lReply').hide();
//   }
//
//   $('.unknownUser .lNewPost').click(
//     function()
//     {
//       $('.unknownUser .lNewPost').hide();
//       $('.unknownUser .lReply').hide();
//       $('.hideLogin .link').attr('href', '#discussion' );
//       $('#discussion #mainLogin').fadeIn(slowEffectTime);
//     }
//   );
//
//   $('.unknownUser .lReply').click(
//     function()
//     {
//       $('.unknownUser .lNewPost').hide();
//       $('.unknownUser .lReply').hide();
//       $('.hideLogin .link').attr('href', '#'+$(this).parent().parent().parent().parent().attr('id') );
//       $('#discussion #mainLogin').fadeIn(slowEffectTime);
//     }
//   );
//
//   $('.unknownUser .hideLogin a').click(
//     function()
//     {
//       if ( $('.hideLogin .link').attr('href' ) == '#discussion' )
//       {
//         $('#discussion #mainLogin').fadeOut(fastEffectTime);
//       }
//       else
//       {
//         $('#discussion #mainLogin').hide();
//       }
//       $('.unknownUser .lNewPost').show();
//       $('.unknownUser .lReply').show();
//     }
//   );
  

  var colors = new Array();
  colors[1] = '#ffffff';
  colors[2] = '#f7923a';
  colors[3] = '#d9d9d9';

  var fonts = new Array();
  fonts[1] = '16px';
  fonts[2] = '14px';
  fonts[3] = '18px';
  fonts[4] = '12px';
  fonts[5] = '24px';

  /* sIFR replace */

  sIFR.replace(ffont,
  {
    selector: '#homepage #facebookUser .sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[4]+'; font-weight: bold; text-transform: uppercase; color: '+colors[1]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; text-transform: uppercase; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[1]+'; }',
      'a:focus { color: '+colors[1]+'; }',
      'a:active { color: '+colors[1]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });

  sIFR.replace(ffont,
  {
    selector: '#user .sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[3]+'; font-weight: bold; text-transform: uppercase; color: '+colors[3]+'; }',
      'a { color: '+colors[3]+'; text-decoration: none; text-transform: uppercase; }',
      'a:link { color: '+colors[3]+'; }',
      'a:visited { color: '+colors[3]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });

  sIFR.replace(ffont,
  {
    selector: '#heading .sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[5]+'; font-weight: bold; text-transform: uppercase; color: '+colors[1]+'; background-color: #272727; }',
       'a { color: '+colors[1]+'; text-decoration: none; }',
       'a:link { color: '+colors[1]+'; }',
       'a:visited { color: '+colors[1]+'; }',
       'a:hover { color: '+colors[2]+'; }',
       'a:focus { color: '+colors[2]+'; }',
       'a:active { color: '+colors[2]+'; }'
      ],
     wmode: 'transparent',
    fitExactly: true
  });

  sIFR.replace(ffont,
  {
    selector: '#newsletter .sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[2]+'; font-weight: bold; color: '+colors[1]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });

//   sIFR.replace(ffont,
//   {
//     selector: '.mainMenu .selected',
//     css:
//       [
//       '.sIFR-root { font-size: '+fonts[3]+'; font-weight: bold; text-transform: uppercase; color: '+colors[2]+'; }',
//       'a { color: '+colors[2]+'; text-decoration: none; }',
//       'a:link { color: '+colors[2]+'; }',
//       'a:visited { color: '+colors[2]+'; }',
//       'a:hover { color: '+colors[2]+'; }',
//       'a:focus { color: '+colors[2]+'; }',
//       'a:active { color: '+colors[2]+'; }'
//       ],
//     wmode: 'transparent',
//     fitExactly: true
//   });

//   sIFR.replace(ffont,
//   {
//     selector: '.boxMenu .selected',
//     css:
//       [
//       '.sIFR-root { font-size: '+fonts[4]+'; font-weight: bold; text-transform: uppercase; color: '+colors[2]+'; }',
//       'a { color: '+colors[2]+'; text-decoration: none; }',
//       'a:link { color: '+colors[2]+'; }',
//       'a:visited { color: '+colors[2]+'; }',
//       'a:hover { color: '+colors[2]+'; }',
//       'a:focus { color: '+colors[2]+'; }',
//       'a:active { color: '+colors[2]+'; }'
//       ],
//     wmode: 'transparent',
//     fitExactly: true
//   });

  sIFR.replace(ffont,
  {
    selector: '.mainTitle .sifr',//, .mainMenu .sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[3]+'; font-weight: bold; text-transform: uppercase; color: '+colors[2]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });

  sIFR.replace(ffont,
  {
    selector: '.boxTitle .sifr',//, .boxMenu .sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[4]+'; font-weight: bold; text-transform: uppercase; color: '+colors[2]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });

  sIFR.replace(ffont,
  {
    selector: '.sifr',
    css:
      [
      '.sIFR-root { font-size: '+fonts[1]+'; font-weight: bold; color: '+colors[1]+'; }',
      'a { color: '+colors[1]+'; text-decoration: none; }',
      'a:link { color: '+colors[1]+'; }',
      'a:visited { color: '+colors[1]+'; }',
      'a:hover { color: '+colors[2]+'; }',
      'a:focus { color: '+colors[2]+'; }',
      'a:active { color: '+colors[2]+'; }'
      ],
    wmode: 'transparent',
    fitExactly: true
  });

  $('#slideArea').after('<span id="slideRight" class="slider"><a class="prev"><!-- --></a></span><span id="slideLeft" class="slider"><a class="next"><!-- --></a></span>');

  $("#slideArea").scrollable({size: 3, speed: 500 }).circular().mousewheel({speed: 50 }).autoscroll({steps: 1, interval: 3000 });


//   $('#club #user').hide();
//
//   $('#mAccount').hover(
//     function(){
//       $('#club #user').fadeIn();
//     },
//     function(){
//       $('#club #user').fadeOut();
//     }
//   );


  $('.printoutOption select').change(
    function()
    {
      $(this).parents('form').submit();
    }
  );

  $('select#message-friends').change(
    function()
    {
      $('input#message-recipient').attr('value', $(this).attr('value') );
      //$(this).parents('form').submit();
    }
  );

// 

  $('#facebookUser .fbIcon a').click(
    function()
    { 
       var href = $(this).attr('href');
       FB.Connect.get_status().waitUntilReady(
         function(status) 
         { 
           if (status == FB.ConnectState.userNotLoggedIn) 
           { 
             window.location.replace(href);
           } else
           if (status == FB.ConnectState.appNotAuthorized) 
           {
             FB.Connect.requireSession();        
           } else
           {
             window.location.replace(href);
           }
         }
       );
       return false;
    }
  );

  /* onfocus events */
  $('#search-string, #main-search-string, #newsletter-email, #section-search-string').focus(
    function()
    {
      var itemID = $(this).attr('id');

      if ( formValues[itemID] == null || $(this).val() == formValues[itemID] )
      {
        formValues[itemID] = $(this).val();
        $(this).val('');
      }
    }
  );

  /* onblur events */
  $('#search-string, #main-search-string, #newsletter-email, #section-search-string').blur(
    function()
    {
      if( $(this).val() == '' )
      {
        $(this).val(formValues[$(this).attr('id')]);
      }
    }
  );

});
