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);
    });
};
var aNewsSlider = {
    itemWidth: 0,
    init: function(s,p) {
        jQuery(".messaging",p).css("display","none");
        itemLength = jQuery(".item",p).length;
		//itemLength = 157;
        /*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;
		//alert(newsContainerWidth);
		jQuery(".container",p).css("width",newsContainerWidth + "px");
		jQuery(".container4",p).css("width",newsContainerWidth + "px");
		jQuery(".sl3",p).css("width","1232px");
		jQuery(".sl1",p).css("width","616px");
		jQuery(".sl2",p).css("width","154px");
        jQuery(".next",p).css("display","block");
		jQuery(".prev",p).fadeTo(300, 0.4);
		jQuery(".start",p).fadeTo(300, 0.4);
		jQuery(".next4",p).css("display","block");
		jQuery(".prev4",p).fadeTo(300, 0.4);
		jQuery(".start4",p).fadeTo(300, 0.4);
		jQuery(".next4_tv",p).css("display","block");
		jQuery(".prev4_tv",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(".next4",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container4",p).css("left")) - (aNewsSlider.itemWidth * 4);
                if (animateLeft + parseInt(jQuery(".container4",p).css("width")) > 0) {
                    jQuery(".prev4",p).fadeTo(300, 1);
					jQuery(".start4",p).fadeTo(300, 1);
                    jQuery(".container4",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container4",p).css("left")) + parseInt(jQuery(".container4",p).css("width")) <= aNewsSlider.itemWidth * 4) {
							jQuery(".next4",p).fadeTo(300, 0.4);
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
		jQuery(".next4_tv",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container4",p).css("left")) - (154 * 4);
                if (animateLeft + parseInt(jQuery(".container4",p).css("width")) > 0) {
                    jQuery(".prev4_tv",p).fadeTo(300, 1);
					//jQuery(".start4",p).fadeTo(300, 1);
                    jQuery(".container4",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container4",p).css("left")) + parseInt(jQuery(".container4",p).css("width")) <= 154 * 4) {
							jQuery(".next4_tv",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(".prev4",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container4",p).css("left")) + (aNewsSlider.itemWidth * 4);
                if ((animateLeft + parseInt(jQuery(".container4",p).css("width"))) <= parseInt(jQuery(".container4",p).css("width"))) {
                    jQuery(".next4",p).fadeTo(300, 1);
                    jQuery(".container4",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container4",p).css("left")) == 0) {
                           	jQuery(".prev4",p).fadeTo(300, 0.4);
							jQuery(".start4",p).fadeTo(300, 0.4);
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
		jQuery(".prev4_tv",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container4",p).css("left")) + (154 * 4);
                if ((animateLeft + parseInt(jQuery(".container4",p).css("width"))) <= parseInt(jQuery(".container4",p).css("width"))) {
                    jQuery(".next4_tv",p).fadeTo(300, 1);
                    jQuery(".container4",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container4",p).css("left")) == 0) {
                           	jQuery(".prev4_tv",p).fadeTo(300, 0.4);
							//jQuery(".start4",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;
        });
		jQuery(".start4",p).click(function() {
            if (animating == false) {
                animating = true;
				animateLeft = parseInt(0);
                if ((animateLeft + parseInt(jQuery(".container4",p).css("width"))) <= parseInt(jQuery(".container4",p).css("width"))) {
                    jQuery(".next4",p).fadeTo(300, 1);
                    jQuery(".container4",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                            jQuery(".prev4",p).fadeTo(300, 0.4);
							jQuery(".start4",p).fadeTo(300, 0.4);
                        animating = false;
                    });
                } else {
                    animating = false;
                }
			}
            return false;
        });
    },

};

