// prototype ajax debugger
function debugAJAX(r) {
	var debug = '';
    debug = 'REQUEST: '+r.request+'\n\n'
    		+'STATUS: '+r.status+' '+r.statusText+'\n\n'
            +'RSTATE: '+r.readyState+'\n\n'
            +'RTEXT: '+r.responseText+'\n\n'
            +'XML: '+r.responseXML+'\n\n'
            +'TRANSPORT: '+r.transport+'\n\n';
    
	alert(debug);
}


// INIT THESE FUNCTIONS WHEN PAGE LOADS




//------------------------------
//	FEATURED BOX SLIDER
//------------------------------

// INIT VARS & COUNT 
var featured_count = 0;
var min_step = 0; //
var max_step = 5; // 0,1,2,3,4,5: total --> 6 featured items

// NAVIGATING VIA STEPS (INDIVIDUAL CIRCLES)
function featured_free_step(num,imgID) {
	var dur = 0.5;
	
	// reset steps (circles) to 'inactive', make selected one 'active'
	var allItems = $('stepStates').descendants('img');
	$(allItems).each(function(x) {
		if($(x).hasClassName('stepStatesImg')) { // weed out the <a> descendents
			$(x).setAttribute('src', '/images/featured-step-inactive.gif');
			$(imgID).setAttribute('src', '/images/featured-step-active.gif');
		}
	});
	
	// forward steps animation
	if (featured_count < num) {
		var steps = num-featured_count;
		new Effect.Move('featuredList', {
			duration: dur,
			y: -232*steps, 
			transition: Effect.Transitions.sinoidal
		});
		
		featured_count=num;
	}
	
	// backward steps animation
	else if (featured_count > num) {
		var steps = featured_count-num;
		new Effect.Move('featuredList', {
			duration: dur,
			y: 232*steps,
			transition: Effect.Transitions.sinoidal
		});
		
		featured_count=num;
	}
	
	// do nothing
	else if (featured_count == num) {
		return;
	}
}


// NAVIGATING VIA ARROWS
function featured_one_step(action) {
	var dur = 0.5;
	var curImgPos = $('featuredList').getStyle('top');

	// forward
	if (action == "forward") {
		if (featured_count != max_step) {
			featured_count++;
			// move to next step
			new Effect.Move('featuredList', {
				duration: dur,
				y: -232,
				transition: Effect.Transitions.sinoidal
			});
			
		}
		else if (featured_count == max_step) {
			featured_count = 0;
			// move to next step
			new Effect.Move('featuredList', {
				duration: dur,
				y: 232*max_step,
				transition: Effect.Transitions.sinoidal
			});
		}
	}
	else 
		if (action == "back" && featured_count != min_step) {
			if (featured_count != min_step) {
				featured_count--;
			}
			// move to next step
			new Effect.Move('featuredList', {
				duration: dur,
				y: 232,
				transition: Effect.Transitions.sinoidal
			});
		}
	// reset steps (circles) to 'inactive', make selected one 'active'
	var current_step = "featuredImg-" + featured_count;
	var allItems = $('stepStates').descendants('img');
	$(allItems).each(function(x){
		if ($(x).hasClassName('stepStatesImg')) { // weed out the <a> descendents
			$(x).setAttribute('src', '/images/featured-step-inactive.gif');
			$(current_step).setAttribute('src', '/images/featured-step-active.gif');
		}
	});
}

function featured_auto_scroll() {
	if (featured_count != max_step) {
		featured_count++;
		// move to next step
		new Effect.Move('featuredInfoList', {
			duration: 0.5,
			y: -232,
			transition: Effect.Transitions.sinoidal
		});
		
		new Effect.Move('featuredImgList', {
			duration: 0.5,
			y: -212,
			transition: Effect.Transitions.sinoidal
		});
	}
	else {
		featured_count = 0;
		// move to next step
		new Effect.Move('featuredInfoList', {
			duration: 0.5,
			y: 1160,
			transition: Effect.Transitions.sinoidal
		});
		
		new Effect.Move('featuredImgList', {
			duration: 0.5,
			y: 1060,
			transition: Effect.Transitions.sinoidal
		});
	}
	
	// reset gifs to inactive, make one active
	var current_step = "featuredImg-"+featured_count;
	var allItems = $('stepStates').descendants('img');
	$(allItems).each(function(x) {
		if($(x).hasClassName('stepStatesImg')) { // weed out the <a> descendents
			$(x).setAttribute('src', '/images/featured-step-inactive.gif');
			$(current_step).setAttribute('src', '/images/featured-step-active.gif');
		}
	});
}

// ALL USER FUNCTIONS
function autoSearch() {
	var string = $('vq').getValue();
	new Ajax.Request('/modules/search/.autocomplete.php', {
		parameters: { q: string },
		onComplete: function(r) { 
			$('autoSearchSuggestions').update(r.responseText);
			if(r.responseText != "") {
				$('autoSearchSuggestions').show();
			}
		}
	});
}

function suggestedSearch() {
	var string = $('vq').getValue();
	window.location.href='/search?vq='+string;
}

