function GetAjaxBlock(vUrl,vCont) 
{ 

   function ShowResult(data) 
   { 
    oWaitCont=document.getElementById('wait_cont');
    oWaitCont.style.display='none';
    $(".fancy_loading").hide();

      var obContainer = document.getElementById(vCont); 
      if (obContainer) 
         obContainer.innerHTML = data; 
   }
   
   oWaitCont=document.getElementById('wait_cont');
   oWaitCont.style.display='block';
   
   $.fn.fancybox.showLoading();
    
   var TID = CPHttpRequest.InitThread(); 
   CPHttpRequest.SetAction(TID, ShowResult); 
   CPHttpRequest.Send(TID, vUrl,{}); 
    
   return false; 
} 


function GetPPBlock(vUrl,vCont,vRecalc) 
{ 
   
  if ($('#'+vCont).hasClass("opened")) 
  {
   $('#'+vCont).removeClass("opened");
   $('#'+vCont).slideUp();
  }
  else
  {
   $('#'+vCont).addClass("opened");
   
   if ($('#'+vCont).hasClass("loaded")) 
   {
    $('#'+vCont).slideDown();
   }
   else
   {

    function ShowResult(data) 
    { 
      oWaitCont=document.getElementById('wait_cont');
      oWaitCont.style.display='none';
      $(".fancy_loading").hide();

      var obContainer = document.getElementById(vCont); 
      if (obContainer) 
      {
	    $('#'+vCont).addClass("loaded");   
        obContainer.innerHTML = data; 
        $('#'+vCont).slideDown();
        if (parseInt(vRecalc)>0)
        {
         PPCountBlock(vRecalc);
        } 
      }   
     }
   
     oWaitCont=document.getElementById('wait_cont');
     oWaitCont.style.display='block';
   
     $.fn.fancybox.showLoading();
    
     var TID = CPHttpRequest.InitThread(); 
     CPHttpRequest.SetAction(TID, ShowResult); 
     CPHttpRequest.Send(TID, vUrl,{}); 
     return false; 
    }
  }  
} 

function PPCountBlock(vBlockNum)
{
 var vI=1;
 var vAllBlockCount=0;
 var vAllSumCount=0;

 while(document.getElementById('pp_item_list_'+vBlockNum+'_'+vI))
 {
  var oObjCount=document.getElementById('pp_item_list_'+vBlockNum+'_'+vI);
   
  if (parseInt(oObjCount.value)>0)
  {
   vAllBlockCount+=parseInt(oObjCount.value);
   var oObjCost=document.getElementById('pp_item_list_'+vBlockNum+'_'+vI+'_cost');
   var oObjSum=document.getElementById('pp_item_list_'+vBlockNum+'_'+vI+'_sum');   
   var vSum = parseInt(oObjCount.value)*parseInt(oObjCost.value);
   oObjSum.innerHTML= number_format(vSum,2,',',' ');
   vAllSumCount+= vSum;
  }
  else
  {
   var oObjSum=document.getElementById('pp_item_list_'+vBlockNum+'_'+vI+'_sum');   
   oObjSum.innerHTML=0;
  }
  
  vI++;
 }

 var oAllBlockCount = document.getElementById('pp_ajax_box_'+vBlockNum+'_count');
 oAllBlockCount.value=vAllBlockCount;

 var oAllBlockSum = document.getElementById('pp_ajax_box_'+vBlockNum+'_sum');
 oAllBlockSum.innerHTML=number_format(vAllSumCount,2,',',' ');
 var oAllBlockSumHidden=document.getElementById('pp_ajax_box_'+vBlockNum+'_sum_hidden');   
 oAllBlockSumHidden.value=vAllSumCount;
 
 PPCountAllBlock();
}

function PPCountAllBlock()
{
 var oObjAllCount = document.getElementById('pp_all_count');
 var oObjAllSum = document.getElementById('pp_all_sum');

 var vAllCount = 0;
 var vAllSum = 0;

 for ( var i in aSection )
 {
  var oObjCount = document.getElementById('pp_ajax_box_'+aSection[i]+'_count');
  var oObjSum = document.getElementById('pp_ajax_box_'+aSection[i]+'_sum_hidden');  
  
  if (parseInt(oObjCount.value)>0)
  {
   vAllCount+=parseInt(oObjCount.value);
  } 
  if (parseInt(oObjSum.value)>0)
  {
   vAllSum+=parseInt(oObjSum.value);
  } 
  
 }

 oObjAllCount.innerHTML = vAllCount;
 oObjAllSum.innerHTML = number_format(vAllSum,2,',',' ');
}


