function reloadPage(){
    $("body").css("display", "inline").css("display", "block");
}

function initCounters(){
    if ($("#counters img").size() > 0) {
        $("#counters img").fadeTo(1, 0.3);
        $("#counters img").hover(function(){
            $(this).fadeTo(200, 1);
        }, function(){
            $(this).fadeTo(200, 0.3);
        });
    }
}

function initFade(){
    $("#rss img").fadeTo(1, 1);
    $("#rss img").hover(function(){
        $(this).fadeTo(100, 0.5);
    }, function(){
        $(this).fadeTo(100, 1);
    });
    $("#widgets img").fadeTo(1, 1);
    $("#widgets img").hover(function(){
        $(this).fadeTo(100, 0.5);
    }, function(){
        $(this).fadeTo(100, 1);
    });


    $("#blogs_n_news img").fadeTo(1, 1);
    $("#blogs_n_news img").hover(function(){
        $(this).fadeTo(100, 0.5);
    }, function(){
        $(this).fadeTo(100, 1);
    });
    
    $("#audio_podcast img").fadeTo(1, 1);
    $("#audio_podcast img").hover(function(){
        $(this).fadeTo(100, 0.5);
    }, function(){
        $(this).fadeTo(100, 1);
    });    

    $(".BlogsSidebar img").fadeTo(1, 1);
    $(".BlogsSidebar img").hover(function(){
        $(this).fadeTo(100, 0.5);
    }, function(){
        $(this).fadeTo(100, 1);
    });

    $("#matrix img").fadeTo(1, 1);
    $("#matrix img").hover(function(){
        $(this).fadeTo(100, 0.5);
    }, function(){
        $(this).fadeTo(100, 1);
    });
}

function initBlogsAndNews(){
    if ($("#blogs_n_news").size() > 0) {
        $("#blogs_n_news").hover(function(){
            $(this).find('div#blogs_list').fadeIn(200);
        }, function(){
            $(this).find('div#blogs_list').fadeOut(100);
        });
    }
}

function initCategories(){
    if ($(".widget_categories ul li").size() > 0) {
        $(".widget_categories ul li a").hover(function(){
            $(this).find("i").animate({
                left: "0px"
            }, 300);
        }, function(){
            $(this).find("i").animate({
                left: "-185px"
            }, 150);


        });
    }
}



function initSIFR(){
    sIFR.replaceElement(named({
        sSelector: "h1",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond-bold.swf",
        sColor: "#FFFFFF",
        sBgColor: "#000000",
        sLinkColor: "#FFFFFF",
        sHoverColor: "#D40064",
        sWmode: "transparent"
    }));
    sIFR.replaceElement(named({
        sSelector: "h3",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond.swf",
        sColor: "#FFC924",
        sBgColor: "#000000",
        sWmode: "transparent"
    }));
    sIFR.replaceElement(named({
        sSelector: "div.geek1 div.link",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond.swf",
        sColor: "#D40064",
        sBgColor: "#000000",
        sLinkColor: "#D40064",
        sHoverColor: "#FFFFFF",
        sWmode: "transparent",
        sFlashVars: "textalign=center"
    }));
    sIFR.replaceElement(named({
        sSelector: "div.geek2 div.link",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond.swf",
        sColor: "#B4E800",
        sBgColor: "#000000",
        sLinkColor: "#B4E800",
        sHoverColor: "#FFFFFF",
        sWmode: "transparent",
        sFlashVars: "textalign=center"
    }));
    sIFR.replaceElement(named({
        sSelector: "div.geek3 div.link",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond.swf",
        sColor: "#30B2FF",
        sBgColor: "#000000",
        sLinkColor: "#30B2FF",
        sHoverColor: "#FFFFFF",
        sWmode: "transparent",
        sFlashVars: "textalign=center"
    }));
    sIFR.replaceElement(named({
        sSelector: "div.geek4 div.link",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond.swf",
        sColor: "#C089FF",
        sBgColor: "#000000",
        sLinkColor: "#C089FF",
        sHoverColor: "#FFFFFF",
        sWmode: "transparent",
        sFlashVars: "textalign=center"
    }));
    sIFR.replaceElement(named({
        sSelector: "div.geek5 div.link",
        sFlashSrc: "/wp-content/themes/4geeks/js/myriad-cond.swf",
        sColor: "#FFC924",
        sBgColor: "#000000",
        sLinkColor: "#FFC924",
        sHoverColor: "#FFFFFF",
        sWmode: "transparent",
        sFlashVars: "textalign=center"
    }));
}

