var mY, mX;
$(document).ready(function() 
{
   
   $(document).mousemove(function(e){
      mY = e.pageY; mX = e.pageX;
   });
   
   $('#gallery a, #mainimage a').lightBox();
   
   $('#couponhelp').qtip({
        content: { 
 
          text: 'Pokud vlastníte Kupón, kód prosím vložte před dokončením objednávky. Nejdříve bude zkontrolována správnost samotného kódu kupónu.'

        },
        position: {
          adjust: { x: 13, y: -13 },
          corner: {
             tooltip: 'bottomMiddle', 
             target: 'bottomMiddle' 
          }
        },
        style: {
          width: 330,
          border: {
             width: 3,
             radius: 7
          },
          padding: 20, 
          textAlign: 'justify',
          tip: true, 
          name: 'cream' 
        },
        hide: { fixed: true, delay: 10 }
   });
     
   $('#cardhelp').qtip({
        content: { 
 
          text: 'Pokud znáte heslo pro aktivaci slevy, vyplňte před dokončením objednávky, celková cena nákupu bude ponížena.'

        },
        position: {
          adjust: { x: 13, y: -13 },
          corner: {
             tooltip: 'bottomMiddle', 
             target: 'bottomMiddle' 
          }
        },
        style: {
          width: 330,
          border: {
             width: 3,
             radius: 7
          },
          padding: 20, 
          textAlign: 'justify',
          tip: true, 
          name: 'cream' 
        },
        hide: { fixed: true, delay: 10 }
   });
   
   $('#moresection').click(function(){
    if($('#morecats').css('display') == 'none')
    {
      $('#morecats').css({'display':'block', left: $('#column1').width() + 1, top: mY - 267})
      $('#moresection').html('schovat...')
    }
    else
    {
      $('#morecats').css('display', 'none')
      $('#moresection').html('>Zobrazit všechny Sekce')
    }
   });
   
   $('#aProducerOfSection').click(function(){
   
  	var d           = new Date();
  	var sec         = (d.getHours()*3600)+(d.getMinutes()*60)+d.getSeconds();
    var Url = "/ajxProducersForCategoryOfSection.asp?catID=" + $(this).attr('rel') + "&sec=" + sec

    //alert(Url)
     
    if($('#infoCategoryProducers').css('display') == 'none')
    {
    
      $('#aProducerOfSection').html('Značka výrobce (klikni a schovej)');
      
      $.ajax({
        url: Url,
        success: function(data) {
        
          //alert(Url + '\n\n' + data)
          
          $('#infoCategoryProducers').html(data).css('display', 'block');
          
        },
        error: function(xhr, ajaxOptions, thrownError) 
               { 
                  //alert(Url + '\n\n' +"error\n" + xhr.status + '\n' + thrownError); 
                  $('#infoCategoryProducers').html(Url + '<br/><br/>' +"error: <br/>" + xhr.status + '<br/><br/>' + thrownError);
               }
      });
    }
    else
    {
      $('#infoCategoryProducers').css('display', 'none')
      $('#aProducerOfSection').html('Značka výrobce (klikni a vyber)');
    }
   });
   
   //$('.par1[href]').each(function(i){

      $('.par1').click(
        function()
        {
          $('#parBubble').css({'display': 'none'});
          
          var sUrl = ($(this).attr('rel'));
          var sData = "";
          var t = 0;
          var arrUrl = sUrl.split('?');
          var Domain = arrUrl[0];
          var Params = arrUrl[1];
          var arrParams = Params.split('&');
          var resParams = '';
          var arrData = '';
          for(var a=0; a < arrParams.length; a++)
          {
            arrData = arrParams[a].split('=');
            resParams+=arrData[0]+'='+escape(arrData[1])+'&';
          }
          
        	var d    = new Date();
        	var sec  = (d.getHours()*3600)+(d.getMinutes()*60)+d.getSeconds(); 
          
          sUrl     = Domain +'?'+ resParams + 'sec='+sec;
          t = mY+40;

          //alert(sUrl);
          
          var w = 780;
          
          $.ajax({
            url: sUrl,
            success: function(data) {
              
              sData = data;
              //alert(sData);
              
              
              
              $('#parBubble').html(sData);
              
              w = $('#parHelp').attr('rel')*1;
              //alert(w)
              
              $('#parBubble').css({'display': 'block', right: 0, top: '20px', 'width': w+'px', 'z-index':333, 'height': 'auto'});
            },
            error: function(xhr, ajaxOptions, thrownError) 
                   { 
                      //alert(Url + '\n\n' +"error\n" + xhr.status + '\n' + thrownError); 
                      $('#parBubble').html(Url + '<br/><br/>' +"error: <br/>" + xhr.status + '<br/><br/>' + thrownError);
                   }
          });
          
          var w = $('#parHelp').attr('rel');

          if( w > 799 )
          {
            t = 0;
          }
          
          t = 0;
          
          //alert(sData);
          

        }
      );
      
      $('#parHelpClose').live('click', function(){
        $('#parBubble').css({'display': 'none', 'width': '780px'});
      });
      
      
   //});
   
   $('.par[href]').each(function(i){

      var sUrl = ($(this).attr('rel'));
      
      var arrUrl = sUrl.split('?');
      var Domain = arrUrl[0];
      var Params = arrUrl[1];
      var arrParams = Params.split('&');
      var resParams = '';
      var arrData = '';
      for(var a=0; a < arrParams.length; a++)
      {
        arrData = arrParams[a].split('=');
        resParams+=arrData[0]+'='+escape(arrData[1])+'&';
      }
      sUrl = Domain +'?btclose=no&'+ resParams;
      
     $(this).qtip({
        content: { 
 
          url: sUrl

        },
        position: {
          adjust: { x: 13, y: -13 },
          corner: {
             tooltip: 'bottomLeft', 
             target: 'bottomLeft' 
          }
        },
        style: {
          width: 430,
          border: {
             width: 3,
             radius: 7
          },
          padding: 3, 
          textAlign: 'justify',
          tip: true, 
          name: 'cream' 
        },
        hide: { fixed: true, delay: 10 }
     });
     
   });
   //----------------------------------------------------------------------------------------------
  $(".littleimgX").mouseover(function() {
    var sID = $(this).attr('id').replace('l_', '');
    
    if($(".commodityCatalog").length>0)
    {
      var scrW = $(window).width();
      var scrH = $(window).height();
      var divW = $(this).parent('a').parent('div').width();
      var divH = $(this).parent('a').parent('div').height();
      var divT = mY;//$(this).offset().top;
      var divL = mX;//$(this).offset().left;
      
      var pageW = $(".commodityCatalog").width();
      var pageL = $(".commodityCatalog").offset().left;
      var pageH = 0;//$(".commodityCatalog").offset().height;
      var imgW = $("#bigimg_" + sID).width();
      var imgL = $("#bigimg_" + sID).parent().offset().left;
      var imgT = divT;
      
      var l = imgL - 90;
      var t = mY - 90;
      if((pageL + imgL) > pageW){ l = imgL-imgW-230; }
      
      $("#bigimg_" + sID)
        .css({'z-index' : '100', 'display' : 'block', 'position':'absolute', 'border':'2px solid black', 'background-color':'#fff', 'top':imgT, 'left':l})
        .animate({
      			top: imgT - 320,
      			left: l + 'px',
      			padding: '20px'
      		}, 200);
    }
  });
  $(".littleimgX").mouseleave(function() {
  	var sID = $(this).attr('id').replace('l_', '');
      $("#bigimg_" + sID).css({'z-index' : '0', 'display' : 'none'});
  });
  //----------------------------------------------------------------------------------------------
});

