/* Global variables ****************/
var current = 0;
var int_scroll_left = 0;
var int_scroll_right = 0;
var slideshowSpeed = 10000;
var playSlideshow = setInterval("scroll_push()",slideshowSpeed);
var push_pos = 0;
var imgwidth = 0;
var pushes = new Array();		

/* Populate push panel ****************/
function pop_push(json, index) {
    $("#highlights-slideshow div.details h2 a").attr("href", json.url);
    $("#highlights-slideshow div.details h2 a").text(json.title);
	$("#highlights-slideshow div.details p.description").text(json.description);
	$("#highlights-slideshow div.details p.next-on").text(json.next);
	if (json.next != "")
		$("#highlights-slideshow div.details div.next-showing-details").show();	
	else
		$("#highlights-slideshow div.details div.next-showing-details").hide();	
    $("#highlights-slideshow div.paging a").each(function() {
        $(this).removeClass("on");
    });	
    $("#highlights-slideshow div.paging a[rel=" + index + "]").addClass("on");
    $("#highlights-slideshow div.pic").css("background-image", "url(" + json.image + ")");  
    if (json.channelImage) {
		$("#highlights-slideshow div.pic div.details").css("background-image", "url(" + json.channelImage + ")");  
    }       
    if (json.logoImage) {
		$("#highlights-slideshow img.channel-logo").attr("src", json.logoImage);  
    }        
    if (json.highlightsLinkUrl) {
		$("#highlights-slideshow div.details div.highlights-link a").attr("href", json.highlightsLinkUrl);
		$("#highlights-slideshow div.details div.highlights-link a").text(json.highlightsLinkText);
    }       
}

/* Add push buttons ****************/
function add_push_buttons() {
    var push_count = 0;		
    while (push_count < pushes.length) {
        if (push_count == 0) {
            $("#highlights-slideshow div.paging").append("<a class='on' rel='" + push_count + "'>" + (push_count + 1) + "</a>");
            push_count++;
        } else {
            $("#highlights-slideshow div.paging").append("<a rel='" + push_count + "'>" + (push_count + 1) + "</a>");
            push_count++;
        }
    }	
    $("#highlights-slideshow div.paging a").click(function() {
        var rel = $(this).attr("rel");
        clearInterval(playSlideshow);
        pop_push(pushes[rel], rel);
        current = parseInt(rel);
        playSlideshow = setInterval("scroll_push()", slideshowSpeed);
    });	
    $("#highlights-slideshow div.left a").click(function() {
		clearInterval(playSlideshow);
		if (current > 0) {
			current = current - 1;
		}
        pop_push(pushes[current], current);
        playSlideshow = setInterval("scroll_push()", slideshowSpeed);
		return false;
    });	
    $("#highlights-slideshow div.right a").click(function() {
        clearInterval(playSlideshow);
		if (current < pushes.length) current++;
        pop_push(pushes[current], current);
        playSlideshow = setInterval("scroll_push()", slideshowSpeed);
		return false;
    });	
}

/* Scroll push panel ****************/
function scroll_push() {
	if (pushes.length > 0) {
		if ((current + 1) == pushes.length) {
			current = 0;
		} else {
			current = current + 1;
		}
		pop_push(pushes[current], current);
	}
};

$(document).ready(function() {
    disableLinks();   
});

function disableLinks() {
    $("a.disabled").click(function() {
		return false;
    });	
}
