/*
*       Site skripty
*
*/

var speed = 200;
var slider;
var sliderTimeout;
var table_popup = false;


function fadeIn(_this, delay,callbk,out) {
    for (i = 1; i <= 100; i++) {
      (function(j) {
            setTimeout(function() {  
                  if (out==true) j=100-j;
                  _this.style.opacity = j/100;
                  _this.style.MozOpacity = j/100;
                  _this.style.KhtmlOpacity = j/100;
                  _this.style.zoom = 1; // for ie, set haslayout
                  _this.style.display="block"; 
                   if (j==100&&callbk!=undefined) {callbk.call(_this);}
                   else if (out==true&&callbk!=undefined&&j==0) {callbk.call(_this);}
                  _this.style.filter = "alpha(opacity=" + j + ");";},j*delay/100);
                 
        })(i);     
    }
};


function loadTopimage()
{
   var img = $('.content-theme .theme:first').css('z-index', '10').clone(); 

  img.css('display','none').appendTo('.content-theme')
    .load('/slide/ajax.aspx?r='+Math.random()+' .cmsGalleryPhoto a img', function() 
    {
      
      setTimeout(function() { fadeIn(img[0], 1000,function () {  $('div.content-theme .theme:first').remove(); }) }, 2000)
      //fadeIn(this, 600,function () {  $('div.content-theme .theme:first').remove(); })
      //$(this).fadeIn('slow', function () {  $('div.content-theme .theme:first').remove(); });
    } ); 
    
  clearTimeout(sliderTimeout);
  sliderTimeout = setTimeout(loadTopimage, 10000);
}

function slideTeam()
{
   var img = $('.slide-team .theme:first').css('z-index', '10').clone(); 

   if (img)
   {
      img.css('display','none').appendTo('.slide-team')
      .load('/slide-firemni/ajax.aspx?r='+Math.random()+' .cmsGalleryPhoto a img', function() 
      {
        
        setTimeout(function() { fadeIn(img[0], 1000,function () {  $('.slide-team .theme:first').remove(); }) }, 2000)
      } ); 
      
      setTimeout(slideTeam, 8000);
  }
}

function slideScm()
{
   var img = $('.slide-scm .theme:first').css('z-index', '10').clone(); 

   if (img)
   {
      img.css('display','none').appendTo('.slide-scm')
      .load('/slide-yachtklub/ajax.aspx?r='+Math.random()+' .cmsGalleryPhoto a img', function() 
      {
        
        setTimeout(function() { fadeIn(img[0], 1000,function () {  $('.slide-scm .theme:first').remove(); }) }, 2000)
      } ); 
      
      setTimeout(slideScm, 8000);
  }
}

function slideCharter()
{
   var img = $('.slide-charter .theme:first').css('z-index', '10').clone(); 

   if (img)
   {
      img.css('display','none').appendTo('.slide-charter')
      .load('/slide-charter/ajax.aspx?r='+Math.random()+' .cmsGalleryPhoto a img', function() 
      {
        
        setTimeout(function() { fadeIn(img[0], 1000,function () {  $('.slide-charter .theme:first').remove(); }) }, 2000)
      } ); 
      
      setTimeout(slideCharter, 8000);
  }
}



function showPopup()
{
  var index = $(this).parent().find('li').index(this);
  $(this).prev('li').fadeIn(speed + index*150, showPopup);
}

function hidePopup()
{
  $(this).next('li').fadeOut(speed, hidePopup);
}




