function initPage()
{
    clearFormFields({
        clearInputs: true,
        clearTextareas: true,
        passwordFieldText: false,
        addClassFocus: "focus",
        filterClass: "default"
    });

    initSlider();
    initHomeSlider();
    initPopupOpen();
    initTabset();
    initVideoSlider();
    initHomeNewsSwitcher();
    initBrandSlider();
    initHistoryButtons();
}
function initHomeNewsSwitcher() {
    setHomeNews(0);
    $('.andgallery2 .andsmall-images a').click(function(evt) {
        evt.preventDefault();
        var index = $(this).parent().index();
        setHomeNews(index);
    });
}
function setHomeNews(i) {
    $('.andgallery2 .andtxt, .andgallery2 .andgallery-image a').hide();
    $('.andgallery2 .andtxt').eq(i).show();
    $('.andgallery2 .andgallery-image a').eq(i).show();
}
function clearFormFields(o) {
    if (o.clearInputs == null) o.clearInputs = true;
    if (o.clearTextareas == null) o.clearTextareas = true;
    if (o.passwordFieldText == null) o.passwordFieldText = false;
    if (o.addClassFocus == null) o.addClassFocus = false;
    if (!o.filterClass) o.filterClass = "default";
    if (o.clearInputs) {
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if ((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass) == -1) {
                inputs[i].valueHtml = inputs[i].value;
                inputs[i].onfocus = function() {
                    if (this.valueHtml == this.value) this.value = "";
                    if (this.fake) {
                        inputsSwap(this, this.previousSibling);
                        this.previousSibling.focus();
                    }
                    if (o.addClassFocus && !this.fake) {
                        this.className += " " + o.addClassFocus;
                        this.parentNode.className += " parent-" + o.addClassFocus;
                    }
                }
                inputs[i].onblur = function() {
                    if (this.value == "") {
                        this.value = this.valueHtml;
                        if (o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
                    }
                    if (o.addClassFocus) {
                        this.className = this.className.replace(o.addClassFocus, "");
                        this.parentNode.className = this.parentNode.className.replace("parent-" + o.addClassFocus, "");
                    }
                }
                if (o.passwordFieldText && inputs[i].type == "password") {
                    var fakeInput = document.createElement("input");
                    fakeInput.type = "text";
                    fakeInput.value = inputs[i].value;
                    fakeInput.className = inputs[i].className;
                    fakeInput.fake = true;
                    inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
                    inputsSwap(inputs[i], null);
                }
            }
        }
    }
    if (o.clearTextareas) {
        var textareas = document.getElementsByTagName("textarea");
        for (var i = 0; i < textareas.length; i++) {
            if (textareas[i].className.indexOf(o.filterClass) == -1) {
                textareas[i].valueHtml = textareas[i].value;
                textareas[i].onfocus = function() {
                    if (this.value == this.valueHtml) this.value = "";
                    if (o.addClassFocus) {
                        this.className += " " + o.addClassFocus;
                        this.parentNode.className += " parent-" + o.addClassFocus;
                    }
                }
                textareas[i].onblur = function() {
                    if (this.value == "") this.value = this.valueHtml;
                    if (o.addClassFocus) {
                        this.className = this.className.replace(o.addClassFocus, "");
                        this.parentNode.className = this.parentNode.className.replace("parent-" + o.addClassFocus, "");
                    }
                }
            }
        }
    }
    function inputsSwap(el, el2) {
        if (el) el.style.display = "none";
        if (el2) el2.style.display = "inline";
    }
}
if (window.addEventListener)
    window.addEventListener("load", initPage, false);
else if (window.attachEvent)
    window.attachEvent("onload", initPage);