function eCheck(str){
    var at = "@";
    var dot = ".";
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
    if (str.indexOf(at) == -1) {
        return false;
    }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false;
    }
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false;
    }
    if (str.indexOf(at, (lat + 1)) != -1) {
        return false;
    }
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false;
    }
    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false;
    }
    if (str.indexOf(" ") != -1) {
        return false;
    }
    return true
}

function validateMail(current, openPopup){
    var emailID = $("#" + current + " input.mail");
    var subMSG = $("#" + current + " label.message");

    if ((emailID.val() == "Ваш e-mail") || (emailID.val() == null) || (emailID.val() == "")) {
        emailID.focus();
        subMSG.removeClass("sucess");
        subMSG.addClass("error").html("<strong>ОШИБКА</strong>: Не введен e-mail адрес.");
        return false;
    }
    else {
        if (eCheck(emailID.val()) == false) {
            emailID.focus();
            subMSG.removeClass("sucess");
            subMSG.addClass("error").html("<strong>ОШИБКА</strong>: E-mail адрес введен неверно.");
            return false;
        }
    }
    if (openPopup) {
        window.open('http://feedburner.google.com/fb/a/mailverify?uri=4geeks/mCVL', 'popupwindow', 'scrollbars=yes,width=600,height=500,top=100,left=100');
    }
    return true;
}

function validateSearch(current){
    var searchString = $("#" + current + " input#s");
    if ((searchString.val() == "что ищем?") || (searchString.val() == null) || (searchString.val() == "")) {
        searchString.focus();
        return false;
    }
    return true;
}

function validateComment(current){
    var commentNode = $("#comment");
    var captchaNode = $("#captcha");
    var messageNode = $("#comments label.message");

    if ((commentNode.val() == "Что скажешь?") || (commentNode.val() == null) || (commentNode.val() == "")) {
        $(messageNode).addClass("error").show().html("Введите сообщение.");
        reloadPage();
        commentNode.focus();
        return false;
    }
    if (commentNode.val().indexOf("<") >= 0) {
        $(messageNode).addClass("error").show().html("HTML-тэги запрещены.");
        reloadPage();
        commentNode.focus();
        return false;
    }
    if ((captchaNode.val() == "")) {
        $(messageNode).addClass("error").show().html("Введите защитный код.");
        reloadPage();
        captchaNode.focus();
        return false;
    }
    return true;
}

function validateRegistration(current){
    var subMSG = $("#" + current + " label.message");
    var stat = true;
    $("#" + current + " input.text").removeClass("error").each(function(){
        if (($(this).val() == null) || ($(this).val() == "")) {
            $(this).addClass("error").focus();
            subMSG.addClass("error").html("<strong>ОШИБКА</strong>: Не заполнено поле '" + $(this).attr("title") + "'.");
            stat = false;
            return false;
        }
        if ((eCheck($(this).val()) == false) && ($(this).attr("id").indexOf("mail") > 0)) {
            $(this).addClass("error").focus();
            subMSG.addClass("error").html("<strong>ОШИБКА</strong>: Поле '" + $(this).attr("title") + "' заполнено неверно.");
            stat = false;
            return false;
        }
        return true;
    });
    /*if (($("#user_email").val() != $("#user_email_repeat").val()) && (stat)) {
        $(".user_email").addClass("error").get(0).focus();
        subMSG.addClass("error").html("<strong>ОШИБКА</strong>: Адреса e-mail не совпадают.");
        stat = false;
    } */
    if (($("#pass1").val() != $("#pass2").val()) && (stat)) {
        $(".user_password").addClass("error").get(0).focus();
        subMSG.addClass("error").html("<strong>ОШИБКА</strong>: Пароли не совпадают.");
        stat = false;
    }
    return stat;
}

