var currentNews = 1;
var countNews = 0;


function initFlash(elementId, filename, widthIn, heightIn)
{
    $('#'+elementId).flash(
    { src: '/templates/basic/images/'+filename,width: widthIn,height: heightIn},
    { expressInstall: true }
    );
}

function nextIdea()
{
    $('#div-img-big-o-firmie').html("");
    initFlash('div-img-big-o-firmie','panorama-pietro.swf',510,288);
    $('img.arrowRight').hide();
    $('img.arrowLeft').show();
    $('#span-current-images').html('2');
}

function backIdea()
{
    $('#div-img-big-o-firmie').html("");
    initFlash('div-img-big-o-firmie','panorama-parter.swf',510,288);
    $('img.arrowRight').show();
    $('#span-current-images').html('1');
}

function next()
{
    currentId++;
    showImg(-1);   
}

function back()
{
    currentId--;
    showImg(-1);
}

function nextDesign()
{
    currentId++;
    showImgDesign(-1);
}

function backDesign()
{
    currentId--;
    showImgDesign(-1);
}

function nextRealisation()
{
    currentId++;
    showImgRealisations(-1);
}

function backRealisation()
{
    currentId--;
    showImgRealisations(-1);
}

function nextFineArt()
{
    currentId++;
    showImgFineArts(-1);
}

function backFineArt()
{
    currentId--;
    showImgFineArts(-1);
}

function nextWyprzedaz()
{
    currentId++;
    showImgWyprzedaz(-1);
}

function backWyprzedaz()
{
    currentId--;
    showImgWyprzedaz(-1);
}

function showImg(i)
{
    if (i!=-1) {currentId=i;}

    //alert(mWidth[currentId]);
    
    $('#slide-product-name').html(productNames[currentId]);
    $('#slide-producer').html(producers[currentId]);
    $('#slide-country').html(countries[currentId]);
    //$('#slide-producer-link').html(links[currentId]);
    $('#slide-producer-link').html("<a href='"+links[currentId]+"' target='_blank'>"+links[currentId]+"</a>");
    $('#slide-short-description').html(descriptions[currentId]);

    $('#a-big-img').attr('href','/upload/' + maxImages[currentId]);
    $('.big').attr('src','/upload/' + middleImages[currentId]);

    $('#span-current-images').html(currentId+1);
    if (currentId==miniImages.length-1) { $('.arrowRight').hide(); }
    else {$('.arrowRight').show();}

    $('#span-current-images').html(currentId+1);
    if (currentId==0) { $('.arrowLeft').hide(); }
    else {$('.arrowLeft').show(); }

    $(".img-mini").removeClass("selected");
    $("#img-mini-"+currentId).addClass("selected");

    cId = currentId;

    $('a.lightbox').each(function(i){

      $(this).attr('href','/upload/' + maxImages[cId]);
      $(this).attr('title','<strong>'+ productNames[cId] +'</strong>&nbsp;&nbsp;Producent: '+producers[cId]+'&nbsp;&nbsp;Kraj: '+countries[cId]);

      cId++;

      if (cId>miniImages.length-1) cId=0;

    });
    $('#input-search').focus();
}


function showImgDesign(i)
{
    if (i!=-1) {currentId=i;}
    
    $('#a-big-img').attr('href',urlS[currentId]);
    $('.big').attr('src','/upload/' + middleImages[currentId]);
    $('#slide-product-name').html(productNames[currentId]);
    $('#slide-producer').html(producers[currentId]);
    $('#slide-country').html(countries[currentId]);
    //$('#slide-producer-link').html(links[currentId]);
    $('#slide-producer-link').html("<a href='"+links[currentId]+"' target='_blank'>"+links[currentId]+"</a>");
    $('#slide-short-description').html(descriptions[currentId]);
    

    $('#span-current-images').html(currentId+1);
    if (currentId==miniImages.length-1) { $('.arrowRight').hide(); }
    else {$('.arrowRight').show();}

    $('#span-current-images').html(currentId+1);
    if (currentId==0) { $('.arrowLeft').hide(); }
    else {$('.arrowLeft').show(); }

    $(".img-mini").removeClass("selected");
    $("#img-mini-"+currentId).addClass("selected");

    cId = currentId;

    $('a.lightbox').each(function(i){

      $(this).attr('href','/upload/' + maxImages[cId]);
      $(this).attr('title','<strong>'+ productNames[cId] +'</strong>&nbsp;&nbsp;Producent: '+producers[cId]+'&nbsp;&nbsp;Kraj: '+countries[cId]);

      cId++;

      if (cId>miniImages.length-1) cId=0;

    });
    $('#input-search').focus();
}

