
$(document).ready(
        	function() 
        	{
                $("[id*='star_']").click(function(event) 
        	    {
        	        event.preventDefault();
        	        var star_id = $(this).attr("id");
        	        var id_split = star_id.split('_');
        	        var rating = id_split[1];
        	        var rose_id = id_split[2];
        	        $.post(base_url + '/ajax/rate_rose', { rose_id: rose_id, rating: rating },
                    function(response) {

                        if (response == null)
                            return;

                        switch (response.ret_code) {
                            //ok 
                            case 1:
                                $("#vote_top_" + rose_id).html(response.msg);
                                $("#vote_new_" + rose_id).html(response.msg);

                                $("#votestarnew_" + rose_id).removeClass();
                                $("#votestarnew_" + rose_id).addClass("rating");
                                $("#votestartop_" + rose_id).removeClass();
                                $("#votestartop_" + rose_id).addClass("rating");
                                switch (response.note) {
                                    case 1:
                                        $("#votestarnew_" + rose_id).addClass("onestar");
                                        $("#votestartop_" + rose_id).addClass("onestar");
                                        break;
                                    case 2:
                                        $("#votestarnew_" + rose_id).addClass("twostar");
                                        $("#votestartop_" + rose_id).addClass("twostar");
                                        break;
                                    case 3:
                                        $("#votestarnew_" + rose_id).addClass("threestar");
                                        $("#votestartop_" + rose_id).addClass("threestar");
                                        break;
                                    case 4:
                                        $("#votestarnew_" + rose_id).addClass("fourstar");
                                        $("#votestartop_" + rose_id).addClass("fourstar");
                                        break;
                                    case 5:
                                        $("#votestarnew_" + rose_id).addClass("fivestar");
                                        $("#votestartop_" + rose_id).addClass("fivestar");
                                        break;
                                    default:
                                        $("#votestarnew_" + rose_id).addClass("nostar");
                                        $("#votestartop_" + rose_id).addClass("nostar");
                                        break;
                                }

                                // load the contact form using ajax
                                $.get(base_url + "/formAjax/voteOk", function(data) {
                                    // create a modal dialog with the data
                                    $(data).modal(
                                    {
                                        closeHTML: "<a href='#' title='" + listText[8] + "' class='modalCloseX simplemodal-close'>x</a>",
                                        position: ["15%", ],
                                        opacity: (85),
                                        overlayId: 'roseVote-overlay',
                                        containerId: 'roseVote-container',
                                        onOpen: roseVote.open,
                                        onShow: roseVote.show,
                                        onClose: roseVote.close
                                    });
                                });

                                break;
                            //error 
                            case 2:
                                // load the contact form using ajax
                                $.get(base_url + "/formAjax/voteError", function(data) {
                                    // create a modal dialog with the data
                                    $(data).modal(
                                    {
                                        closeHTML: "<a href='#' title=" + listText[8] + " class='modalCloseX simplemodal-close'>x</a>",
                                        position: ["15%", ],
                                        opacity: (85),
                                        overlayId: 'roseVote-overlay',
                                        containerId: 'roseVote-container',
                                        onOpen: roseVote.open,
                                        onShow: roseVote.show,
                                        onClose: roseVote.close
                                    });
                                });
                                //alreadyVoted
                            case 3:
                                // load the contact form using ajax
                                $.get(base_url + "/formAjax/voteAlreadyDone", function(data) {
                                    // create a modal dialog with the data
                                    $(data).modal(
                                    {
                                        closeHTML: "<a href='#' title=" + listText[8] + " class='modalCloseX simplemodal-close'>x</a>",
                                        position: ["15%", ],
                                        opacity: (85),
                                        overlayId: 'roseVote-overlay',
                                        containerId: 'roseVote-container',
                                        onOpen: roseVote.open,
                                        onShow: roseVote.show,
                                        onClose: roseVote.close
                                    });
                                });
                                break;
                        }
                    }, "json");
        	    });
        	});

        	var roseVote =
        {
            message: null,
            open: function(dialog) 
            {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                    $('#roseVote-container .roseVote-button').css({
                        'padding-bottom': '2px'
                    });
                }
                // input field font size
                if ($.browser.safari) {
                    $('#roseVote-container .roseVote-input').css({
                        'font-size': '.9em'
                    });
                }

                // dynamically determine height
                var h = 120;

                var title = $('#roseVote-container .roseVote-title').html();
                $('#roseVote-container .roseVote-title').html(listText[0]);
                dialog.overlay.fadeIn(200, function() 
                {
                    dialog.container.fadeIn(200, function() 
                    {
                        dialog.data.fadeIn(200, function() 
                        {
                            $('#roseVote-container .roseVote-content').animate(
                        {
                            height: h
                        },
                        function() 
                        {
                            $('#roseVote-container .roseVote-title').html(title);
                        
                            $('#roseVote-container .roseVote-message').fadeIn(200, function() 
                            {
                                // fix png's for IE 6
                                if ($.browser.msie && $.browser.version < 7) 
                                {
                                    $('#roseVote-container .roseVote-button').each(function() 
                                    {
                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) 
                                        {
                                            var src = RegExp.$1;
                                            $(this).css(
                                            {
                                                backgroundImage: 'none',
                                                filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")'
                                            });
                                        }
                                    });
                                }
                            });
                        });
                        });
                    });
                });
            },
            show: function(dialog) {
            },
            close: function(dialog) {
                $('#roseVote-container .roseVote-message').fadeOut()
                $('#roseVote-container .roseVote-title').html(listText[3]);
                $('#roseVote-container .roseVote-content').animate(
            {
                height: 40
            },
            function() {
                dialog.data.fadeOut(200, function() {
                    dialog.container.fadeOut(200, function() {
                        dialog.overlay.fadeOut(200, function() {
                            $.modal.close();
                        });
                    });
                });
            });
        },
            error: function(xhr) {
                alert(xhr.statusText);
            },
            showError: function() {
//                alert('eeror');
            }
        };