// JavaScript Document
jQuery.fn.accessNews = function(settings) {
    settings = jQuery.extend({
        newsHeadline: "Top Stories",
        newsSpeed: "slow",
		visible:3
		
    }, 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",p).prepend("<p class='view_all'></p>");
        }
        newsContainerWidth = itemLength * aNewsSlider.itemWidth;
        jQuery(".container",p).css("width",newsContainerWidth + "px");
        jQuery(".next",p).css("display","block");
		jQuery(".prev",p).css("display","block");
        animating = false;
        jQuery(".next",p).click(function() {
            if (animating == false) {
                animating = true;
                /*animateLeft = parseInt(jQuery(".container",p).css("left")) - (aNewsSlider.itemWidth * 4);*/
				animateLeft = parseInt(jQuery(".container",p).css("left")) - (aNewsSlider.itemWidth * s.visible)
                if (animateLeft + parseInt(jQuery(".container",p).css("width")) > 0) {
                    jQuery(".prev",p).css("display","block");
                    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 * 2) {
                            jQuery(".next",p).css("display","block");
                        }
                        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 * 4);
				animateLeft = parseInt(jQuery(".container",p).css("left")) + (aNewsSlider.itemWidth * s.visible);
                if ((animateLeft + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width"))) {
                    jQuery(".next",p).css("display","block");
                    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).css("display","block");
                        }
                        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("View All") != -1) {
            jQuery(".next",p).css("display","block");
            jQuery(".prev",p).css("display","block");
            jQuery(o).text("View Less");
            jQuery(".container",p).css("left","0px").css("width",aNewsSlider.itemWidth * 2 + "px");
        } else {
            jQuery(o).text("View All");
            aNewsSlider.init(s,p);
        }
    }
};
			  
		function go_peli(actual,ir,w){
			   
			  var actual = actual.split("_",2);
			  var ir = ir.split("_",2);
			  actual = actual[1];
			  ir = ir[1];

			  var totales = 0;
			  var cells = document.getElementsByTagName("div"); 
				for (var i = 0 ; i <cells.length ; i++) { 
   				 status = cells[i].getAttribute("class");
				 status2 = cells[i].getAttribute("className"); 	 
  				  if ( status == "slider_peliculas" || status2 == "slider_peliculas") { 
  				 		 if (cells[i].style.display!='none'){
							var actual = cells[i].id;
						}
    			  var totales = totales + 1;
				  }
				}
			
			
			
			  var actual = actual.split("_",2);
			  var actual = actual[1];

			  if (ir>totales){
			  ir = 1; 
			  }
			  
			  if (ir==0){
			  ir = totales; 
			  }
			  
			  if (actual=='undefined'){
			  return false;
			  }
			
			 document.getElementById("div_"+actual).style.display='none';
			  $('#div_'+ir).fadeIn('slow');
			  var actual2 = ir;
			  var next = Math.floor(ir) + 1;
			   
			  if (w==1){
			  clearTimeout(timeout);
			  }
			  
			  timeout = setTimeout("go_peli('div_"+actual2+"','div_"+next+"',0);",5000);
			  
	}
	
	
	function next_peli(){
			   
			  var totales = 0;
			  var cells = document.getElementsByTagName("div"); 
				for (var i = 0 ; i <cells.length ; i++) { 
   				 status = cells[i].getAttribute("class");
				 status2 = cells[i].getAttribute("className"); 	 
  				  if ( status == "slider_peliculas" || status2 == "slider_peliculas") { 
  				 		 if (cells[i].style.display!='none'){
							var actual = cells[i].id;
						 }
    			  var totales = totales + 1;
				  }
				}
			
			  var actual = actual.split("_",2);
			  var actual = actual[1];

			  var ir = Math.floor(actual) ;

			  if (ir>totales){
			  ir = 1; 
			  }
			  
			  if (ir==0){
			  ir = totales; 
			  }
			  
			  if (actual=='undefined'){
			  return false;
			  }
			  
			  var actual2 = ir;
			  var next = Math.floor(ir) + 1;
			  
			  
			  go_peli("div_"+actual2,"div_"+next,1);
			 
	}
	
	function prev_peli(){
			   
			  var totales = 0;
			  var cells = document.getElementsByTagName("div"); 
				for (var i = 0 ; i <cells.length ; i++) { 
   				 status = cells[i].getAttribute("class");
				 status2 = cells[i].getAttribute("className"); 	 
  				  if ( status == "slider_peliculas" || status2 == "slider_peliculas") { 
  				 		 if (cells[i].style.display!='none'){
							var actual = cells[i].id;
						 }
    			  var totales = totales + 1;
				  }
				}
			
			  var actual = actual.split("_",2);
			  var actual = actual[1];

			  var ir = Math.floor(actual);

			  if (ir>totales){
			  ir = 1; 
			  }
			  
			  if (ir==0){
			  ir = totales; 
			  }
			  
			  if (actual=='undefined'){
			  return false;
			  }
			  
			  var actual2 = ir;
			  var next = Math.floor(ir) -1;
			  go_peli("div_"+actual2,"div_"+next,1);
			 
	}
	
