jQuery.fn.accessNews = function(settings) {
   return this.each(function(i) {
        aNewsSlider.itemWidth = parseInt(jQuery(".item:eq(" + i + ")",".gui_home_sld").css("width")) + parseInt(jQuery(".item:eq(" + i + ")",".gui_home_sld").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) {
		/* Starting setting css*/
		jQuery(".gui_home_sld").css("background","#7692a7");
		//Left button
		jQuery(".prev",p).css({position: "absolute", top: "1%", display: "block"});
		//Right button
		jQuery(".next",p).css({position: "absolute", top: "1%", display: "block", right: "0"});  
		//Container div
		jQuery(".gui_sld_cnt",p).css({top: "0", left: "0", width: "100%", background: "#444", padding: "0"});
		//Item div
		jQuery(".item",p).css("border-top","none");
		jQuery(".gui_sld_itm",p).css({height: "169px", top: "0", left: "21px", overflow:"hidden"});
		//Block div
		jQuery(".gui_blck",p).css("margin","0");
		jQuery(".gui_msg",p).css("display","none");
        itemLength = jQuery(".item",p).length;
        newsContainerWidth = itemLength * aNewsSlider.itemWidth + 315;
		jQuery(".gui_br_noscript",p).css("display","none");
        jQuery(".gui_sld_cnt",p).css("width",newsContainerWidth + "px");
		jQuery(".gui_sld_cnt",p).css("left","-474px"); /* Positioning at the second group of three hotels to allow back animation */
				
        animating = false;
        jQuery(".next",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".gui_sld_cnt",p).css("left")) - (474);
                if (animateLeft + parseInt(jQuery(".gui_sld_cnt",p).css("width")) - 474 > 0) {
                    jQuery(".gui_sld_cnt",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".gui_sld_cnt",p).css("left")) + parseInt(jQuery(".gui_sld_cnt",p).css("width")) <= 1422) {
													var tmp = jQuery(".gui_blck:first",p)
													jQuery(".gui_blck:first",p).remove();
													jQuery(".gui_sld_cnt",p).append(tmp);
													animating = true;
													animateLeft = parseInt(jQuery(".gui_sld_cnt",p).css("left")) - (-474);
													jQuery(this).css("left",animateLeft);
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
        jQuery(".prev",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".gui_sld_cnt",p).css("left")) + (474);
                if ((animateLeft + parseInt(jQuery(".gui_sld_cnt",p).css("width"))) <= parseInt(jQuery(".gui_sld_cnt",p).css("width"))) {
                    jQuery(".gui_sld_cnt",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        if (parseInt(jQuery(".gui_sld_cnt",p).css("left")) == 0) {
													var tmp = jQuery(".gui_blck:last",p)
													jQuery(".gui_blck:last",p).remove();
													jQuery(".gui_sld_cnt",p).prepend(tmp);
													animating = true;
													animateLeft = parseInt(jQuery(".gui_sld_cnt",p).css("left")) - (474);
													jQuery(this).css("left",animateLeft);
                        }
						else jQuery(this).css("left",animateLeft);
                        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("gui_home_sld") != -1) {
                break;
            }
        }
        if (jQuery(o).text().indexOf("View All") != -1) {
            jQuery(".next",p).css("display","none");
            jQuery(".prev",p).css("display","none");
            jQuery(o).text("View Less");
            jQuery(".gui_sld_cnt",p).css("left","0px").css("width",474 + "px");
        } else {
            jQuery(o).text("View All");
            aNewsSlider.init(s,p);
        }
    }
};
