var entryCount=0;
var anim_interval;
var currentEntry = 0;
var old_headline = 0;
var entryHeight = 89.5; 

var popup = {
    ref : null
};
VSCROLL ={
	entryCount:0,
	anim_interval:null,
	currentEntry : 0,
	old_headline : 0,
	entryHeight : 89.5, 
	scrollInterval:4,
	scrollSpeed:40,
	btnUpSelector: "#btnEventsUpArrow a",
	btnDownSelector: "#btnEventsDownArrow a",
	outerContainer:"#contentRightList",
	container:"#contentRightList div.scrollable",
	listItem: ".scrollable ul .eventListEntry",
	init: function(params){
		if(params){
			this.currentEntry= (params.currentEntry)? params.currentEntry  : 0,
			this.entryHeight = (params.entryHeight)?params.entryHeight: 89.5;
			this.scrollInterval=(params.scrollInterval)?params.scrollInterval : 4;
			this.scrollSpeed=(params.scrollSpeed)?params.scrollSpeed :40;
			this.outerContainer = (params.outerContainer)?params.outerContainer:"#contentRightList";
			this.btnUpSelector = (params.btnUpSelector)?params.btnUpSelector: "#btnEventsUpArrow a";
			this.btnDownSelector=(params.btnDownSelector)? params.btnDownSelector: "#btnEventsUpArrow a";
			this.container=(params.container)?params.container : "#contentRightList div.scrollable";
			this.listItem=(params.listItem)?params.listItem : ".scrollable ul .eventListEntry";
		}
		$(this.btnUpSelector).mouseover(function(){
			VSCROLL.entryCount = $(VSCROLL.listItem).size();
			//$(VSCROLL.container).css({height: $(VSCROLL.container).outerHeight(true)+"px", top:"0px"});
			VSCROLL.anim_interval= setInterval(
				function(){ 
					var top = parseInt($(VSCROLL.container).css("top"));
						
						if(top < 0){
							$(VSCROLL.container).css("top", (top+VSCROLL.scrollInterval));	
			
						}
				}, 
				VSCROLL.scrollSpeed
			);      
			//$("#contentRightList .scrollable").animate({top: 0},9000); 
			//alert($("#contentRightList .scrollable").css("top"));
			return false;
		});
		$(this.btnDownSelector).mouseover(function(){
			VSCROLL.entryCount = $(VSCROLL.listItem).size();
			//$(VSCROLL.container).css({height: VSCROLL.entryHeight*VSCROLL.entryCount+"px", top:"0px"});
			VSCROLL.anim_interval=setInterval(
				function(){ 
					var top = parseInt($(VSCROLL.container).css("top"));
						if(top > -($(VSCROLL.container).outerHeight(true) - $(VSCROLL.outerContainer).innerHeight()) ){
							$(VSCROLL.container).css("top", (top-VSCROLL.scrollInterval));	
							
						}	
						
				}, 
				VSCROLL.scrollSpeed
			);      
			return false;
		});
		$(this.btnDownSelector+","+this.btnUpSelector ).mouseout(function(){clearInterval(VSCROLL.anim_interval);});
	}
};
$(document).ready(function(){
						   
	VSCROLL.init();
	$(".EstherAudio").click(function (e) { 
			e.preventDefault();
			e.stopPropagation();
			
			if(popup.ref != null){
				popup.ref.close();
				popup.ref = null;
			}
			
			var topPx = (screen.height/2)-(246/2);
			var leftPx = (screen.width/2)-(512/2);
			popup.ref = window.open($(this).attr('href'),"_blank","width=512,height=248,top=" + topPx + ",left=" + leftPx + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
		});	
	
});


/*
$(document).ready(function(){

	var scrollInterval=4;
	var scrollSpeed=40;
	$("#btnEventsUpArrow a").mouseover(function(){
		//entryCount = $(".scrollable ul .eventListEntry").size();
		//$("#contentRightList.scrollable").css({height: entryHeight*entryCount+"px", top:"0px"});
		$("#contentRightList.scrollable").css({ top:"0px"});
		var scrollPaneHeight = $(".scrollable ul .eventListEntry").height();
		anim_interval= setInterval(
			function(){ 
				var top = parseInt($("#contentRightList .scrollable").css("top"));
					
					if(top < 0){
						$("#contentRightList .scrollable").css("top", (top+scrollInterval));	
		
					}
			}, 
			scrollSpeed
		);      
		//$("#contentRightList .scrollable").animate({top: 0},9000); 
		//alert($("#contentRightList .scrollable").css("top"));
		return false;
	});
	$("#btnEventsDownArrow a").mouseover(function(){
		//entryCount = $(".scrollable ul .eventListEntry").size();
		//$("#contentRightList.scrollable").css({height: entryHeight*entryCount+"px", top:"0px"});
		var scrollWindowHeight = $("#contentRightList .scrollable ul").height();
		var scrollPaneHeight =  $("#contentRightList .scrollable").height() - scrollWindowHeight; 
		alert($("#contentRightList .scrollable").height() +","+scrollWindowHeight);
		anim_interval=setInterval(
			function(){ 
				var top = parseInt($("#contentRightList .scrollable").css("top"));
				
					if(top > -(scrollPaneHeight){
					//if(top > -(entryHeight*(entryCount-3)) ){
						$("#contentRightList .scrollable").css("top", (top-scrollInterval));	
						
					}	
					
			}, 
			scrollSpeed
		);      
		return false;
	});
	$("#btnEventsDownArrow a, #btnEventsUpArrow a").mouseout(function(){clearInterval(anim_interval);});
});
*/

/**
* Global object for clientside cookie handling.  Super basic.
*/
if (typeof HC == 'undefined' || !HC) {
    var HC = {};
} 

/**
*   Key name for a cookie to prevent spelling errors 
*   from killing the intended functionality
*/
HC.keys = {
    hideLaureateHelp:"HideLaureateHelp"
}

/**
*   Adds a simple name key value cookie.  Send null for
*   days to make it permanent.
*   @param {string} name - Name key for cookie.
*   @param {any} value - value of key.
*   @param {int} days - Number of days this should stick around for.
*/
HC.createCookie = function(name,value,days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/**
*   Read the value from a cookie.
*   @param {string} name - event to be published
*/
HC.readCookie = function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**
*   Erases the cookie by name.
*   @param {string} name - name of cookie to kill
*/
HC.eraseCookie = function(name) {
	HC.createCookie(name,"",-1);
}



