var fade_running = false;
var new_img_save = false;
var timer = false;

$(document).ready(function()
{
  if(!$.browser.msie)
  {
    $('.imgr').hover(
      function() { $(this).children('span').fadeIn(500); },
      function() { $(this).children('span').fadeOut(500); }
    );

    $('#mainmenu.home a').not('.active').hover(
      function() { $(this).children('span').fadeIn(500); },
      function() { $(this).children('span').fadeOut(500); }
    );
  }

  $('#scroll_block-one').jScrollPane();
  $('#scroll_block-two').jScrollPane();
  $('#scroll_block-three').jScrollPane();
  $('.scroller').jScrollPane();

  $('#mainmenu.home a').not('#mainmenu ul ul a').click( function() { $('#mainmenu ul ul').slideUp(500); $(this).parent().children('ul').slideToggle(500); });

  $('div.right_news').not('.first').hide();

  $('.button_more').click(function()
  {
    var id = '#' + $(this).attr('rel');
    $('div.right_news').fadeOut(800);
    $('.button_more').removeClass('active');
    $(this).addClass('active');
    $(id).delay(900).fadeIn(800);
  });

  $('.paging').click(function()
  {
    var id = '#' + $(this).attr('rel');

    $('.paging').removeClass('active');
    $(this).addClass('active');
    $('.listpage').fadeOut(800);
    $(id).delay(900).fadeIn(800);
  });

  var preload_images = new Array(
    '/images/content/fader/home_old.jpg',
    '/images/content/fader/home_old.jpg',
    '/images/content/fader/bft06.jpg',
    '/images/content/fader/bft08.jpg',
    '/images/content/fader/bft09.jpg',
    '/images/content/fader/martin_hrca.jpg',
    '/images/content/fader/lenka_srsnova.jpg',
    '/images/content/fader/maria_stranekova.jpg',
    '/images/content/fader/marek_kopanica.jpg',
    '/images/content/fader/michaela_bednarova.jpg',
    '/images/content/fader/hana_prevratilova.jpg',
    '/images/content/fader/boris_hanecka.jpg',
    '/images/content/fader/marcel_holubec.jpg',
    '/images/content/fader/kia_design_fond.jpg',
    '/images/content/inspiracie/alexander_mcqueen.jpg',
    '/images/content/inspiracie/antwerp_fashion.jpg',
    '/images/content/inspiracie/balenciaga.jpg',
    '/images/content/inspiracie/designby.jpg',
    '/images/content/inspiracie/maison_martin_margiela.jpg',
    '/images/content/inspiracie/nineteenth_century_fashions.jpg',
    '/images/content/inspiracie/slovenske_centrum_designu.jpg',
    '/images/content/inspiracie/style.jpg',
    '/images/content/inspiracie/vogue.jpg',
    '/images/content/porota/karol_weisslechner.jpg',
    '/images/content/porota/milota_havrankova.jpg',
    '/images/content/porota/boris_hanecka.jpg',
    '/images/content/porota/dana_lapsanska.jpg',
    '/images/content/porota/eva_blahutova.jpg',
    '/images/content/porota/katarina_hubova.jpg',
    '/images/content/porota/libena_rochova.jpg',
    '/images/content/porota/milan_corba.jpg',
    '/images/content/porota/karol_pichler.jpg',
    '/images/content/porota/andrej_taraba.jpg',
    '/images/content/porota/lukac_kimlicka.jpg',
    '/images/content/porota/milan_machajdik.jpg',
    '/images/content/porota/zuzana_macasova.jpg',
    '/images/content/nas_tim/nasta_mayerova.jpg',
    '/images/content/nas_tim/silvia_gazdikova.jpg',
    '/images/content/nas_tim/hana_prevratilova.jpg',
    '/images/content/nas_tim/marek_kopanica.jpg',
    '/images/content/nas_tim/maria_stranekova.jpg',
    '/images/content/nas_tim/lenka_srsnova.jpg',
    '/images/content/nas_tim/martin_hrca.jpg',
    '/images/content/nas_tim/zuzana_vary.jpg',
    '/images/content/nas_tim/kristof.jpg',
    '/images/content/nas_tim/martin_michalica.jpg'
  );

  for(var i=0; i<preload_images.length; i++)
  {
    tmp = new Image(600, 406);
    tmp.src = preload_images[i];
  }

  $('a.fashion_talent_06').mouseenter( function() { FadeImage(700, '/images/content/fader/bft06.jpg', 'Brillance Fashion Talent\'06', true); });
  $('a.fashion_talent_10').mouseenter( function() { FadeImage(700, '/images/content/fader/home.jpg', 'Brillance Fashion Talent\'10', false); });
  $('a.fashion_talent_08').mouseenter( function() { FadeImage(700, '/images/content/fader/bft08.jpg', 'Brillance Fashion Talent\'08', true); });
  $('a.fashion_talent_09').mouseenter( function() { FadeImage(700, '/images/content/fader/bft09.jpg', 'Brillance Fashion Talent\'09', true); });

  $('a.martin_hrca').mouseenter( function() { FadeImage(700, '/images/content/fader/martin_hrca.jpg', 'Martin Hrča', true); });
  $('a.lenka_srsnova').mouseenter( function() { FadeImage(700, '/images/content/fader/lenka_srsnova.jpg', 'Lenka Sršnová', true); });
  $('a.maria_stranekova').mouseenter( function() { FadeImage(700, '/images/content/fader/maria_stranekova.jpg', 'Mária Štraneková', true); });
  $('a.marek_kopanica').mouseenter( function() { FadeImage(700, '/images/content/fader/marek_kopanica.jpg', 'Marek Kopanica', true); });
  $('a.michaela_bednarova').mouseenter( function() { FadeImage(700, '/images/content/fader/michaela_bednarova.jpg', 'Michaela Bednárová', true); });
  $('a.hana_prevratilova').mouseenter( function() { FadeImage(700, '/images/content/fader/hana_prevratilova.jpg', 'Hana Převrátilová', true); });
  $('a.boris_hanecka').mouseenter( function() { FadeImage(700, '/images/content/fader/boris_hanecka.jpg', 'Boris Hanečka', true); });
  $('a.marcel_holubec').mouseenter( function() { FadeImage(700, '/images/content/fader/marcel_holubec.jpg', 'Marcel W. Holubec', true); });

  $('a.alexander_mcqueen').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/alexander_mcqueen.jpg', '', false); });
  $('a.antwerp_fashion').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/antwerp_fashion.jpg', '', false); });
  $('a.balenciaga').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/balenciaga.jpg', '', false); });
  $('a.designby').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/designby.jpg', '', false); });
  $('a.maison_martin_margiela').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/maison_martin_margiela.jpg', '', false); });
  $('a.nineteenth_century_fashions').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/nineteenth_century_fashions.jpg', '', false); });
  $('a.slovenske_centrum_designu').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/slovenske_centrum_designu.jpg', '', false); });
  $('a.style').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/style.jpg', '', false); });
  $('a.vogue').mouseenter( function() { FadeImage(900, '/images/content/inspiracie/vogue.jpg', '', false); });

  $('a#karol_weisslechner').mouseenter( function() { FadeImage(900, '/images/content/porota/karol_weisslechner.jpg', '', false); });
  $('a#milota_havrankova').mouseenter( function() { FadeImage(900, '/images/content/porota/milota_havrankova.jpg', '', false); });
  $('a#boris_hanecka').mouseenter( function() { FadeImage(900, '/images/content/porota/boris_hanecka.jpg', '', false); });
  $('a#dana_lapsanska').mouseenter( function() { FadeImage(900, '/images/content/porota/dana_lapsanska.jpg', '', false); });
  $('a#eva_blahutova').mouseenter( function() { FadeImage(900, '/images/content/porota/eva_blahutova.jpg', '', false); });
  $('a#katarina_hubova').mouseenter( function() { FadeImage(900, '/images/content/porota/katarina_hubova.jpg', '', false); });
  $('a#libena_rochova').mouseenter( function() { FadeImage(900, '/images/content/porota/libena_rochova.jpg', '', false); });
  $('a#milan_corba').mouseenter( function() { FadeImage(900, '/images/content/porota/milan_corba.jpg', '', false); });
  $('a#karol_pichler').mouseenter( function() { FadeImage(900, '/images/content/porota/karol_pichler.jpg', '', false); });
  $('a#andrej_taraba').mouseenter( function() { FadeImage(900, '/images/content/porota/andrej_taraba.jpg', '', false); });
  $('a#lukac_kimlicka').mouseenter( function() { FadeImage(900, '/images/content/porota/lukac_kimlicka.jpg', '', false); });
  $('a#milan_machajdik').mouseenter( function() { FadeImage(900, '/images/content/porota/milan_machajdik.jpg', '', false); });
  $('a#zuzana_macasova').mouseenter( function() { FadeImage(900, '/images/content/porota/zuzana_macasova.jpg', '', false); });
  $('a#nasta_mayerova').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/nasta_mayerova.jpg', '', false); });
  $('a#silvia_gazdikova').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/silvia_gazdikova.jpg', '', false); });
  $('a#hana_prevratilova').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/hana_prevratilova.jpg', '', false); });
  $('a#marek_kopanica').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/marek_kopanica.jpg', '', false); });
  $('a#maria_stranekova').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/maria_stranekova.jpg', '', false); });
  $('a#lenka_srsnova').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/lenka_srsnova.jpg', '', false); });
  $('a#martin_hrca').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/martin_hrca.jpg', '', false); });
  $('a#zuzana_vary').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/zuzana_vary.jpg', '', false); });
  $('a#kristof').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/kristof.jpg', '', false); });
  $('a#martin_michalica').mouseenter( function() { FadeImage(900, '/images/content/nas_tim/martin_michalica.jpg', '', false); });

  $('a.intro_03').click(function() { FadeImage(900, '/images/content/fader/kia_design_fond.jpg', '', true); });

  if($('#image_fader.intro').length>0) RunIntro(0);
  $('a.fashion_talent_10').mouseleave( function() { RunIntro(0); });

  $('.fancybox').fancybox({
	  'titlePosition' : 'over',
    'padding' : 0
	});

  if($('#video_player').length>0)
  {
    swfobject.embedSWF('/flash/flv_player/player.swf', 'video_player', '600', '404', '9.0.0', false, { config: '/flash/flv_player/config.xml', autostart: true }, { base: '.', bgcolor: '#000000', allowfullscreen: 'true' });
  }

  if($('#slideshow_plugin').length>0)
  {
    swfobject.embedSWF('/flash/slideshow/slideshowpro.swf', 'slideshow_plugin', '910', '100%', '9.0.0', false, { paramXMLPath: 'params.xml' }, { base: '.', bgcolor: '#191919', wmode: 'opaque', allowfullscreen: 'true' });
  }

  $('#porota_box a').hover(
    function()
    {
      if($(this).attr('className')=='cv')
      {
        $('#show_cv').attr('rel', $(this).attr('rel'));
        $('#show_cv').fadeIn('slow');
      }
      else $('#show_cv').fadeOut('slow');
    },
    function() { ; }
  );

  $('#show_cv').click(
    function()
    {
      var box_id = $(this).attr('rel');
      $('#porota_box').fadeOut('slow', function() { $('#'+box_id).fadeIn('slow'); $('#go_back').fadeIn('slow'); });
    }
  );

  $('#go_back').click(
    function()
    {
      var box_id = $('#show_cv').attr('rel');

      $('#go_back').fadeOut('slow');
      $('#'+box_id).fadeOut('slow', function() { $('#porota_box').fadeIn('slow'); });
    }
  );

  $('.iframe').fancybox({'width': 800, 'height': 400, 'modal': true});
  //$('.iframe').fancybox();
});