function initRegistration(){
    function compareMail(){
        if (($("#user_email").val() == $("#user_email_repeat").val()) && ($("#user_email").val() != "")) {
            $("div.user_email").removeClass("invalid").addClass("valid");
        }
        else {
            $("div.user_email").addClass("invalid").removeClass("valid");
        }
    }

    function comparePass(){
        if (($("#pass1").val() == $("#pass2").val()) && ($("#pass1").val() != "")) {
            $("div.user_password").removeClass("invalid").addClass("valid");
        }
        else {
            $("div.user_password").addClass("invalid").removeClass("valid");
        }
    }

    if ($("#registerform").size() > 0) {
        $("#registerform input.user_email").keyup(compareMail);
        $("#registerform input.user_password").keyup(comparePass);
    }
}


function verify(url, text){
    if (text == '') {
        text = 'Вы точно хотите удалить этот комментарий?';
    }
    if (confirm(text)) {
        document.location = url;
    }
    return void (0);
}


function initWall(){
    if ($("#wallform").size() > 0) {
        $("#wallform").ajaxForm({
            target: "#wallcomments",
            success: function(responseText, statusText){
                $("#wallresponse").html('<span class="wall-success">' + 'Ваше сообщение опубликовано!' + '</span>');
                $('.wp_wall .preloader').hide();
                $(".wp_wall").each(function(){
                    $("#wallcomments").jScrollPane({
                        showArrows: true,
                        scrollbarWidth: 19
                    });
                });
            },
            error: function(request){
                var data = request.responseText.match(/<p>(.*)<\/p>/);
                $('#wallresponse').html('<span class="wall-error">' + data[1] + '</span>');
                $('.wp_wall .preloader').hide();
            },
            beforeSubmit: function(){
                $('#wallresponse').empty();
                var msgID = $('#wpwall_comment');
                if ((msgID.val() == "Ваше сообщение") || (msgID.val() == null) || (msgID.val() == "")) {
                    $(msgID).focus();
                    $('#wallresponse').html('<span class="wall-error">Введите сообщение.</span>');
                    return false;
                }
                else {
                    $('.wp_wall .preloader').show();
                }
            }
        });
    }

    if ($(".wp_wall").size() > 0) {
        refreshtime = parseInt(WPWallSettings.refreshtime);
        if (refreshtime) {
            timeoutID = setInterval(refresh, (refreshtime < 5000) ? 5000 : refreshtime);
        }

        function refresh(){
            var wallform = $('#wallform');
            var page = $('#wallcomments #page');
            if (wallform[0]) {
                $('#wallcomments').load(wallform[0].action + '?refresh=' + page[0].value);
            }
        }
    }
}


function initBookmarks(){
    if ($("#bookmark").size() > 0) {
        $("#bookmark").hover(function(){
            $(this).find('div#sharepage').fadeIn(200);
        }, function(){
            $(this).find('div#sharepage').fadeOut(100);
        });
    }
}

function matrix_reload(){
    $("#reload_matrix").click(function(){
        $("#reload_matrix").fadeOut("slow");
	$("#matrix_table").slideToggle("slow");
        $(".tooltip_image").remove();
        $("#matrix_table").load("/ajax.php");
        $("#matrix_table").slideToggle("slow");
        $("#reload_matrix").fadeIn(2000);
        t = setTimeout(function(){
            initFade();
            matrix_tooltip('.prev_image a', 'tooltip_image', 'rel');
        }, 2000);

 });

}

function matrix_tooltip(selector, selectname, atrribute){
$(selector).each(function(i){
			if ($(this).attr(atrribute) != ""){
			$("body").append("<div class='"+selectname+"' id='"+selectname+i+"'><div><img class='tooltipimg' src='"+$(this).attr(atrribute)+"' alt='' /></div></div>");

			$(this).removeAttr(atrribute).mouseover(function(e){
					$("#"+selectname+i).css({display:"none", visibility:"visible"}).fadeTo(400,1).fadeIn(200);
			}).mousemove(function(e){
					$("#"+selectname+i).css({left:e.pageX+15, top:e.pageY+15});
			}).mouseout(function(){
					$("#"+selectname+i).css({display:"none", visibility:"hidden"});
			});


			}
		});
 	}


