var wh = 0, ww = 0, ci = 0, ni = -1, cw = "";
var end = 0;
var enable = true;
var dy = 175;

jQuery(document).ready(function () {



    $("#radial_container").radmenu({

        radius: 250, // radius in pixels
        animSpeed: 100, // animation speed in millis
        centerX: 0, // the center x axis offset
        centerY: 0, // the center y axis offset
        selectEvent: "click", // the select event (click)

        rotate: true,
        angleOffset: 0, // in radians
        onSelect: function (jselected) { // show what is returned 
            //jQuery(".start-intro").hide();
            //jQuery(".radial-background").addClass("slide");
            //jQuery("body").addClass("open-wheel");
            //jQuery(".awesome.awesome-grey.middle").addClass("open");
            if (jselected.index() != 0) {
                var offset = jselected.index();
                var _len = jselected.siblings().andSelf().length;
                var _mid = Math.floor((_len * 100) / 200);
                var isNext = offset > _mid;
                if (isNext) offset = Math.abs(_len - offset);
                while (offset > 0) {
                    jQuery("#radial_container").radmenu(isNext ? "next" : "prev");
                    offset -= 1;
                }
            }

            //
            showContent(jselected.children("div").text());
        },



        onShow: function (jMenuitems) {
            jQuery("#radial_container").radmenu();
            jMenuitems.each(function (i) {
                var jthis = jQuery(this);
                var scale = i == jMenuitems.length - 1;
                setTimeout(function () {
                    jthis.fadeIn(1000).css("z-index", 100 - i);
                });
                $('.radial_div_item:first').addClass('active')
            });
        },
        scaleAnimSpeed: 200,
        onScaleItem: function (jitem, factor, coords) {
            if (factor > 0.00001)
                jQuery(".my_class").css("opacity", factor);
        },
        initialScale: 1,
        angleOffset: 0
    }).radmenu("show");

    $(document).bind("keyup", function (evt) {
        var keycode = window.event ? window.event.keyCode : evt.which;
        var tab_key = "";
        switch (keycode) {
            case 13: //enter
                var item = jQuery(".radial_div_item.active");
                if (!item.length) item = jQuery(".radial_div_item:first-child");
                item.click();
                tab_key = "open/close";
                break;
            case 37: // left
                jQuery("#radial_container").find(".radial_div_item:last-child").click();
                tab_key = "prev";
                break;
            case 39: // right
                jQuery("#radial_container").find(".radial_div_item.active").next().click();
                tab_key = "next";
                break;
            default:
                break;
        };
    });

    //-- right block



    rightBlock();
    goToPoint();
    goToPointWord();
    $(window).resize(function () {
        rightBlock();
        var point = wh / 2 - $("div.jump img").eq(ci).height() / 2;
        $("div.jump img").eq(ci).css("top", point);
        var point2 = wh / 2 - $("div.e-word[title=" + cw + "]").height() / 2 + dy;
        $("div.e-word[title=" + cw + "]").css("top", point2);
    });



    function rightBlock() {
        var win = $(window);
        wh = win.height();
        ww = win.width();
        $("div.right-block").height(wh);
        $("div.jump").height(wh);
        $("div.jump img").css({ "position": "absolute", "top": wh });
        $("div.e-word").css({ "position": "absolute", "top": wh });
        $("#flashContent").css({ "position": "absolute", "top": wh });
        $("div.content-wrapper").css("top", wh / 2 - $("div.content-wrapper").height() / 2);
        $("#flashContent").css("top", wh / 2 - $("#flashContent").height() / 2);


    }

    end = $("div.jump img").size() - 1;
    $("div.top-arrow").click(function () {

        if (enable) {
            enable = false;
            ni = ci == end ? 0 : (ci + 1);
            goToPoint(1);
        }
    });

    $("div.bottom-arrow").click(function () {
        if (enable) {
            enable = false;
            ni = ci == 0 ? end : (ci - 1);
            goToPoint(0);
        }
    });



    //-- end right block





});






function goToPoint() {
        var $cimg = $("div.jump img").eq(ci);
        //$cimg.stop();

        if (ni != -1) {
            var $nimg = $("div.jump img").eq(ni);
            if ($nimg.position()["top"] == -$nimg.height()) { $nimg.css("top", wh); }
            $cimg.animate({ "top": -$cimg.height() }, 200, function () {
                $nimg.animate({ "top": wh / 2 - $nimg.height() / 2 }, 2500, 'easeOutElastic', function () {
                    enable = true;
                });
            });
            ci = ni;
        } else {        
            $cimg.animate({ "top": wh / 2 - $cimg.height() / 2 }, 2500, 'easeOutElastic'); }
    }

function goToPointWord(t) {
        var $cw;
        if (cw != "") {
            if (cw != t) {
                $cw = $("div.e-word[title=" + cw + "]");
                $cw.stop();
                var $nw = $("div.e-word[title=" + t + "]");
                if ($nw.position()["top"] == -$nw.height()) { $nw.css("top", wh); }
                $cw.animate({ "top": -$cw.height() }, 200, function () {
                    $nw.animate({ "top": wh / 2 - $nw.height() / 2 + dy }, 2500, 'easeOutElastic', function () {
                        enable = true;
                    });
                });
                cw = t;
            }
        } else { $cw = $("div.e-word").eq(0); cw = $cw.attr("title"); $cw.animate({ "top": wh / 2 - $cw.height() / 2 + dy }, 2500, 'easeOutElastic'); }
    }

function showContent(n) {
        //var f = $("div.e-word").size() - 1;
        nw = n; //cw == f ? 0 : (cw + 1);       
        goToPointWord(n);
        if (enable) {
            enable = false;
            ni = ci == end ? 0 : (ci + 1);
            goToPoint();
        }
		var $cur = $(("#" + n));
              //alert(n + ".html");
        $("div.content-wrapper div.contant-item").load(n + ".html", function () {
		$("div.content-wrapper").css("top", wh / 2 - $cur.height() / 2);            
        });

		};
		
        //var $cur = $(("#" + n));
//        $("div.content-wrapper div.contant-item").each(function () {
//            if (!$(this).is(":hidden")) {
//                if ($cur.text()) {
//		
//                    $(this).fadeOut(200, function () {
//                        if ($cur.is(":hidden")) {
//$("div.content-wrapper").css("top", wh / 2 - $cur.height() / 2);
// $cur.fadeIn(200, function(){}); }
//                    });
//                }
//            }
//        });