function showImgRealisations(i)
{
    if (i!=-1) {currentId=i;}
    
    $('#a-big-img').attr('href',urlS[currentId]);
    $('.big').attr('src','/upload/' + middleImages[currentId]);
    $('#slide-product-name').html(productNames[currentId]);
    $('#slide-producer').html(producers[currentId]);
    $('#slide-country').html(countries[currentId]);
    //$('#slide-producer-link').html(links[currentId]);
    $('#slide-short-description').html(descriptions[currentId]);
   
    $('#span-current-images').html(currentId+1);
    if (currentId==miniImages.length-1) { $('.arrowRight').hide(); }
    else {$('.arrowRight').show();}

    $('#span-current-images').html(currentId+1);
    if (currentId==0) { $('.arrowLeft').hide(); }
    else {$('.arrowLeft').show(); }

    $(".img-mini").removeClass("selected");
    $("#img-mini-"+currentId).addClass("selected");

    cId = currentId;

    $('a.lightbox').each(function(i){

      $(this).attr('href','/upload/' + maxImages[cId]);
      $(this).attr('title','<strong>'+ productNames[cId] +'</strong>');

      cId++;

      if (cId>miniImages.length-1) cId=0;

    });
    $('#input-search').focus();
}

function showImgFineArts(i)
{
    if (i!=-1) {currentId=i;}
    
    $('#a-big-img').attr('href',urlS[currentId]);
    $('.big').attr('src','/upload/' + middleImages[currentId]);
    $('#slide-product-name').html(productNames[currentId]);
    $('#slide-producer').html(producers[currentId]);
    $('#slide-country').html(countries[currentId]);
    //$('#slide-producer-link').html(links[currentId]);
    $('#slide-producer-link').html("<a href='"+links[currentId]+"' target='_blank'>"+links[currentId]+"</a>");
    $('#slide-short-description').html(descriptions[currentId]);   

    $('#span-current-images').html(currentId+1);
    if (currentId==miniImages.length-1) { $('.arrowRight').hide(); }
    else {$('.arrowRight').show();}

    $('#span-current-images').html(currentId+1);
    if (currentId==0) { $('.arrowLeft').hide(); }
    else {$('.arrowLeft').show(); }

    $(".img-mini").removeClass("selected");
    $("#img-mini-"+currentId).addClass("selected");

    cId = currentId;

    $('a.lightbox').each(function(i){

      $(this).attr('href','/upload/' + maxImages[cId]);
      $(this).attr('title','<strong>'+ productNames[cId] +'</strong>');

      cId++;

      if (cId>miniImages.length-1) cId=0;

    });
    $('#input-search').focus();
}

function showImgWyprzedaz(i)
{
    if (i!=-1) {currentId=i;}

    //alert(mWidth[currentId]);

    //$('#a-big-img').attr('href','/upload/' + maxImages[currentId]);
    $('#a-big-img').attr('href',urlS[currentId]);
    $('.big').attr('src','/upload/' + middleImages[currentId]);
    $('#slide-product-name').html(productNames[currentId]);
    $('#slide-producer').html(producers[currentId]);
    $('#slide-country').html(countries[currentId]);
    $('#slide-producer-link').html("<a href='"+links[currentId]+"' target='_blank'>"+links[currentId]+"</a>");
    $('#slide-short-description').html(descriptions_ext[currentId]);
   
    $('#span-current-images').html(currentId+1);
    if (currentId==miniImages.length-1) { $('.arrowRight').hide(); }
    else {$('.arrowRight').show();}

    $('#span-current-images').html(currentId+1);
    if (currentId==0) { $('.arrowLeft').hide(); }
    else {$('.arrowLeft').show(); }

    $(".img-mini").removeClass("selected");
    $("#img-mini-"+currentId).addClass("selected");

    cId = currentId;

    $('a.lightbox').each(function(i){

      $(this).attr('href','/upload/' + maxImages[cId]);
      $(this).attr('title','');

      cId++;

      if (cId>miniImages.length-1) cId=0;

    });

    $('#input-search').focus();
}

