$(document).ready(function() {

    $(".menuitem").hover(function() {

        var target = $(this).attr("target");
        hideAllMenu();

        $(this).addClass('selected');
        $("#" + target).css("top", $(this).offset().top + 25);
        $("#" + target).css("left", $(this).offset().left - 7);

        $("#" + target).css("display", "block");

        var tt = $(this);

        $("#" + target).hover(function() { tt.addClass('selected'); },
            function() {
                $(this).css("display", "none");
                $(".menuitem").removeClass('selected');
            });
    },
	function() {
	    $(this).removeClass('selected');
	});

    function hideAllMenu() {
        $(".menuitem").removeClass('selected');
        $(".floatmenu_container").css('display', 'none');
    }

    $(".pinkytext").hover(function() {
        var id = $(this).attr("SpecId");
        var date = $(this).attr("Date");
        $("#ticketmenu").css("top", $(this).offset().top - 20);
        $("#ticketmenu").css("left", $(this).offset().left - 20);
        $("#ticketmenu").css("display", "block");
        //var href = $("#spc_About").attr("href") + "?id=" + id;
        var hrefabout = "http://www.stage-molot.ru/spectacle/Details/" + id;
        var hrefcomments = "http://www.stage-molot.ru/spectacle/Comments/" + id;
        var hreforder = "http://www.stage-molot.ru/spectacle/Order/" + id + "?date=" + date;

        $("#spc_About").attr("href", hrefabout);
        $("#spc_Comments").attr("href", hrefcomments);
        $("#spc_OrderTicket").attr("href", hreforder);

    },
	function() {

	});

    $("#ticketmenu").hover(function() { },
	function() {
	    $(this).css("display", "none");
	    hideAllMenu();
	});

    $("#search").click(function() {
        $(this).attr("value", "");
    });

    function DoChange(target, value) {
        $("#" + target).html(value);
    }

    $("#spectacleSelect").change(function() {
        DoChange($(this).attr('_Target'), this.options[this.selectedIndex].text);
    });

    $("#dateSelect").change(function() {
        DoChange($(this).attr('_Target'), this.options[this.selectedIndex].text);
    });

    $("#countSelect").change(function() {
        DoChange($(this).attr('_Target'), this.options[this.selectedIndex].text);
    });

    $(".SmallPhoto").click(function() {
        var target = $(this).attr('target');
        var alt = $(this).attr('alt');
        var descr = $(this).attr('descr');
        $(".SmallPhoto").removeClass('opacityOn');
        $(this).addClass('opacityOn');
        $("#" + target).attr('src', $(this).attr('src'));
        $("#" + target).attr('alt', alt);
        if (descr != "false") {
            $("#BigPhotoDescr").html(descr);
        }
    });

    $(".SmallPhoto").eq(0).addClass('opacityOn');

    $(".Year").click(function() {
        $(".Year").removeClass('active');
        $(this).addClass('active');
        $("#currentFormYear").attr("value", $(this)[0].firstChild.data);
        SubmitMonthAndYearForNews();
    });

    $(".Month").click(function() {
        $(".Month").removeClass('active');
        $(this).addClass('active');
        $("#currentFormMonth").attr("value", $(this).attr('id').replace(/[a-zA-Z_]*/g, ""));
        SubmitMonthAndYearForNews();
    });

    function SubmitMonthAndYearForNews() {
        var href = "http://www.stage-molot.ru/news/?Year=" + $("#currentFormYear").attr("value") + "&Month=" + $("#currentFormMonth").attr("value");
        //var href = "http://localhost:1714/news/?Year=" + $("#currentFormYear").attr("value") + "&Month=" + $("#currentFormMonth").attr("value");
        document.location = href;
    }
});

