// JavaScript Document

//window.onload = init();

function init() {
	return true;
}

var more_details = 'more_details_container';
var more_details_item_path;
function display_more_details(path) {
	$(more_details).style.top = mouse_y+'px';
	$(more_details).style.left = (mouse_x-$(more_details).offsetWidth-30)+'px';
	$(more_details).scrollTo();
	document.documentElement.scrollTop = document.documentElement.scrollTop - 60;
/*	if(document.documentElement.scrollTop == 0) //for IE8 and earlier
		document.body.scrollTop = document.body.scrollTop - 60;*/
	
	more_details_item_path = encodeURIComponent(path);
	display_tab('rom_details_tab', null, null, more_details_item_path);
}

var displayed_tab = 'rom_details_tab'; //this should be changed to the default tab (id of tab to be used)
function display_tab(id, action, responseText) {
	if(action == 'response') {
		$(id).innerHTML = responseText;
		return;
	}
	
	if(id == 'rom_details_tab') {
		ajax_request('dirLIST_files/custom_development/rom_details_tab.php?folder='+get_folder+'&item_path='+more_details_item_path, id);
	} else if(id == 'comments_tab') {
		ajax_request('dirLIST_files/custom_development/comments_reviews_tab.php?post_type=comments&folder='+get_folder+'&item_path='+more_details_item_path, id);
	} else if(id == 'reviews_tab') {
		ajax_request('dirLIST_files/custom_development/comments_reviews_tab.php?post_type=reviews&folder='+get_folder+'&item_path='+more_details_item_path, id);
	} else if(id == 'screenshots_tab') {
		ajax_request('dirLIST_files/custom_development/screenshots_tab.php?folder='+get_folder+'&item_path='+more_details_item_path, id);
	}
	
	$(displayed_tab).style.display = 'none';
	$(displayed_tab+'_button').style.backgroundColor = '';
	$(id).style.display = 'block';
	$(id+'_button').style.backgroundColor = '#4D4D4D'; //color of the active tab button
	displayed_tab = id;
	
	return true;
}

function ajax_request(url, action) {
	xhr = new XMLHttpRequest();
	
	xhr.open('get', url, true);
  	xhr.onreadystatechange = function () {
		if(xhr.readyState == 4) {
			display_tab(action, 'response', xhr.responseText);
		}
	}
  	xhr.send(null);
}

function toggle_div(status, type) {
	if(status == 'show') {
		if(type == 'comment') {
			$('add_user_post_comment_button').style.display = 'none'; 
			$('add_user_post_comment').style.display = 'block';
			setTimeout('$("user_post_comment_text").focus()', 10);
		} else if (type == 'review') {
			$('add_user_post_review_button').style.display = 'none';
			$('add_user_post_review').style.display = 'block';
			setTimeout('$("user_post_review_text").focus()', 10);
		} else if (type == 'screenshots') {
			$('add_screenshots_button').style.display = 'none';  
			$('add_screenshots').style.display = 'block';  
  		}
	} else {
		if(type == 'comment') {
			$('add_user_post_comment_button').style.display = 'block';
			$('add_user_post_comment').style.display = 'none';
		} else if(type == 'review') {
			$('add_user_post_review_button').style.display = 'block';
			$('add_user_post_review').style.display = 'none';
		} else if (type == 'screenshots') {
			$('add_screenshots_button').style.display = 'block';
			$('add_screenshots').style.display = 'none';
		}
	}
}

var comment_length_limit = 500;
function limit_comment(obj) {
	current_length = obj.value.length;
	if (current_length > comment_length_limit)
		obj.value = obj.value.substring(0, comment_length_limit);
	$('comment_length_counter').innerHTML = comment_length_limit - obj.value.length;
}

var top_10_display = 'none';
function toggle_top_10() {
	if(top_10_display == 'none')
		top_10_display = 'block';
	else
		top_10_display = 'none';
	
	$('top_10').style.display = top_10_display;
}

function toggle_login(action) {
	if(action == 'show') {
		$('login_div_container').style.left = '390px';
		$('login_div_container').scrollTo();
	}
	else {
		$('login_div_container').style.left = '-5000px';
	}
}

function pop_up(URL) {
window.open(URL, '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1000,height=860');
return false;
}
