$(function() {
    startFrontpage()
});
mainMenu1Cur = 1;
var gsi = 1;
var s = 2200;
var cs = 220;
var __int = 4500;
var t = 0;
var cstop = 0;
var last = 5;
var first = 1;
var prev = a;
var maxN = 3;
var speed = 100;
var cl = true;
var inviteBlock = 0;
$(document).ready(function() {
    $("#gsn_" + gsi).addClass("grande_spot_nav_activ");
    if (ma > 5) {
        $(".mini_spot_l_h").click(function() {
            miniSpot2("right")
        });
        $(".mini_spot_r_h").click(function() {
            miniSpot2("left")
        });
        $(".menu_2_tab_1").click(function() {
            menu2Slide(1)
        });
        $(".menu_2_tab_2").click(function() {
            menu2Slide(2)
        })
    }
    $("#znikaj").fadeOut(3000);
    $(".grande_spot_nav").click(function() {
        grandeClick($(this).attr("id"))
    });
    if (a > 1) {
        t = setTimeout("grandeSpot(a,0)", __int);
        $(".grande_spot_holder").hover(function() {
            grandeSpotStop()
        },
        function() {
            grandeSpotGo()
        })
    }
    $(".mini_spot_item_13,.mini_spot_item_12").hover(function() {
        $(this).fadeTo(1, 0.9)
    },
    function() {
        $(this).fadeTo(1, 1)
    });
    $(".grande_spot_holder").hover(function() {
        $(".grande_spot_image").fadeTo(90, 0.93)
    },
    function() {
        $(".grande_spot_image").fadeTo(90, 1)
    });
    $(".for_you_arow").click(function() {
        menuSlide(2)
    });
    $(".was_arow").click(function() {
        menuSlide(1)
    });
    $("#nP1").keyup(function(A) {
        if (A.keyCode == 13) {
            $("#nP2").focus()
        }
    });
    $("#nP2").keyup(function(A) {
        if (A.keyCode == 13) {
            proceedReset()
        }
    });
});
function menuSlide(A) {
    if (A == 1) {
        $(".menu_1_w").animate({
            left: "-236px"
        },
        200);
        $(".menu_1_r").animate({
            left: "0px"
        },
        200)
    }
    if (A == 2) {
        $(".menu_1_w").animate({
            left: "0px"
        },
        200);
        $(".menu_1_r").animate({
            left: "236px"
        },
        200)
    }
}
function startFrontpage() {
    $(".grande_spot_nav").click(function() {
        grandeClick($(this).attr("id"))
    });
    $("#gsn_" + gsi).addClass("grande_spot_nav_activ");
    $(".r_n_holder").click(function() {
        lng = $("#lng").val();
        window.top.location = "/" + lng + "/frontpage/rss"
    });
    $(".grande_spot_nav").css("cursor", "pointer")
}


