var timeBetweenFade = 4000;
var promoLinks = 0;
var currentPromoId = 1;
var timeoutId = null;

$(document).ready(function(){	
	promoLinks = $('a.quickPromoLink').size();	
	if(promoLinks > 1) { timeoutId = setTimeout('fadeNext()', timeBetweenFade); }	
});

function fadeNext()
{	
	clearTimeout(timeoutId);
	timeoutId = setTimeout('fadeNext()', timeBetweenFade);
	
	var prevPromo = currentPromoId;
	currentPromoId ++;
	if(currentPromoId > promoLinks) { currentPromoId = 1; }
	
	$('a#quickPromoLink_'+prevPromo).fadeOut(400);
	$('a#quickPromoLink_'+currentPromoId).fadeIn(400);
}

function openWindow(link) // inspired by porneL - http://pornel.net/pups/
{
  try
  {
    var new_window = window.open(link, '_blank');
    if(new_window) return false;
  }
  catch(e){}
  return true;
}

function checkRequiredFields(form_id)
{
  ok = true;
  fields = document.getElementsByTagName('input');
  for(var i in fields) if(fields[i].className=='text required')
  {
    if(fields[i].parentNode.parentNode.parentNode.id==form_id && !fields[i].value) ok = false;
  }
  fields = document.getElementsByTagName('textarea');
  for(var i in fields) if(fields[i].className=='required')
  {
    if(fields[i].parentNode.parentNode.parentNode.id==form_id && !fields[i].value) ok = false;
  }
  if(ok)
  {
    //document.getElementById('submit_'+form_id).disabled = 'disabled';
    return true;
  }
  alert('You have to fill all the required fields (marked with asterisk).');
  return false;
}

function addMenuHover()
{
  m = document.getElementsByTagName('li');
  for(var i in m) if(m[i].innerHTML && m[i].parentNode.parentNode.id=='header' && m[i].className=='dd')
  {
    id = m[i].id;
    m[i].onmouseover = function()
    {
      document.getElementById('s'+id).style.display = 'block';
    }
    m[i].onmouseout = function()
    {
      document.getElementById('s'+id).style.display = 'none';
    }
  }
}

onload = function()
{
  a = document.getElementsByTagName('a');
  for(var i in a) if(a[i].innerHTML && (a[i].className=='nw' || a[i].className=='photo nw'))
  {
    a[i].target = '_blank';
  }
}


var im=1;
var imK=1;
var aS = true;   
function changeImg(imTo,imCh){
      $('#slide'+imTo).fadeOut('normal',function() { $('#slide'+imTo).css('display','none'); });
      $('#slide'+imCh).fadeIn('normal',function() { $('#slide'+imCh).css('display','block'); });
}
    
function nextImg(){
      aS = false; //Zatrzymanie autosliade
      var newIm = im + 1;
      if(newIm>imK) newIm=1;
      changeImg(im,newIm);
      im = newIm;
}
    
function nextImg2(){
      var newIm = im + 1;
      if(newIm>imK) newIm=1;
      changeImg(im,newIm);
      im = newIm;
        
}
    
function prevImg(){
        aS = false; //Zatrzymanir autosliade
        var newIm = im - 1;
        if(newIm<1) newIm=imK;
        changeImg(im,newIm);
        im = newIm;
}
    
function autoSlide(){
        if(aS) nextImg2(); //Jeśli było sterowane ręcznie to jedna kolejka bez przełączania
        aS = true;
        setTimeout("autoSlide()",6000);
}

function autoSlide2(imk){
  imK = imk;
  setTimeout("autoSlide()",6000);    
}

var qImg1 = 1;
var qImg2 = 3;
var qImgK = 3;

function autoQuickImg(qimk){
  qImgK = qimk;
  var newWidth = qImgK*319;
  $("#quickBoxSlide").css('width',newWidth+'px');
}

function nextQImg(){
      var newIm2 = qImg2 + 1;
      if(newIm2>qImgK){ return false; }
      else{
        var newIm1 = qImg1 + 1;
        $("#quickBoxSlide").animate({marginLeft: "-=319px"}, "normal");
        qImg1 = newIm1;
        qImg2 = newIm2;
      }
}

function prevQImg(){
      var newIm1 = qImg1 - 1;
      if(newIm1<1){ return false; }
      else{
        var newIm2 = qImg2 - 1;
        $("#quickBoxSlide").animate({marginLeft: "+=319px"}, "normal");
        qImg1 = newIm1;
        qImg2 = newIm2;
      }  
}