$(document).ready(function(){
	matrix_tooltip('.prev_image a', 'tooltip_image', 'rel');
    //$.get("/counter.php", function(data){if ($('#counts').size() > 0) {$('#counts').prepend(data);}});
    initSIFR();
    initFade();
    initCounters();
    initCategories();
    initRegistration();
    initWall();
    initBookmarks();
    initBlogsAndNews();
    matrix_reload();
    $(".arrowBack").each(function(){
        $("#innerlogo").mouseover(function(){
            $(".arrowBack").show();
        })
        $("#innerlogo").mouseout(function(){
            $(".arrowBack").hide();
        })
    });
    $(".wp_wall").each(function(){
        $("#wallcomments").jScrollPane({
            showArrows: true,
            scrollbarWidth: 19
        });
    });
    $(".widget_comments").each(function(){
        if ($(".widget_comments .area").height() > 400) {
            $(".widget_comments .area").height(400).jScrollPane({
                showArrows: true,
                scrollbarWidth: 19
            });
            reloadPage();
        }
    });

})










/*
 +----------------------------------------------------------------+
 |																							|
 |	WordPress 2.5 Plugin: WP-Polls 2.31										|
 |	Copyright (c) 2008 Lester "GaMerZ" Chan									|
 |																							|
 |	File Written By:																	|
 |	- Lester "GaMerZ" Chan															|
 |	- http://lesterchan.net															|
 |																							|
 |	File Information:																	|
 |	- Polls Javascript File															|
 |	- wp-content/plugins/wp-polls/polls-js.js									|
 |																							|
 +----------------------------------------------------------------+
 */
// Variables
var polls = new sack(polls_ajax_url);
var poll_id = 0;
var poll_answer_id = "";
var poll_fadein_opacity = 0;
var poll_fadeout_opacity = 100;
var is_ie = (document.all && document.getElementById);
var is_moz = (!document.all && document.getElementById);
var is_opera = (navigator.userAgent.indexOf("Opera") > -1);
var is_being_voted = false;

// Function: When User Vote For Poll
function poll_vote(current_poll_id){
    if (!is_being_voted) {
        is_being_voted = true;
        poll_id = current_poll_id;
        poll_form = document.getElementById('polls_form_' + poll_id);
        poll_answer = eval("poll_form.poll_" + poll_id);
        poll_answer_id = "";
        if (document.getElementById('poll_multiple_ans_' + poll_id)) {
            poll_multiple_ans = parseInt(document.getElementById('poll_multiple_ans_' + poll_id).value);
        }
        else {
            poll_multiple_ans = 0;
        }
        poll_multiple_ans_count = 0;
        if (poll_answer.length != null) {
            for (i = 0; i < poll_answer.length; i++) {
                if (poll_answer[i].checked) {
                    if (poll_multiple_ans > 0) {
                        poll_answer_id = poll_answer[i].value + "," + poll_answer_id;
                        poll_multiple_ans_count++;
                    }
                    else {
                        poll_answer_id = parseInt(poll_answer[i].value);
                    }
                }
            }
        }
        else {
            poll_answer_id = poll_answer.value;
        }
        if (poll_multiple_ans > 0) {
            if (poll_multiple_ans_count > 0 && poll_multiple_ans_count <= poll_multiple_ans) {
                poll_answer_id = poll_answer_id.substring(0, (poll_answer_id.length - 1));
                poll_loading_text();
                poll_process();
            }
            else
                if (poll_multiple_ans_count == 0) {
                    is_being_voted = false;
                    alert(polls_text_valid);
                }
                else {
                    is_being_voted = false;
                    alert(polls_text_multiple + " " + poll_multiple_ans + ".");
                }
        }
        else {
            if (poll_answer_id > 0) {
                poll_loading_text();
                poll_process();
            }
            else {
                is_being_voted = false;
                alert(polls_text_valid);
            }
        }
    }
    else {
        alert(polls_text_wait);
    }
    return false;
}