$(document).ready(
  function adminDocumentLoad()
  {
    /*/ corners
    DD_roundies.addRule('.rounded', '5px', true);
    DD_roundies.addRule('.rounded-top', '5px 5px 0 0', true);
    DD_roundies.addRule('.rounded-topleft', '5px 0 0 0', true);
    DD_roundies.addRule('.rounded-topright', '0 5px 0 0', true);
    DD_roundies.addRule('.rounded-bottomleft', '0 0 5px 0', true);
    DD_roundies.addRule('.rounded-bottomright', '0 0 0 5px', true); */
    
    //loadTopimage();
    if ($('.content-theme .theme').length!=0)
      sliderTimeout = setTimeout(loadTopimage, 10000);
      
    if ($('.slide-scm .theme').length!=0)
      setTimeout(slideScm, 5000);
      
    if ($('.slide-team .theme').length!=0)
      setTimeout(slideTeam, 5000);  
      
    if ($('.slide-charter .theme').length!=0)
      setTimeout(slideCharter, 5000);   
    
    /*$('.popup-menu-content').hoverIntent(
      {
      timeout: 600,
      over: function () 
      {
        var ul = $(this).find('ul');
        ul.hide().css('height','auto');
        var h = ul.height()+'px';
        ul.css('height','0px').show();
        
        ul.animate( { height: h } ,500 );
      } , 
      out: function () 
      { 
        $(this).find('ul').animate( { height: '0px' } ,500 );
      }});*/
      
      /*$('.popup-table-plachetky .popup-menu-content').hoverIntent(
      {
      timeout: 600,
      over: function () 
      {
        var table = $('.popup-table-plachetky');
        $(table).css('margin-top','0px');
        $(table).css('height','473px');
        
        var ul = $(this).find('ul');
        ul.hide().css('height','auto');
        var h = ul.height()+'px';
        ul.css('height','0px').show();
        
        
        ul.animate( { height: h } ,500  );
      } , 
      out: function () 
      {
        
        
        // timeout musi byt vetsi nez open aby se neprepsalo table_popup        
        $(this).find('ul').animate( { height: '0px' } ,900, function() 
          { 
            //if (!table_popup)
            if ($('.popup-table-plachetky ul[clientHeight!=0]').size()==0)
            {
              var table = $('.popup-table-plachetky');
              $(table).css('margin-top','430px'); 
              $(table).css('height','43px'); 
            }
          } );
        
      }}); */
      
      // animace náhledu produktu - pravý
      $('.right-style li.popup-product').hoverIntent(
      {
      timeout: 500,
      over: function () 
      {
        $(this).children('div:first').css('z-index','50');
        $(this).children('div:first').css('overflow','hidden');
        $(this).children('div:first').css('height','0px');
        //$(this).children('div:first').css('margin-top','5px');
        $(this).children('div:first').animate({width:'toggle',height: '365px'},600, function () {$(this).css('z-index','5');} );
      } , 
      out: function () 
      {
        $(this).children('div:first').css('z-index','5');   
        //$(this).children('div:first').hide(500);    
        $(this).children('div:first').animate({width:'toggle',height: '0px'},300);   
      }});
      
      // animace náhledu produktu - levý
      $('.left-style li.popup-product').hoverIntent(
      {
      timeout: 500,
      over: function () 
      {
        $(this).children('div:first').css('z-index','50');
        $(this).children('div:first').css('overflow','hidden');
        $(this).children('div:first').css('height','0px');
        //$(this).children('div:first').css('margin-top','5px');
        $(this).children('div:first').css('margin-left','-15px');
        $(this).children('div:first').animate({width:'toggle',height: '365px',  marginLeft: '-460px'},600, function () {$(this).css('z-index','5');});
      } , 
      out: function () 
      {
        $(this).children('div:first').css('z-index','5');   
        //$(this).children('div:first').hide(500);    
        $(this).children('div:first').animate({width:'toggle',height: '0px',  marginLeft: '-15px'},300);    
      }});
      
      // hlavní menu
      $('.pop-menu li.polozka').hoverIntent(
      {
      timeout: 500,
      over: function () 
      {
        $(this).children('ul').slideDown();
      } , 
      out: function () 
      {
        $(this).children('ul').slideUp(); 
      }});
      
      // scrollbar u produktu
      $('div.scroll-obsah').jScrollPane({scrollbarWidth:10, scrollbarMargin:10, showArrows:false, arrowSize: 0});
      
      // scrollbar u contentu
      $('div.content-obsah').jScrollPane({scrollbarWidth:10, scrollbarMargin:10, showArrows:false, arrowSize: 0});
      $('div.jScrollPaneDrag').css('height','20px');
      

    });
    
  
  