function number_format(number, decimals, dec_point, thousands_sep){
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
 var i, z;
  if(eindex > -1){
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if(decimals != null){
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
  if(decimals != null && decimals > 0){
    for(i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if(thousands_sep != null && thousands_sep != ""){
  for (i = integer.length - 3; i > 0; i -= 3)
   integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  return sign + integer + fractional + exponent;
}


 function fn_makegallery(vNum)
 {
//  $('#gallery_'+vNum).unbind();	
  $('#gallery_'+vNum+' li:first-child').addClass("active");
 
 
   if (document.getElementById("main_img_"+vNum))
   {
 				var oObj = document.getElementById("main_img_"+vNum);
				oObj.innerHTML='';
   }
 
	$('#gallery_'+vNum).galleria({
			history   : false, // deactivates the history object for bookmarking, back-button etc.
			clickNext : false, // helper for making the image clickable. Let's not have that in this example.
			insert    : "#main_img_"+vNum, // the containing selector for our main image. 
								   // If not found or undefined (like here), galleria will create a container 
								   // before the ul with the class .galleria_container (see CSS)

			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				
				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail		
				_li.siblings().children('img.selected').fadeTo(500,0.5);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				
				var vLinkId=thumb.attr('id');				
				var vLink=document.getElementById('hidden_'+vLinkId);
				var oBox=document.getElementById('main_img_a_'+vNum);
				
				oBox.href=vLink.value;
				
				$('#main_img_a_'+vNum).fancybox();
				
				}
,
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.5';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}
).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); }
,
					function() { _li.not('.active').children('img').fadeTo('fast',0.5); }
 // don't fade out if the parent is active
				)
			  }

});

}

function fn_turn_news_page(vNum)
{
  var oObj0=document.getElementById('news_start_page_block_0');
  var oObj1=document.getElementById('news_start_page_block_1');  

 if (vNum==0)
 {
  $("#news_start_page_block_1").fadeOut(300);
  $("#news_start_page_block_0").fadeIn(800);
 
 }
 else
 {
  $("#news_start_page_block_0").fadeOut(300);
  $("#news_start_page_block_1").fadeIn(800);

 }

}

function equal_cols()
{
 var oLeftCol = document.getElementById('id_leftcol_height');
 var oRightCol = document.getElementById('id_rightcol_height');
 
 if (oLeftCol.clientHeight!=oRightCol.clientHeight)
 {
  var oRcont = document.getElementById('news_start_page_block_cont');
  oRcont.style.height=(oRcont.clientHeight+oLeftCol.clientHeight-oRightCol.clientHeight)+"px";
 }
 
  var oRcont = document.getElementById('id_centercol_height_comp');
  oRcont.style.height=(oLeftCol.clientHeight-68)+"px";
}

function redraw_table()
{
 $(".catalog_element table tr:nth-child(odd)").addClass("trow1");
 $(".catalog_element table tr:nth-child(even)").addClass("trow2");
 $(".catalog_element table td").addClass("tcell");
 $(".catalog_element table").addClass("ttable");
}

function reheight_template()
{
 return;

 var oHeader=document.getElementById('header');
 var oMain=document.getElementById('main');  
 var oFooter=document.getElementById('footer'); 
 
 var vBlockHeight=oHeader.offsetHeight+oMain.offsetHeight+oFooter.offsetHeight;
 
 if (vBlockHeight<document.body.offsetHeight)
 {
  var oCH = document.getElementById('id_hlc');
  var vDelta=document.body.offsetHeight-vBlockHeight;
  oCH.style.height=(oCH.offsetHeight+vDelta)+"px";
 }
}



$(function()  
{  
  var hideDelay = 500;    
  var currentID;  
  var hideTimer = null;  
  
  // One instance that's reused to show info for the current person  
  var container = $('<div id="personPopupContainer"><div id="personPopupContent">123</div></div>');  
  
  $('body').append(container);  
  
  $('.personPopupTrigger').live('mouseover', function()  
  {  
      // format of 'rel' tag: pageid,personguid  
      var settings = $(this).attr('rel').split(',');  
      var itemID = settings[0]; 

      // If no guid in url rel tag, don't popup blank  
      if (itemID == '')  
          return;  
  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  
	  var pos = $(this).offset(); 
	  var width = $(this).width(); 

      if (settings[1])
      {
      	width=5;
		pos.left=arCoord[0];
		pos.top=arCoord[1];		
      } 
     
 
      container.css({  
          left: (pos.left + width) + 'px',  
          top: pos.top - 5 + 'px'  
      });  
  
      $('#personPopupContent').html('&nbsp;');       
      $('#personPopupContent').html($('#reginfo_item_'+itemID).html());
	  $("#personPopupContainer").fadeIn("fast");

  });  
  
  $('.personPopupTrigger').live('mouseout', function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
	   $("#personPopupContainer").fadeOut("fast");
      }, hideDelay);  
  });  
  
  // Allow mouse over of details without hiding details  
  $('#personPopupContainer').mouseover(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
  });  
  
  // Hide after mouseout  
  $('#personPopupContainer').mouseout(function()  
  {  
      if (hideTimer)  
          clearTimeout(hideTimer);  
      hideTimer = setTimeout(function()  
      {  
	   $("#personPopupContainer").fadeOut("fast");
      }, hideDelay);  
  });  
});  


function fnShowHideBlock(vIdBlock)
{
 if ($('#'+vIdBlock).hasClass('open'))
 {
  $('#'+vIdBlock).removeClass('open');
  $('#'+vIdBlock).slideUp('slow');
 }
 else
 {
  $('#'+vIdBlock).addClass('open');
  $('#'+vIdBlock).slideDown('slow'); 
 }

}