function miniSpot2(A) {
    if (cstop == 0) {
        cstop = 1;
        if (A == "right") {
            $('<div id="m_a_2" class="mini_spot_set m_h" style="left: 965px;"></div>').insertAfter("#m_act");
            for (i = 1; i <= 5; i++) {
                if (last >= ma) {
                    last = 0
                }
                nexte = ++last;
                if (i == 3 || i == 4) {
                    pos = (i - 1) * 193 - 1;
                    $("#m_a_2").append($("#msimg_" + nexte).clone(true).attr("id", "ms_" + i).css("left", pos + "px"))
                }
                if (i == 5) {
                    pos = (i - 1) * 193 - 2;
                    $("#m_a_2").append($("#msimg_" + nexte).clone(true).attr("id", "ms_" + i).css("left", pos + "px"))
                } else {
                    pos = (i - 1) * 193;
                    $("#m_a_2").append($("#msimg_" + nexte).clone(true).attr("id", "ms_" + i).css("left", pos + "px"))
                }
            }
            if ((last - 4) >= 1) {
                first = last - 4
            } else {
                first = ma + (last - 4)
            }
            $("#m_act").fadeOut(100,
            function() {
                $("#m_a_2").show();
                $(this).remove();
                $("#ms_1").fadeIn(speed,
                function() {
                    $("#ms_2").fadeIn(speed,
                    function() {
                        $("#ms_3").fadeIn(speed,
                        function() {
                            $("#ms_4").fadeIn(speed,
                            function() {
                                $("#ms_5").fadeIn(speed,
                                function() {
                                    $("#m_a_2").attr("id", "m_act");
                                    cstop = 0
                                })
                            })
                        })
                    })
                })
            })
        }
        if (A == "left") {
            $('<div id="m_a_2" class="mini_spot_set m_h" style="left: 965px;"></div>').insertAfter("#m_act");
            for (i = 1; i <= 5; i++) {
                if (last >= ma) {
                    last = 0
                }
                nexte = ++last;
                if (i == 3 || i == 4) {
                    pos = (i - 1) * 193 - 1;
                    $("#m_a_2").append($("#msimg_" + nexte).clone(true).attr("id", "ms_" + i).css("left", pos + "px"))
                }
                if (i == 5) {
                    pos = (i - 1) * 193 - 2;
                    $("#m_a_2").append($("#msimg_" + nexte).clone(true).attr("id", "ms_" + i).css("left", pos + "px"))
                } else {
                    pos = (i - 1) * 193;
                    $("#m_a_2").append($("#msimg_" + nexte).clone(true).attr("id", "ms_" + i).css("left", pos + "px"))
                }
            }
            if ((last - 4) >= 1) {
                first = last - 4
            } else {
                first = ma + (last - 4)
            }
            $("#m_act").fadeOut(100,
            function() {
                $("#m_a_2").show();
                $(this).remove();
                $("#ms_5").fadeIn(speed,
                function() {
                    $("#ms_4").fadeIn(speed,
                    function() {
                        $("#ms_3").fadeIn(speed,
                        function() {
                            $("#ms_2").fadeIn(speed,
                            function() {
                                $("#ms_1").fadeIn(speed,
                                function() {
                                    $("#m_a_2").attr("id", "m_act");
                                    cstop = 0
                                })
                            })
                        })
                    })
                })
            })
        }
    }
}
function miniSpot(A) {
    if (cstop == 0) {
        cstop = 1;
        if (A == "left") {
            $('<div id="l_next" class="mini_spot_set" style="left: 1930px;"></div>').insertAfter("#m_act");
            for (i = 1; i <= 5; i++) {
                if (last >= ma) {
                    last = 0
                }
                nexte = ++last;
                $("#l_next").append($("#msimg_" + nexte).clone(true))
            }
            if ((last - 4) >= 1) {
                first = last - 4
            } else {
                first = ma + (last - 4)
            }
            $("#m_act").animate({
                left: 0
            },
            speed,
            function() {
                $(this).remove()
            });
            $("#l_next").animate({
                left: 965
            },
            speed,
            function() {
                $(this).attr("id", "m_act");
                cstop = 0
            })
        }
        if (A == "right") {
            $('<div id="r_next" class="mini_spot_set" style="left: 0px;"></div>').insertBefore("#m_act");
            for (i = 5; i >= 1; i--) {
                if (first == 1) {
                    first = (ma + 1)
                }
                nexte = --first;
                $("#r_next").prepend($("#msimg_" + nexte).clone(true))
            }
            if ((first + 4) <= ma) {
                last = first + 4
            } else {
                last = first + 4 - ma
            }
            $("#m_act").animate({
                left: 1930
            },
            speed,
            function() {
                $(this).remove()
            });
            $("#r_next").animate({
                left: 965
            },
            speed,
            function() {
                $(this).attr("id", "m_act");
                cstop = 0
            })
        }
    } else {}
}

function grandeSpot(B, A) {
    if (B > 1) {
        if (A > 0) {
            if (c == gsi) {} else {
                prev = gsi;
                next = A;
                $("#gs_" + next).clone(true).attr("id", "gsv_" + next).insertBefore("#gsv_" + prev);
                $("#gsv_" + prev).fadeOut(cs).queue(function() {
                    $(this).remove()
                });
                setTimeout("$('.grande_spot_nav').removeClass(\"grande_spot_nav_activ\")", cs / 2);
                setTimeout("$('#gsn_'+next).addClass(\"grande_spot_nav_activ\")", cs / 2);
                gsi = next;
                t = setTimeout("grandeSpot(a,0)", __int)
            }
        } else {
            if (gsi >= B) {
                prev = B;
                next = 1;
                gsi = 1
            } else {
                prev = gsi;
                next = gsi + 1
            }
            $("#gs_" + next).clone(true).attr("id", "gsv_" + next).insertBefore("#gsv_" + prev);
            $("#gsv_" + prev).fadeOut(s).queue(function() {
                $(this).remove()
            });
            setTimeout("$('.grande_spot_nav').removeClass(\"grande_spot_nav_activ\")", s / 2);
            setTimeout("$('#gsn_'+next).addClass(\"grande_spot_nav_activ\")", s / 2);
            gsi = next;
            t = setTimeout("grandeSpot(a,0)", __int)
        }
    }
}
function grandeSpotStop() {
    pr = $("#gsv_" + prev).css("opacity");
    if (pr != null) {
        if (pr < 0.4) {
            $("#gsv_" + prev).stop()
        } else {
            grandeClick("gsn_" + prev)
        }
    }
    clearTimeout(t)
}
function grandeSpotGo() {
    t = setTimeout("grandeSpot(a,0)", __int)
}
function grandeClick(A) {
    clearTimeout(t);
    c = parseInt(A.replace("gsn_", ""));
    grandeSpot(a, c)
}