function show()
{
    var options = {};
    $("#slide").show('slide',options,500);
    $("#imgShow").hide();
    $("#imgHide").show();
}

function hide()
{
    var options = {};
    $("#slide").hide('slide',options,500);
    $("#imgShow").show();
    $("#imgHide").hide();
}

function initScrollable(sizeIn)
{
    $("div.scrollable").scrollable({vertical:true, size:sizeIn, clickable: false});
}

function nextPromotion()
{
    currentId++;
    showPromotion(currentId);
}

function backPromotion()
{
    currentId--;
    showPromotion(currentId);
}

function showPromotion(id)
{
    $('a.big').hide();
    $('div.description').hide();
    $('#a-big-img-'+id).show();
    $('#image_'+id).show();
    $('#description_'+id).show();

    if (currentId==promotions.length-1) { $('.arrowRight').hide(); }
    else {$('.arrowRight').show();}

    if (currentId==0) { $('.arrowLeft').hide(); }
    else {$('.arrowLeft').show(); }

    $('#span-current-images').html(currentId+1);
}

function showNews()
{
    $('#overlay-in-full-news').show();
    $('#div-overlay-news').show();
    $('#btn-news').hide();
    $('#div-inner-content').hide();
    $('#div-loga').hide();
}

function closeNews()
{
    $('#overlay-in-full-news').hide();
    $('#div-overlay-news').hide();
    $('#btn-news').show();
    $('#div-inner-content').show();
    $('#div-loga').show();
}

function nextNews()
{
    countNews = $('#count-news').val();
    
    if (countNews>currentNews) 
    {
      $('#news_'+currentNews).hide();
      currentNews++;
      $('#news_'+currentNews).show();
    }
}

function backNews()
{
    countNews = $('#count-news').val();    
    if (currentNews>1) 
    {
      $('#news_'+currentNews).hide();
      currentNews--;
      $('#news_'+currentNews).show();
    }
}

function showTeem()
{
    $('#btn-news').hide();
    $('#div-inner-content').hide();
    $('#div-loga').hide();
    $('#overlay-in-big-team').show();
}

function closeTeem()
{
    $('#overlay-in-big-team').hide();
    $('#btn-news').show();
    $('#div-inner-content').show();
    $('#div-loga').show();
}

function add2Newsletter()
{
     email = $('#email-ns').val();

     bodyContent = $.ajax({
        type: "POST",
        url: "/lib/myAjax.php",
        data: 'f=addToNewsletter&email='+email,
        dataType: "html",
        success: function(msg)
        {            
            $('.th').hide();
            $('div.msg').html('Dziękujemy!');
            //$('div.msg').html(msg);
            $('div.msg').show();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown)
        {          
          //$('#div-Ajax-massages').html('Error-> o: '+XMLHttpRequest+' k: '+textStatus+' r: '+ errorThrown);
        }
      }).responseText;
}

function checkEmail(lang)
{
    var email = $('#email-ns').val();    
    var filter = /^[^@]+@[^@]+.[a-z]{2,}$/i;

    if (email.search(filter)==-1)
    {
        if (lang=='en') alert('Please provide a valid email address');
        else alert('Podaj poprawny adres email!');
        return false;
    }
    return true;
}

function checkOfferFrm(lang)
{    
    if ($('#lastname').val()=='')
    {
        if (lang=='en') alert('Wypełnij pole \'nazwisko\'');
        else alert('Wypełnij pole \'nazwisko\'!');
        return false;
    }

    if ($('#phone_email').val()=='')
    {
        if (lang=='en') alert('Wypełnij pole \'telefon i/lub email\'');
        else alert('Wypełnij pole \'telefon i/lub email\'!');
        return false;
    }

    if ($('#content').val()=='')
    {
        if (lang=='en') alert('Wypełnij pole \'treść zapytania\'');
        else alert('Wypełnij pole \'treść zapytania\'!');
        return false;
    }

    return true;    
}
