var temp_vals= new Array(10);

// Thickbox Setup
function thickboxer()
{
	jQuery("a.thickbox").unbind("click");
	
	// For IE, open a popup window instead
	if(jQuery.browser.msie)
	{
		jQuery("a.thickbox").click(function() {
			var t = this.title || this.name || this.href || null;
			window.open(this.href,null,'width=850,height=740,scrollbars=0,toolbar=0,status=0,menubar=0');
			this.blur();
			return false;
		});
	}
	else
	{
		// Add thickbox functionality to new content
		jQuery("a.thickbox").click(function() {
			var t = this.title || this.name || this.href || null;
			tb_show(t, this.href);
			this.blur();
			return false;
		});
		
		// Flash disabling
		 jQuery("a.thickbox").click(function(){
		    jQuery("#eleanor_player").toggle();
			jQuery("#page_top_ad").toggle();
			jQuery("#news_ticker_container").toggle();
		});
	}
}

function toggle_expand(element) {
	if (jQuery(element).hasClass('expanded')) {
		 jQuery(element).removeClass('expanded');
	} else {
		jQuery(element).addClass('expanded').siblings().removeClass('expanded');
	}
}

function toggle_children(element) {
	if (jQuery(element + ' .expanded').length) { // Collapse
		jQuery(element + ' .expanded').each(function (pos) {
			jQuery(this).removeClass('expanded');
		});
	} else { // Expand
		jQuery(element + ' .expandable').each(function (pos) {
			jQuery(this).addClass('expanded');
		});
	}
}

function toggle_item(section, entry_id) {
	if (jQuery("#top_"+section+"_"+entry_id).hasClass('alt')) {
		jQuery("#top_"+section+"_"+entry_id).removeClass('alt');
	} else {
		jQuery("#top_"+section+"_"+entry_id).addClass('alt');
	}
	jQuery("#top_"+section+"_"+entry_id+' .top_content_item_accordian').slideToggle('normal');
	jQuery("#top_"+section+"_"+entry_id+" .top_content_button img").toggle();
}

function tzgo(elm, base_path) { //PRJ coded
	var exdate=new Date();
	var expiredays = 7;
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie="speed_tz=" +escape(elm.options[elm.selectedIndex].value)+((expiredays==null) ? "" : ";path=/;domain=speedtv.com;expires="+exdate.toGMTString());

	if (elm.options[elm.selectedIndex].value) {
		location.href = base_path+elm.options[elm.selectedIndex].value+'/';
	}
}
function toggle_expand_all() { //PRJ Coded
	if (jQuery('.expandable:first').is('.expanded')) {
		jQuery('.expandable').removeClass('expanded');
	} else {
		jQuery('.expandable').addClass('expanded');
	}
}

function switchTab(cat) {
	jQuery('#top_content_'+cat).show().siblings('.top_content_article_cats').hide();
	jQuery('#tab_'+cat).addClass('active').siblings().removeClass('active');
}

function show_program(id) {
	jQuery('#right_block_'+id+', #preview_'+id).fadeIn("slow").siblings().fadeOut('slow');
}

// Rotate featured headlines
var headline_count;
var headline_interval;
var current_headline = 0;
var old_headline = 0;
var rotate_freq = 7500; // 7.5 Seconds

jQuery(document).ready(function () {
	
	headline_count = jQuery('.headline_gallery_item').size();
	
	headline_interval = setInterval(headline_rotate, rotate_freq);
	
	jQuery('.headline_gallery_item').hover(function () {
		clearInterval(headline_interval);
	}, function () {
		headline_interval = setInterval(headline_rotate, rotate_freq);
	});
	
	jQuery('.headlines_cells .cell_item').hover(function () {
		jQuery('.headlines_cells').attr({id: 'pos'+jQuery('.headlines_cells .cell_item').index(this)});
	}, function () {
		jQuery('.headlines_cells').attr({id: 'pos'+current_headline});
	});
	
});

function headline_rotate(index, auto) {
	if (typeof(index) != 'undefined' && auto == false) {
		current_headline = index;
	} else {
		current_headline = (old_headline + 1) % headline_count;
	}
	
	jQuery('.headline_gallery_item:eq(' + current_headline + ')').fadeIn("slow").siblings().fadeOut('slow');
	
	jQuery('.headlines_gallery div a').removeClass('current');
	jQuery('.headlines_gallery .headlines_cells .cell_item:eq(' + current_headline + ') a').addClass('current');
	
	jQuery('.headlines_cells').attr({id: 'pos'+current_headline});
	
	old_headline = current_headline;
}

function bg_switch(id, img_src) 
{
	document.getElementById(id).style.backgroundImage = "URL("+img_src+")";
}


// Elevator Ad
var elevator_interval;
var el_rotate_freq = 10000; // 10 seconds

jQuery(document).ready(function () {
	
	elevator_interval = setInterval(toggle_elevator_ad, el_rotate_freq);
	
	jQuery('#elevator_ad').hover(function () {
		clearInterval(elevator_interval);
	}, function () {
		toggle_elevator_ad();
		elevator_interval = setInterval(toggle_elevator_ad, el_rotate_freq);
	});
	
});

function toggle_elevator_ad() {
	jQuery('#elevator_ad').slideToggle('normal');
}

/*
For select box navigation
*/
function go(elm, base_path, filter_path) {
	if (elm.options[elm.selectedIndex].value)
		location.href = base_path + filter_path + elm.options[elm.selectedIndex].value;
    else
        location.href = base_path;
}

// Wiki search

function search_wiki(action, xid, search_terms)
{
	var wikiform = document.createElement('form');
	var inputkeywords = document.createElement('input');
	var inputXID = document.createElement('input');
	wikiform.setAttribute('action', action);
	wikiform.setAttribute('method', 'post');
	wikiform.setAttribute('style', 'display: none;');
	inputkeywords.setAttribute('type', 'text');
	inputkeywords.setAttribute('name', 'keywords');
	inputkeywords.setAttribute('value', search_terms);
	inputXID.setAttribute('type', 'text');
	inputXID.setAttribute('name', 'XID');
	inputXID.setAttribute('value', xid);
	wikiform.appendChild(inputkeywords);
	wikiform.appendChild(inputXID);
	document.body.appendChild(wikiform);
	wikiform.submit();
}

// Navigation Switch


// Copies a value from a input of some sort to another, used in registration to hide username field and copy email into it.
function copy_field_value(from_field, to_field) {
    document.getElementById(to_field).value = document.getElementById(from_field);
}

// Load the gallery for the homepage
function ajax_gallery_home(order, limit, page)
{
	var data = null;
	jQuery.get('/gallery/ajax/'+order+'/'+limit+'/'+page, function(data){

			//clear gallery div and load content into new div
			var container = null;
			var newdiv = null;
			container = document.getElementById("gallery_index");
			if(container) {
				container.innerHTML = "";
				newdiv = document.createElement("div");
				newdiv.innerHTML = data;
				newdiv.className = "gallery_thumbnails";
				container.appendChild(newdiv);
			}

			//add thickbox functionality to new content
			thickboxer();
	});
}
/*
functions to determine if the user is currently observing Daylight savings
*/

Date.prototype.stdTimezoneOffset = function() {
var jan = new Date(this.getFullYear(), 0, 1);
var jul = new Date(this.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}


Date.prototype.isDST = function() {
    var local = this.getTimezoneOffset();
    var std = this.stdTimezoneOffset();
return local < std;
}