eval(function(p, a, c, k, e, r) { e = function(c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) r[e(c)] = k[c] || e(c); k = [function(e) { return r[e] } ]; e = function() { return '\\w+' }; c = 1 }; while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]); return p } ('9 u=k(){9 g=/^([^#.>`]*)(#|\\.|\\>|\\`)(.+)$/;k u(a,b){9 c=a.J(/\\s*\\,\\s*/);9 d=[];n(9 i=0;i<c.l;i++){d=d.v(o(c[i],b))};6 d};k o(a,b,c){a=a.z(" ","`");9 d=a.r(g);9 e,5,m,7,i,h;9 f=[];4(d==8){d=[a,a]};4(d[1]==""){d[1]="*"};4(c==8){c="`"};4(b==8){b=E};K(d[2]){w"#":7=d[3].r(g);4(7==8){7=[8,d[3]]};e=E.L(7[1]);4(e==8||(d[1]!="*"&&!x(e,d[1]))){6 f};4(7.l==2){f.A(e);6 f};6 o(7[3],e,7[2]);w".":4(c!=">"){5=p(b,d[1])}y{5=b.B};n(i=0,h=5.l;i<h;i++){e=5[i];4(e.C!=1){q};7=d[3].r(g);4(7!=8){4(e.j==8||e.j.r("(\\\\s|^)"+7[1]+"(\\\\s|$)")==8){q};m=o(7[3],e,7[2]);f=f.v(m)}y 4(e.j!=8&&e.j.r("(\\\\s|^)"+d[3]+"(\\\\s|$)")!=8){f.A(e)}};6 f;w">":4(c!=">"){5=p(b,d[1])}y{5=b.B};n(i=0,h=5.l;i<h;i++){e=5[i];4(e.C!=1){q};4(!x(e,d[1])){q};m=o(d[3],e,">");f=f.v(m)};6 f;w"`":5=p(b,d[1]);n(i=0,h=5.l;i<h;i++){e=5[i];m=o(d[3],e,"`");f=f.v(m)};6 f;M:4(c!=">"){5=p(b,d[1])}y{5=b.B};n(i=0,h=5.l;i<h;i++){e=5[i];4(e.C!=1){q};4(!x(e,d[1])){q};f.A(e)};6 f}};k p(a,b){4(b=="*"&&a.F!=8){6 a.F};6 a.p(b)};k x(a,b){4(b=="*"){6 N};6 a.O.G().z("P:","")==b.G()};6 u}();k Q(a,b){9 c=u(a);n(9 i=0;i<c.l;i++){c[i].R=k(){4(t.j.H(b)==-1){t.j+=" "+b}};c[i].S=k(){4(t.j.H(b)!=-1){t.j=t.j.z(b,"")}}}}4(D.I&&!D.T){D.I("U",V)}', 58, 58, '||||if|listNodes|return|subselector|null|var||||||||limit||className|function|length|listSubNodes|for|doParse|getElementsByTagName|continue|match||this|parseSelector|concat|case|matchNodeNames|else|replace|push|childNodes|nodeType|window|document|all|toLowerCase|indexOf|attachEvent|split|switch|getElementById|default|true|nodeName|html|hoverForIE6|onmouseover|onmouseout|opera|onload|ieHover'.split('|'), 0, {}))
/*parametrs [selector, hover_class]*/
function ieHover() {
    hoverForIE6("#andnav li", "andhover");
}

/* Home sliders */

var slideHomerUl = false;
var slideHomes = 0;
var slideHomeWidth = 0;
var slideHomerPosition = 0;
var slideHomeIndex = 0;
var slideHomerWorking = false;

function initHomeSlider() {
    slideHomerUl = $('.andgallery .anditemlist');
    slideHomeWidth = slideHomerUl.children('li').width();
    slideHomes = slideHomerUl.children('li').length;

    $('.andgallery .andswitcher2 li a').click(function(evt) {
        evt.preventDefault();
        if (!slideHomerWorking) {
            var index = $(this).parent().index();
            if (slideHomeIndex != index) {
                $('.andswitcher2 li a.active').removeClass('active');
                $(this).addClass('active');

                if (index == 0) {
                    var moveTo = 0;
                }
                else {
                    var moveTo = '-' + slideHomeWidth * index;
                }

                slideHomerUl.animate({ left: moveTo + 'px' }, function() {
                    slideHomeIndex = index;
                    slideHomerWorking = false;
                });
            }
        }
    });
}


function initPopupOpen() {
    $('body').append('<div class="andlitebox2"></div>');

    $('.andlitebox1 .andclose, .andlitebox2 .andclose').live('click', function(evt) {
        evt.preventDefault();
        $('.andlitebox2').hide();
        $('.andlitebox1').hide();
        $('#overlay').hide();
    });

    $('.andlink2').live('click', function(evt) {
        evt.preventDefault();
        $('html, body').animate({ scrollTop: '0px' }, 'fast');
        $('.andlitebox1').show();
    });
}

function initTabset() {
    $('.andtabset a img').hover(function() {
        $(this).attr('src', $(this).attr('src').replace(/_off/i, "_on"));
    }, function() {
        $(this).attr('src', $(this).attr('src').replace(/_on/i, "_off"));
    });
}

function showOverlay() {
    if ($('#overlay').length == 0) {
        $('body').append('<div id="overlay"></div>');
    }
    var s = ___getPageSize();
    $('#overlay').css({ width: s[0], height: s[1] });
    $('#overlay').show();
}

