﻿
var newwindow = ''
function popitup(url) {
    if (newwindow.location && !newwindow.closed) {
        newwindow.location.href = url;
        newwindow.focus();
    }
    else {
        newwindow = window.open(url, 'Infiniauto', 'width=250,height=250,resizable=0,status=0,location=0');
    }
}

function _click(id) {
    document.getElementById(id).click();
}

function YesNo() {
    var ans = window.confirm('Tem a certeza ?');
    if (ans == true) {
        return;
    }
    else {
        return false;
    }
}

function PressEnter(clientid) {
    if (window.event.keyCode == 13) {
        window.event.keyCode = 0;
        eval("document.all." + clientid + ".click()");
    }
}

function Refresh(timeoutPeriod) {
    setTimeout("window.location.href=window.location.href", timeoutPeriod);
}

//  ### check all checkboxes
function ChangeCheckBoxState(id, checkState) {
    var cb = document.getElementById(id);
    if (cb != null)
        cb.checked = checkState;
}

function ChangeAllCheckBoxStates(checkState) {
    // Toggles through all of the checkboxes defined in the CheckBoxIDs array
    // and updates their value to the checkState input parameter
    if (CheckBoxIDs != null) {
        for (var i = 0; i < CheckBoxIDs.length; i++)
            ChangeCheckBoxState(CheckBoxIDs[i], checkState);
    }
}
//  ### check all checkboxes    -   end


function GetWidth() {
    var x = 0;
    if (self.innerHeight) {
        x = self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        x = document.documentElement.clientWidth;
    }
    else if (document.body) {
        x = document.body.clientWidth;
    }
    return (x - 180);
}




/*
    ### Random Image
*/
(function ($) {
    $.randomImage = {
        defaults: {
            //you can change these defaults to your own preferences.
            path: 'images/imageslide/', //change this to the path of your images
            myImages: ['1.png', '2.png', '3.png', '4.png', '5.png', '6.png', '7.png', '8.png', '9.png', '10.png', '11.png', '12.png', '13.png', '14.png', '15.png', '16.png']
        }
    }

    $.fn.extend({
        randomImage: function (config) {
            var config = $.extend({}, $.randomImage.defaults, config);
            return this.each(function () {
                var imageNames = config.myImages;
                //get size of array, randomize a number from this
                // use this number as the array index
                var imageNamesSize = imageNames.length;
                var lotteryNumber = Math.floor(Math.random() * imageNamesSize);
                var winnerImage = imageNames[lotteryNumber];
                var fullPath = config.path + winnerImage;

                //put this image into DOM at class of randomImage
                // alt tag will be image filename.
                $(this).attr({
                    src: fullPath,
                    alt: winnerImage
                });
            });
        }
    });
})(jQuery);

//#####################################################################################################
//#####################################################################################################
// correr imagens slide1 

// id é o nome do ficheiro da imagem
// nome da função que corre as imagens que estão no slide
function RandomImg(path, imgName, caralho, total,controlo) {
    // soma sempre mais 1 ex. 1 , 2 , 3 ,... ciclo do slide
    var id = randomDeAte(1, total);

    // o nome da imagem (img) ou do caralho onde vai estar a imagem by telmogondar
    $('#' + caralho).fadeOut('slow', function () {
        // vai ser alterado o source (src) da imagem
        if (path.length > 0) path += '/';

        if (controlo == 'img')
            $(this).attr('src', 'images/' + path + imgName + id + '.jpg');
        else if (controlo == 'div')
            $(this).css('background-image', 'url(images/' + path + imgName + id + '.jpg)');
        $('#' + caralho).fadeIn(300);
    });
}

//#####################################################################################################
//#####################################################################################################

// gera numeros random 

function randomDeAte(de, ate) {
    return Math.floor(Math.random() * (ate - de + 1) + de);
}


//#####################################################################################################
//#####################################################################################################

// nome da função que corre as imagens que estão no slide
function HighlightImg(valImg) {
    $('#PromoImg').css('background-image', 'url(images/Highlight' + valImg + '.jpg)');
}

/*
#####################################################################################################
#####################################################################################################

    animacao topo da página
*/