function list_nav(org, val, ord, page, style) {
	new Ajax.Request('/support/.session_listnav.php', {
		method: 'get',
		parameters: { org: org, val: val, ord: ord, page: page, style: style },
		onComplete: function(r) {
			$('videoList').update(r.responseText);
			// fade in videoList data AFTER it has been rendered -- Smoove
			new Effect.Opacity('videoList', { from: 0, to: 1, duration: 0.5 });
		}
	});
}
function paging(org, val, ord, page, style) {
	new Ajax.Request('/support/.session_listnav.php', {
		method: 'get',
		parameters: { org: org, val: val, ord: ord, page: page, style: style },
		onComplete: function(r) {
			$$('img','.listButton').each(function(el){
				$(el).removeClassName(el.id+'On');
				$(el).addClassName(el.id);
			});
			$(style+'List').addClassName(style+'ListOn');
			$('videoList').update(r.responseText);
			// fade in videoList data AFTER it has been rendered -- Smoove
			new Effect.Opacity('videoList', { from: 0, to: 1, duration: 0.5 });
			new Effect.ScrollTo('videoList', { duration: 0.5, offset: -100, queue: 'end' });
		}
	});
}
function list_ord(ord) {
	// set the order button
	$$('.v_list-order-link').each(function(el){
		$(el).removeClassName('v_list-order-active');
	});
	$('list-order-'+ord).addClassName('v_list-order-active');
}
function list_style(style) {
	// set the list style button
	$$('img','.listButton').each(function(el){
		$(el).removeClassName(el.id+'On');
		$(el).addClassName(el.id);
	});
	$(style+'List').addClassName(style+'ListOn');
}
/*
function list_pref(style, channel, group) {
	// hide videoList data with opacity
	new Effect.Opacity('videoList', { from: 1, to: 0, duration: 0 });
	new Ajax.Request('/support/.session_listtype.php', {
		parameters: { style: style, channel: channel, group: group },
		onComplete: function(r) {
			$$('img','.listButton').each(function(el){
				$(el).removeClassName(el.id+'On');
				$(el).addClassName(el.id);
			});
			$(style+'List').addClassName(style+'ListOn');
			$('videoList').update(r.responseText);
			// fade in videoList data AFTER it has been rendered -- Smoove
			new Effect.Opacity('videoList', { from: 0, to: 1, duration: 0.5 });
		}
	});
}
function list_order(order, channel, group) {
	// hide videoList data with opacity
	new Effect.Opacity('videoList', { from: 1, to: 0, duration: 0 });
	new Ajax.Request('/support/.session_listorder.php', {
		parameters: { order: order, channel: channel, group: group },
		onComplete: function(r) {
			$('videoList').update(r.responseText);
			$$('.v_list-order-link').each(function(el){
				$(el).removeClassName('v_list-order-active');
			});
			$('list-order-'+order).addClassName('v_list-order-active');
			// fade in videoList data AFTER it has been rendered -- Smoove
			new Effect.Opacity('videoList', { from: 0, to: 1, duration: 0.5 });
		}
	});
}
function list_page(style, channel, group, page) {
	// hide videoList data with opacity
	new Effect.Opacity('videoList', { from: 1, to: 0, duration: 0 });
	new Ajax.Request('/support/.session_paging.php', {
		parameters: { style: style, channel: channel, group: group, page: page },
		onComplete: function(r) {
			$$('img','.listButton').each(function(el){
				$(el).removeClassName(el.id+'On');
				$(el).addClassName(el.id);
			});
			$(style+'List').addClassName(style+'ListOn');
			$('videoList').update(r.responseText);
			// fade in videoList data AFTER it has been rendered -- Smoove
			new Effect.Opacity('videoList', { from: 0, to: 1, duration: 0.5 });
			new Effect.ScrollTo('videoList', { 
				duration: 0.5, 
				offset: -100, 
				queue: 'end' });
		}
	});
}
*/
function toggleLogin() {
	if($('v_loginDiv').getStyle('display') == "none") {
		$('v_login-btn').addClassName('active-login');
		$('v_loginDiv').show();
		/*new Effect.Appear('v_loginDiv', {
			from: 0.5,
			to: 1,
			duration: 0.3
		});*/
		$('username').focus();
	}
	else {
		$('v_login-btn').removeClassName('active-login');
		$('v_loginDiv').hide();
	}
	//$('v_loginDiv').toggle();
}

function hoverPointer(element) {
	$(element).addClassName('hover-pointer');
}

function staffTabSwitch(tab) {
	resetStaffTabs();
	if(tab == "v_so-sub-tab") {
		$('subscribeTo').show();
		$('v_so-sub-tab').addClassName('v_so-active-tab');
	}
	if(tab == "v_so-comments-tab") {
		$('commentBox').show();
		$('v_so-comments-tab').addClassName('v_so-active-tab');
	}
	if(tab == "v_so-fav-tab") {
		
	}
}

function resetStaffTabs() {
	$('commentBox').hide();
	$('v_so-comments-tab').removeClassName('v_so-active-tab');
	$('v_so-fav-status').hide();
	$('v_so-fav-tab').removeClassName('v_so-active-tab');
	$('subscribeTo').hide();
	$('v_so-sub-tab').removeClassName('v_so-active-tab');
	$$('.v_so-active-tab').each(function(x) {
		$(x).removeClassName('v_so-active-tab');
	});
}