$(document).ready(function() {
    $('a[rel="lightbox"]').unbind("click");
    $('a[rel="lightbox"]')
    .colorbox({
        maxWidth:800,
        maxHeight:600,
        iframe:true
    //        onCleanup:function(){
    //            console.log(this);
    //            }
    });
    $(window).bind('scroll', function() {
        var posY = $(window).scrollTop() + 20 + "px";

        $('#request_call').animate({
            'top' : posY
        }, 100);
    });
    $("#products-select").sexyCombo();
    //    $("select.ddl-products").bind('change',function(){
    //        $(this).val('');
    //    })
    Cufon.replace(".sIFR-h1");
    Cufon.replace(".sIFR-ModelName");
    Cufon.replace('.sIFR-Yellow');
    Cufon.replace('.promo-h1');
    Cufon.replace('.promo-h2');
    //
    ////, {color: '#232f84'});
    //Cufon.replace("h1.sIFR-ModelName", {color: '#464646'});
    //Cufon.replace("h1.sIFR-Yellow", {color: '#FCB131', fontWeight: 'bold'});

    //    var maxHeight = 0;
    //    $('.ntgrdiff-pan-red')
    //    .each(function(){
    //        if($(this).css('float')=='left'){
    //            if($(this).height()>maxHeight){
    //                maxHeight = $(this).height();
    //            }
    //        }
    //    });
    //    $('.ntgrdiff-pan-red')
    //    .each(function(){
    //        if($(this).css('float')=='left'){
    //            $(this).height(maxHeight);
    //        }
    //    })
//    $(document).snowfall({
//        flakeCount : 300,        //Количество снежинок на странице
//        flakeColor: '#ffffff', //Цвет снежинок
//        flakeIndex: 999999,     //CSS z-index снежинок
//        minSize: 1,            //Минмальный размер снежинки
//        maxSize: 3,            //Максимальный размер снежинки
//        minSpeed: 2,           //Минимальная скорость падения снежинки
//        maxSpeed: 3,           //Максимальная скорость падения снежинки
//        round: false,          //Круглые снежинки – true, квадратные - false
//        shadow: false         //Тень от снежинок
////        collection: '#nav'          //Класс или идентификатор элемента сверху которого будут оседать и скапливаться снежинки
//    });

});

function addFavorite(url, title) {
    // if firefox
    if (window.sidebar)
        window.sidebar.addPanel(title, url, "");
    // if IE
    else if (window.external)
        window.external.AddFavorite(url, title);
}

function popProduct(objSelect) {
    if (objSelect != null) {
        for (i = 0; i < objSelect.options.length; i++) {
            if (objSelect.options[i].selected) {
                if (objSelect.options[i].value != '') {
                    window.location = objSelect.options[i].value;
                }
            }
        }
    }
}
function popRequestCall() {
    if (location.href.search(/\?page=offer/) == -1) {
        if (!getCookie('dontShow')) {
            var posY = document.documentElement.scrollTop
            || document.body.scrollTop;
            // 			console.log($(window).scrollTop());
            // 			console.log(posY);
            $('#request_call').css({
                display : 'block',
                left : '20px',
                top : posY + 20 + 'px'
            });
        }

    }
}
function closePop() {
    setCookie('dontShow', true);
    document.getElementById("request_call").style.display = 'none';
}
// возвращает cookie если есть или undefined
function getCookie(name) {
    var matches = document.cookie
    .match(new RegExp("(?:^|; )"
        + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1')
        + "=([^;]*)"))
    return matches ? decodeURIComponent(matches[1]) : undefined
}

// уcтанавливает cookie
function setCookie(name, value, props) {
    props = props || {}
    var exp = props.expires
    if (typeof exp == "number" && exp) {
        var d = new Date()
        d.setTime(d.getTime() + exp * 1000)
        exp = props.expires = d
    }
    if (exp && exp.toUTCString) {
        props.expires = exp.toUTCString()
    }

    value = encodeURIComponent(value)
    var updatedCookie = name + "=" + value
    for (var propName in props) {
        updatedCookie += "; " + propName
        var propValue = props[propName]
        if (propValue !== true) {
            updatedCookie += "=" + propValue
        }
    }
    document.cookie = updatedCookie

}

// удаляет cookie
function deleteCookie(name) {
    setCookie(name, null, {
        expires : -1
    })
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function show_answ(id){
    $('.faq:visible').css('display','none');
    $('#'+id).css('display','block');
    return false;
}
function alignBlocks(blocks){
    var max=0;
    for(i in blocks){
        if($(blocks[i]).height()>max){
            max=$(blocks[i]).height();
        }
    }
    $(blocks.join()).height(max)
}

//function ntgrAlign(){
//    var hgt = 0;
//    $('div[class^="ntgrdiff-pan-"]').each(function(){
//        if($(this).height()>hgt){
//            hgt = $(this).height();
//        }
//    })
//    $('div[class^="ntgrdiff-pan-"]').height(hgt);
//}