// Function: When User View Poll's Result
function poll_result(current_poll_id){
    if (!is_being_voted) {
        is_being_voted = true;
        poll_id = current_poll_id;
        poll_loading_text();
        poll_process_result();
    }
    else {
        alert(polls_text_wait);
    }
    return false;
}

// Function: When User View Poll's Voting Booth
function poll_booth(current_poll_id){
    if (!is_being_voted) {
        is_being_voted = true;
        poll_id = current_poll_id;
        poll_loading_text();
        poll_process_booth();
    }
    else {
        alert(polls_text_wait);
    }
    return false;
}

// Function: Poll Fade In Text
function poll_fadein_text(){
    if (poll_fadein_opacity == 90) {
        poll_unloading_text();
    }
    if (poll_fadein_opacity < 100) {
        $('#polls-' + poll_id + '-ans').slideDown(350);
        poll_fadein_opacity = 100;
        poll_unloading_text();
        setTimeout("poll_fadein_text()", 100);
    }
    else {
        poll_fadein_opacity = 100;
        is_being_voted = false;
    }
    return false;
}

// Function: Poll Loading Text
function poll_loading_text(){
    if (poll_show_loading) {
        document.getElementById('polls-' + poll_id + '-loading').style.display = 'block';
    }
}

// Function: Poll Finish Loading Text
function poll_unloading_text(){
    if (poll_show_loading) {
        document.getElementById('polls-' + poll_id + '-loading').style.display = 'none';
    }
}

// Function: Process The Poll
function poll_process(){
    if (poll_fadeout_opacity > 0) {
        $('#polls-' + poll_id + '-ans').slideUp(350);
        poll_fadeout_opacity = 0;
        setTimeout("poll_process()", 100);
    }
    else {
        poll_fadeout_opacity = 0;
        polls.reset();
        polls.setVar("vote", true);
        polls.setVar("poll_id", poll_id);
        polls.setVar("poll_" + poll_id, poll_answer_id);
        polls.method = 'POST';
        polls.element = 'polls-' + poll_id + '-ans';
        polls.onCompletion = poll_fadein_text;
        polls.runAJAX();
        poll_fadein_opacity = 0;
        poll_fadeout_opacity = 100;
    }
    return false;
}

// Function: Process Poll's Result
function poll_process_result(){
    if (poll_fadeout_opacity > 0) {
        $('#polls-' + poll_id + '-ans').slideUp(350);
        poll_fadeout_opacity = 0;
        setTimeout("poll_process_result()", 100);
    }
    else {
        poll_fadeout_opacity = 0;
        polls.reset();
        polls.setVar("pollresult", poll_id);
        polls.method = 'GET';
        polls.element = 'polls-' + poll_id + '-ans';
        polls.onCompletion = poll_fadein_text;
        polls.runAJAX();
        poll_fadein_opacity = 0;
        poll_fadeout_opacity = 100;
    }
    return false;
}

// Function: Process Poll's Voting Booth
function poll_process_booth(){
    if (poll_fadeout_opacity > 0) {
        $('#polls-' + poll_id + '-ans').slideUp(350);
        poll_fadeout_opacity = 0;
        setTimeout("poll_process_booth()", 100);
    }
    else {
        poll_fadeout_opacity = 0;
        polls.reset();
        polls.setVar("pollbooth", poll_id);
        polls.method = 'GET';
        polls.element = 'polls-' + poll_id + '-ans';
        polls.onCompletion = poll_fadein_text;
        polls.runAJAX();
        poll_fadein_opacity = 0;
        poll_fadeout_opacity = 100;
    }
    return false;
}

// Function: Disable Poll's Voting Booth
function poll_disable_voting(current_poll_id){
    poll_form = document.getElementById('polls_form_' + current_poll_id);
    for (i = 0; i < poll_form.length; i++) {
        poll_form[i].disabled = true;
    }
}
