jQuery.fn.accessNews = function(settings) {
    settings = jQuery.extend({
        newsHeadline: "Top Stories",
        newsSpeed: "normal"
    }, settings);
    return this.each(function(i) {
        aNewsSlider.itemWidth = parseInt(jQuery(".item:eq(" + i + ")",".news_slider").css("width")) + parseInt(jQuery(".item:eq(" + i + ")",".news_slider").css("margin-right"));
        aNewsSlider.init(settings,this);
        jQuery(".view_all > a", this).click(function() {
            aNewsSlider.vAll(settings,this);
            return false;
        });
    });
};
var aNewsSlider = {
    itemWidth: 0,
    init: function(s,p) {
        jQuery(".messaging",p).css("display","none");
        itemLength = jQuery(".item",p).length;
        if (jQuery(".view_all",p).width() == null) {
            jQuery(".news_items_view",p).prepend("<div style='background:url(img/ru/per_t.gif) top no-repeat #252525; width:520px; margin-left:15px; padding: 6px 10px 3px 10px; font-size:11px; clear:both'><span style='color:#d22c2c;'><b>ÍÎÂÛÅ ÏÅÐÅÄÀ×È</b> —</span> Ñàìîå íîâîå è èíòåðåñíîå èç ìèðà êîìïüþòåðíûõ èãð è âûñîêèõ òåõíîëîãèé!<div style='color:#face1f; text-align:right; margin-top:4px; font-size:10px; line-height:10px' class='view_all'>[ <a href='#' style='color:#face1f;'>âñå âèäåî çà íåäåëþ</a> ]</div></div><div style='background:url(img/ru/per_b.gif); width:540px; height:4px; margin-left:15px; font-size:0px'></div>");
        }
        newsContainerWidth = itemLength * aNewsSlider.itemWidth;
        jQuery(".container",p).css("width",newsContainerWidth + "px");
        jQuery(".next",p).css("display","block");
		jQuery(".prev",p).fadeTo(300, 0.4);
		jQuery(".start",p).fadeTo(300, 0.4);
        animating = false;
        jQuery(".next",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",p).css("left")) - (aNewsSlider.itemWidth * 5);
                if (animateLeft + parseInt(jQuery(".container",p).css("width")) > 0) {
                    jQuery(".prev",p).fadeTo(300, 1);
					jQuery(".start",p).fadeTo(300, 1);
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",p).css("left")) + parseInt(jQuery(".container",p).css("width")) <= aNewsSlider.itemWidth * 5) {
							jQuery(".next",p).fadeTo(300, 0.4);
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
        jQuery(".prev",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",p).css("left")) + (aNewsSlider.itemWidth * 5);
                if ((animateLeft + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width"))) {
                    jQuery(".next",p).fadeTo(300, 1);
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",p).css("left")) == 0) {
                           	jQuery(".prev",p).fadeTo(300, 0.4);
							jQuery(".start",p).fadeTo(300, 0.4);
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
		jQuery(".start",p).click(function() {
            if (animating == false) {
                animating = true;
				animateLeft = parseInt(0);
                if ((animateLeft + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width"))) {
                    jQuery(".next",p).fadeTo(300, 1);
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                            jQuery(".prev",p).fadeTo(300, 0.4);
							jQuery(".start",p).fadeTo(300, 0.4);
                        animating = false;
                    });
                } else {
                    animating = false;
                }
			}
            return false;
        });
    },
    vAll: function(s,p) {
        var o = p;
        while (p) {
            p = p.parentNode;
            if (jQuery(p).attr("class") != undefined && jQuery(p).attr("class").indexOf("news_slider") != -1) {
                break;
            }
        }
        if (jQuery(o).text().indexOf("âñå âèäåî çà íåäåëþ") != -1) {
            jQuery(".next",p).css("display","none");
            jQuery(".prev",p).css("display","none");
            jQuery(o).text("ñâåðíóòü");
            jQuery(".container",p).css("left","0px").css("width",aNewsSlider.itemWidth * 5 + "px");
        } else {
            jQuery(o).text("âñå âèäåî çà íåäåëþ");
            aNewsSlider.init(s,p);
        }
    }
};