var menuSlider = function () {
    var m, e, g, s, q, i; e = []; q = 8; i = 8;
    return {
        init: function (j, k) {
            m = document.getElementById(j); e = m.getElementsByTagName('li');
            var i, l, w, p; i = 0; l = e.length;
            for (i; i < l; i++) {
                var c, v; c = e[i]; v = c.value; if (v == 1) { s = c; w = c.offsetWidth; p = c.offsetLeft }
                c.onmouseover = function () { menuSlider.mo(this) }; c.onmouseout = function () { menuSlider.mo(s) };
            }
            g = document.getElementById(k); g.style.width = w + 'px'; g.style.left = p + 'px';
        },
        mo: function (d) {
            clearInterval(m.tm);
            var el, ew; el = parseInt(d.offsetLeft); ew = parseInt(d.offsetWidth);
            m.tm = setInterval(function () { menuSlider.mv(el, ew) }, i);
        },
        mv: function (el, ew) {
            var l, w; l = parseInt(g.offsetLeft); w = parseInt(g.offsetWidth);
            if (l != el || w != ew) {
                if (l != el) { var ld, lr, li; ld = (l > el) ? -1 : 1; lr = Math.abs(el - l); li = (lr < q) ? ld * lr : ld * q; g.style.left = (l + li) + 'px' }
                if (w != ew) { var wd, wr, wi; wd = (w > ew) ? -1 : 1; wr = Math.abs(ew - w); wi = (wr < q) ? wd * wr : wd * q; g.style.width = (w + wi) + 'px' }
            } else { clearInterval(m.tm) }
        }
    };
} ();

/*
#####################################################################################################
#####################################################################################################

activar e desactivar campanhas
*/

function Mostra(idDiv, idImg) {
    div = document.getElementById(idDiv);
    img = document.getElementById(idImg);

    if (div.style.display == 'none') {
        div.style.display = 'block';
        img.src = '../../images/cima.gif';
    } else {
        div.style.display = 'none';
        img.src = '../../images/baixo.gif';
    }
}

/*
#####################################################################################################
#####################################################################################################

faq's accordion
*/


$(document).ready(function () {
    $('h2.acordiaoHeader').click(function () {
        $(this).parent().find('div.acordiaoContent').slideToggle(100);
    });
});

// 


/*
#####################################################################################################
#####################################################################################################

Automatic Image Slider w/ CSS & jQuery
*/

$(document).ready(function () {

    //Set Default State of each portfolio piece
    $(".paging").show();
    $(".paging a:first").addClass("active");

    //Get size of images, how many there are, then determin the size of the image reel.
    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;

    //Adjust the image reel to its new size
    $(".image_reel").css({ 'width': imageReelWidth });

    //Paging + Slider Function
    rotate = function () {
        var triggerID = $active.attr("rel") - 1; //Get number of times to slide
        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

        $(".paging a").removeClass('active'); //Remove all active class
        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500);

    };

    //Rotation + Timing Event
    rotateSwitch = function () {
        play = setInterval(function () { //Set timer - this will repeat itself every 3 seconds
            $active = $('.paging a.active').next();
            if ($active.length === 0) { //If paging reaches the end...
                $active = $('.paging a:first'); //go back to first
            }
            rotate(); //Trigger the paging and slider function
        }, 4000); //Timer speed in milliseconds (3 seconds)
    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $(".image_reel a").hover(function () {
        clearInterval(play); //Stop the rotation
    }, function () {
        rotateSwitch(); //Resume rotation
    });

    //On Click
    $(".paging a").click(function () {
        $active = $(this); //Activate the clicked paging
        //Reset Timer
        clearInterval(play); //Stop the rotation
        rotate(); //Trigger rotation immediately
        rotateSwitch(); // Resume rotation
        return false; //Prevent browser jump to link anchor
    });

});

/*
#####################################################################################################
#####################################################################################################

jQuery topLink Plugin
*/
//plugin
jQuery.fn.topLink = function (settings) {
    settings = jQuery.extend({
        min: 1,
        fadeSpeed: 200,
        ieOffset: 50
    }, settings);
    return this.each(function () {
        //listen for scroll
        var el = $(this);
        el.css('display', 'none');
        //in case the user forgot
        $(window).scroll(function () {
            //stupid IE hack
            if (!jQuery.support.hrefNormalized) {
                el.css({
                    'position': 'absolute',
                    'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
                });
            }
            if ($(window).scrollTop() >= settings.min) {
                el.fadeIn(settings.fadeSpeed);
            }
            else {
                el.fadeOut(settings.fadeSpeed);
            }
        });
    });
};


/*
#####################################################################################################
#####################################################################################################
    submit order
*/

$(document).ready(function () {
    $('#submitButton2').click(function () {
        if ($('#finishOrder').css('display') == 'none') {
            $('#finishOrder').show('slow');
            $('#submitButton2').attr('value', 'cancelar');
        }
        else {
            $('#finishOrder').hide('slow');
            $('#submitButton2').attr('value', 'enviar encomenda');
        }
    });
});

/*
#####################################################################################################
#####################################################################################################
avisos e notificacoes site encomendas
*/


function Mostra(idDiv, idImg,nomeImg) {
    div = document.getElementById(idDiv);
    img = document.getElementById(idImg);

    if (div.style.display == 'none') {
        img.src = '../../images/' + nomeImg + '1.png';
        $('#'+idDiv).show(400);
    } else {
        img.src = '../../images/' + nomeImg + '2.png';
        $('#' + idDiv).hide(400);
    }
}