function isNumeric(value) {
    if (value != null && !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}
/* Products sliders */

var sliderUl = false;
var slides = 0;
var slideWidth = 0;
var sliderPosition = 0;
var slideIndex = 0;
var sliderWorking = false;

function initSlider() {
    sliderUl = $('.andgallery-list');
    slideWidth = sliderUl.children('li').width();
    slides = sliderUl.children('li').length;


    var t = sliderUl.children('li').children().children('.text').html();
    $('.anddescription').html(t);

    sliderUl.children().children().children('img').each(function(i) {
        if (i > 0) $(this).attr('src', $(this).attr('src').replace(/_on/i, "_off"));
    });

    $('.andgallery-prod .andprev, .andgallery-prod .andnext').click(function(evt) {
        evt.preventDefault();
        if (!sliderWorking) {
            sliderWorking = true;
            lastIndex = slideIndex;
            if ($(this).is('.andprev') && sliderPosition < 0) {
                sliderPosition += slideWidth;
                slideIndex--;
            }
            else if ($(this).is('.andnext') && sliderPosition > ('-' + (slideWidth * slides - slideWidth))) {
                sliderPosition -= slideWidth;
                slideIndex++;
            }
            sliderUl.animate({ left: sliderPosition }, function() {
                sliderWorking = false;
            });

            img = sliderUl.children().children().eq(lastIndex).children('img');
            img.attr('src', img.attr('src').replace(/_on/i, "_off"));

            img = sliderUl.children().children().eq(slideIndex).children('img');
            img.attr('src', img.attr('src').replace(/_off/i, "_on"));

            t = sliderUl.children().children().eq(slideIndex).children('.text').html();
            $('.anddescription').html(t);
        }
    });
}

/* Video sliders */

var slideVideorUl = false;
var slideVideos = 0;
var slideVideoWidth = 0;
var slideVideorPosition = 0;
var slideVideoIndex = 0;
var slideVideorWorking = false;

function initVideoSlider() {

    slideVideorUl = $('.andcarousel .andcarousel-list');
    slideVideoWidth = slideVideorUl.children('li').width();
    slideVideos = slideVideorUl.children('li').length;

    $('.andcarousel .andswitcher2 li a').click(function(evt) {
        evt.preventDefault();
        if (!slideVideorWorking) {
            var index = $(this).parent().index();
            if (slideVideoIndex != index) {
                $('.andcarousel .andswitcher2 li a.active').removeClass('active');
                $(this).addClass('active');

                if (index == 0) {
                    var moveTo = 0;
                }
                else {
                    var moveTo = '-' + slideVideoWidth * index;
                }

                slideVideorUl.animate({ left: moveTo + 'px' }, function() {
                    slideVideoIndex = index;
                    slideVideorWorking = false;
                });
            }
        }
    });

    // On page load
    var navigation = ".andcarousel-list a";
    var url = document.location.toString();
    if (url.match('#')) {
        var anchor = url.split('#')[1];
        if (isNumeric(anchor)) {
            $(navigation + ':eq(' + anchor + ')').click();
            var pageIndex = Math.abs(((Math.abs(anchor))) / 4);
            $('.andcarousel .andswitcher2 li:eq(' + pageIndex + ') a').click();
        } else {
            if ($(navigation + ' a[href="#' + anchor + '"]').length > 0) {
                $(navigation + ' a[href="#' + anchor + '"]').click();
            } else {
                $(navigation + ':eq(0)').click();
            }
        }
    } else {
        $(navigation + ':eq(0)').click();
    }


}
/* Encode Search URL */
var UrlEncoding = {
    // public method for url encoding
    encode: function(string) { return escape(this._utf8_encode(string)); },
    // public method for url decoding
    decode: function(string) { return this._utf8_decode(unescape(string)); },
    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";
        for (var n = 0; n < string.length; n++) {
            var c = string.charCodeAt(n);
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
        }
        return utftext;
    },
    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while (i < utftext.length) {
            c = utftext.charCodeAt(i);
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
        }
        return string;
    }
}
/* Hover Color Effect on Brand Carousel */

var oldsrc;
function initBrandSlider() {
    $('#mycarousel').scrollingCarousel();
    $('.andlogo-brand img').bind('mouseover',
		function() {
		    oldsrc = $(this).attr('src');
		    $(this).attr('src', oldsrc.replace('_off', '_on'));
		}
	);
    $('.andlogo-brand img').bind('mouseout',
		function() {
		    $(this).attr('src', oldsrc);
		}
	);
}
/* Selection of Video */
$(document).ready(
    function() {
        var navigation = "ul.andcarousel-list li";
        var url = document.location.toString();
        if (url.match('#')) {
            var anchor = url.split('#')[1];
            //alert($(navigation + ' a[flashhref="#' + anchor + '"]').length);
            if ($(navigation + ' a[flashhref="#' + anchor + '"]').length > 0) {
                $(navigation + ' a[flashhref="#' + anchor + '"]').click();
            } else {
                $(navigation + ':eq(0)').click();
            }
        } else {
            $(navigation + ':eq(0)').click();
        }
    }
);

function initHistoryButtons() {
    var oldSrc = false;
    $('.historyButtons a').hover(function() {
        var i = $(this).children('img');
        i.attr('src', i.attr('src').replace(/_off/i, "_on"));
    }, function() {
        var i = $(this).children('img');
        i.attr('src', i.attr('src').replace(/_on/i, "_off"));
    });
}

function ___getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
    return arrayPageSize;
};


