//if (!window.console || !console.firebug) { var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; window.console = {}; for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {} }
var debug = false;
function l(a){ if(console && debug) console.log(a); }


$(document).ready(function(){

    
   /* $("div.clist ul li").click(function(e){

        if($(e.target).parent().find("ul").length ){
        if( !$(this).hasClass("open")){
            $("div.clist ul li").removeClass("open");
            $(this).addClass("open"); //.find("ul").removeClass("hidden");
        }else if($(this).hasClass("open")){
            $(this).removeClass("open");//.find("ul").addClass("hidden");
        }

        return false;
        }
    });

     */

    /* block hightlight */
   $("div.block_hl").hover(function(){
        $(this).find(".nhl").show(); //css("opacity","1");
    },function(e){
        $(this).find(".nhl").hide(); //css("opacity","0");
    });
    /* END block hightlight */


    var last_screen_full = true;
    function resize_window(){
        /* TODO  ïîïðàâèòü â Îïåðå íåêîððåêòíî ñõëîïûâàåòñÿ â 1024 */
        if( $(window).width() >= 1200 && !last_screen_full){
            l("Set to full resolution");
            last_screen_full = true;
            $("body").removeClass("low");
        }

        if($(window).width() < 1200 && last_screen_full){
            l("Set to Low");
            last_screen_full = false;
            $("body").addClass("low");
        }
    }
    $(window).resize(resize_window);
    resize_window();






    $(".vote_switch").click(function(e){
        var value;
        $(this).find(".vote_switch_item").removeClass("selected");

        if($(e.target).is(".vote_switch_item")){
           $(e.target).addClass("selected");
            value = $(e.target).attr("id").substring(1);
        }else{
            if($(e.target).is(".vote_switch_item")){
                $(e.target).addClass("selected");
            }else{
                $(e.target).parent(".vote_switch_item").addClass("selected");
            }
            value = $(e.target).parent(".vote_switch_item").attr("id").substring(1);
        }
        l(value);
        $(this).find("input.vote_switch_input").val(value);
    });

(function($){
    $.dvshyph = {
        options: {
            shy: $('<i>&shy;</i>').html(),
            spec: '[éüú]', //"ñïåöèàëüíûå" áóêâû
            vovel: '[àåÞèîóûýþß]', //ãëàñíûå áóêâû
            consonant: '[áâãäæçêëìíïðñòôõö÷øù]', //ñîãëàñíûå áóêâû
            letters: '[üúéàåÞèîóûýþßáâãäæçéêëìíïðñòôõö÷øùúü]',
            rules: []
        },
        run: function(options) {
            var o = $.dvshyph.options;
            with(o) {
                rules = [ //íàáîð ïðàâèë (àëãîðèòì)
                    [consonant + vovel, vovel + letters],
                    [vovel + consonant, consonant + vovel],
                    [consonant + vovel, consonant + vovel],
                    [vovel + consonant, consonant + consonant + vovel],
                    [vovel + consonant + consonant, consonant + vovel],
                    [vovel + consonant + consonant, consonant + consonant + vovel],
                    [spec, letters + letters]
                ];
            };
            
            return this.each(function() {
                var obj  = $(this);
                var text = obj.html();
                
                for(var i = o.rules.length - 1; i >= 0; i--) {
                    var r = o.rules[i];
                    var regexp = new RegExp('(' + r[0] + ')(?=' + r[1] + ')', 'gi');
                    text = text.replace(regexp, '$1' + o.shy);
                }
                obj.html(text);
            });
        }
    };
    
    $.fn.hyph = $.dvshyph.run;
})(jQuery);
$('.testdrive_text').hyph();

});