function flashPutHref(href) { location.href = href; }

function FadeImage(timeout, new_img, title, cancel)
{
  if(cancel) clearTimeout(timer);

  if(!fade_running)
  {
    $('#video_player').hide();

    var fader = $('#image_fader');
    var fader_content = $('#image_fader_content');
    var css_img = 'url(' + new_img + ')';

    if(fader_content.is(':visible'))
    {
      if(fader_content.css('background-image').indexOf(new_img)==-1)
      {
        fader.css('background-image', css_img);
        fader.attr('title', title);
        fader_content.fadeOut(timeout, function() { fade_running = false; if(new_img_save!=false) { FadeImage(timeout_save, new_img_save, title_save, true); new_img_save = false; } } );
        fade_running = true;
      }
    }
    else
    {
      if(fader.css('background-image').indexOf(new_img)==-1)
      {
        fader_content.css('background-image', css_img);
        fader.attr('title', title);
        fader_content.fadeIn(timeout, function() { fade_running = false; if(new_img_save!=false) { FadeImage(timeout_save, new_img_save, title_save, true); new_img_save = false; } } );
        fade_running = true;
      }
    }
  }
  else { new_img_save = new_img; title_save = title; timeout_save = timeout; }
}

function RunIntro(i)
{
  if(i==0) { var img = '/images/content/fader/default.jpg'; i = 1; }
  else if(i==1) { var img = '/images/content/fader/home_old.jpg'; i = 0; }
  
  //var img = '/images/content/fader/home_old.jpg';

  FadeImage(2000, img, 'Foto Ján Horák, modely Martin Hrča, baletky SND Francesca Dell\' Aria, Miki Iwafuchi', false);

  timer = setTimeout('RunIntro(' + i + ')', 3100);
}

function OpenShopForm(product_id)
{
  $.fancybox({
  	'padding' : 0,
  	'href' : '/galeria-obchod/form/?mail_id=' + product_id ,
  	'transitionIn' : 'elastic',
  	'transitionOut' : 'elastic',
		'type' : 'iframe',
		'width' : 800,
		'height' : 550
  });
}
