//Functionality for shade changes on row items
function makeOddRollover(id)
{
	var object = document.getElementById(id);
	object.style.backgroundColor = "#dbdbdb";
}

function makeEvenRollover(id)
{	
	var object = document.getElementById(id);
	object.style.backgroundColor = "#dbdbdb";
}

function makeOddRollout(id)
{	
	var object = document.getElementById(id);
	object.style.backgroundColor = "#fff";
}

function makeEvenRollout(id)
{	
	var object = document.getElementById(id);
	object.style.backgroundColor = "#f7f7f7";
}

//functionality for sort arrows at the top of columns

function carrow(crd,shw)
{
sect="search_results_container"+shw;

divsect=document.getElementsByTagName('div');

for(j=0;j<divsect.length;j++)
{
	if(divsect[j].id==sect)
	{
		
		sarr=divsect[j].getElementsByTagName('span');

		for(a=0;a<sarr.length;a++)
		{
			if(sarr[a].id=="sarrow")
			{
		  	sarr[a].style.display="none";
		 	}
		}
	}
}


sarr2=crd.getElementsByTagName('span');

	for(x=0;x<sarr2.length;x++)
	{

		ihm=sarr2[x].innerHTML;
		if(ihm.match("a_lib"))
		{
		sarr2[x].style.display="block";
		sarr2[x].innerHTML='<img src="images/sort_'+shw+'b_lib.gif" alt="filter status" id="sortarrow2" name="sortarrowu" />';
		}else{
		sarr2[x].style.display="block";
		sarr2[x].innerHTML='<img src="images/sort_'+shw+'a_lib.gif" alt="filter status" id="sortarrow2" name="sortarrowu" />';
		}
	 
	}		
}

/**
 * Top 10 / Selection Row
 */
var SelectionRow = function(id) {
	this.initialize(id);
}

SelectionRow.prototype = {
	
	current: 0,
	timeout: null,
	
	/**
	 * constructor
	 * 
	 * @param string id - id of the container for the row
	 */
	initialize: function(id) {
		
		this.container = document.getElementById(id);
		this.items = this.container.getElementsByTagName('div');
		this.links = [];
		
		var maxHeight = 0;
		var listItems = this.container.getElementsByTagName('li');
		
		for (var i = 0; i < this.items.length; i++) {
			
			//show, get height, then hide
			this.items[i].className = 'active';
			if (this.items[i].offsetHeight > maxHeight) maxHeight = this.items[i].offsetHeight;
			this.items[i].className = '';
			
			//get link
			var link = listItems[i].getElementsByTagName('a')[0];
			link.position = i;
			//attach event
			var self = this;
			link.onmouseover = function() { self.stop(); self.activate(this.position); }
			link.onmouseout = function() { self.start(); }
			
			this.links[i] = link;
		}
		
		//set height
		this.container.style.height = maxHeight + 'px';
		
		//activate first
		this.activate(0);
		this.start();
		
	},
	
	activate: function(item) {				
		this.current = item;
		for (var i = 0; i < this.items.length; i++) {
			this.items[i].className = (i == item) ? 'active' : '';
			this.links[i].className = (i == item) ? 'active' : '';
		}
	},
	
	advance: function() {
		if (this.current < this.items.length - 1) {
			this.activate(this.current + 1);
		} else {
			this.activate(0);
		}
	},
	
	start: function() {
		var self = this;
		this.interval = window.setInterval(function(){ self.advance(); }, SelectionRow.delay);
	},
	
	stop: function() {
		window.clearInterval(this.interval);
	}
}

//constants
SelectionRow.delay = 2000;


//Image changes for top navigation bar
function rollOver(img_name, img_src)
{
    document[img_name].src = img_src;
}

//Opens new window for print
function openWindow(){
	window.open('eulaprint.shtml', 'EULA_printer_ready', 'location=no, menubar=no, toolbar=no');
}

//genre dropdown on top navbar
function opennav() {
	anynav=document.getElementById('anytimeNav');	
	if (anynav.style.display=="block") {
		anynav.style.display="none";
	} else {
		anynav.style.display="block";
	}
}

/**
 * clearNav function
 * 
 * unsets the active class on all nav links
 */
function clearNav() {
	var links = document.getElementsByTagName('a');
	for (a = 0; a < links.length; a++) {
		if (links[a].className.match('category-active')) {
			links[a].className = '';
			
			var subNavs = links[a].parentNode.getElementsByTagName('ul');
			for (var a = 0; a < subNavs.length; a++) {
				subNavs[a].style.display = 'none';
			}
		}
	}
}


/** 
 * trackLink
 * 
 * Hitbox link tracking wrapper function
 * 
 * @param string name - lid for hitbox, link name
 * @param string position - lpos for hitbox, position on the page
 */
function trackLink(name, position) {
	
	//replace spaces with +
	name = name.replace(' ', '+');
	position = position.replace(' ', '+');
	
	if (window._hbLink) {
		window._hbLink(name, position);
	}
	return true;
}
 
//Top Navigation Browse Channels Dropdown 
$(document).ready(function() {
 		$(".menuBrowseChannelsSelect").change(function() {
 		if ($(".menuBrowseChannelsSelect").val() != "") {
 			window.location = ($(".menuBrowseChannelsSelect").val());
 		}
 	});
 });
