function setBg( id, current )
{
  if ( id == 2 )
  {
    $('#productList').find('a').each(function(){ $(this).css('background','url(site/pic/prod-bg-off.png) no-repeat top left');} );
    $('#productList').find('li').each(function(){ $(this).css('background','none');} );
  }
  else
  {
    $('#groupList').find('a').each(function(){ $(this).css('background','none');} );
    $('#groupList').find('li').each(function(){ $(this).css('background','none');} );
  }
  $(current).css('background','url(site/pic/prod-bg.png) no-repeat top left');
  return false;
}


function getProd( docId, groupId )
{
  var data = {};
  data.product = docId;
  data.group = groupId;
  data.selector = 'product';
  $.get( 'ajax.html', data, callback_getProd, 'html' );
  return false;
}



function callback_getProd(data, textStatus) {
  	var _images = [];
    var k = 0;
  	var goTime = 0;
  $('#product').fadeOut('slow',
  function () {


    $('#product').html(data);
    $('#product').find('img').each(function(){ _images[k] = $(this).attr("src"); k=k+1; });

  	goTime = _images.length;

    for(var i = 0; i<_images.length; i++)
    {
  	  $("<img>").attr('src',_images[i]+"?t="+Math.random()*65555).load(
      function()
        { if ( --goTime < 1 ) { $('#product').fadeIn('slow'); }}
      );
  	};

    }
  );
}



function getProdList( groupId )
{
  var data = {};
  data.group = groupId;
  data.selector = 'productList';
  $.get( 'ajax.html', data, callback_getProdList, 'html' );
  return false;
}

function callback_getProdList(data, textStatus) {
  $('#productList').fadeOut('slow', function(){ $(this).html(data).fadeIn('slow');} );
}

$(document).ready(function(){
  $("a").bind( 'focus', function() { $(this).blur(); } );

  $('#hmenu ul').superfish();
  $('#hmenu ul li').each(function(i){$(this).css('z-index',100+i);});
  $('#vmenu ul').superfish();
  $('#bmenu ul').superfish();

  $('.table').each(function() {
    $('tr:first', this).addClass('firstTr');
    $('tr:even', this).not(':first').addClass('evenTr');
    $('tr',this).not(':first').each(function() {
      $('td',this).addClass('allTd');
      });
    });

  Date.format = 'dd/mm/yyyy';
  $('.calendar').each(function() {
  	$(this).datePicker({
      startDate: '01/01/1900',
      clickInput:true,
      createButton:false,
      showYearNavigation:false,
      verticalOffset:20
    });
  });

});

function popup(url, target, width, height, features)
{
    var wnd, features1;

    features1 = 'width=' + width + ',height=' + height;
    if (screen) {
        features1 += ',left=' + (screen.width - width) / 2 +
                ',top=' + (screen.height - height) /2;
    }
    if (features) {
        features1 += ',' + features;
    }

    wnd = window.open(url, target, features1);
    wnd.focus();

    return false;    
}
