// JavaScript Document

var visible_list="none";
var base_url;
//base_url = "http://localhost:8000/";//get_base_url()+"/";
media_url = "http://media2.dreamnowtest.com/";

function get_base_url() {
    var css_url = document.styleSheets[0].href;
    var last_slash = css_url.lastIndexOf('/css');
    return css_url.substr(0,last_slash);
}

function get_random_entry(type){
	if (type=='events'){
		new_type='events';
	} else if (type=='organizations'){
		new_type='organizations';
	} else if (type=='links'){
		new_type='links';
	}
	new Ajax.Updater(type,base_url+'ajax/questions/get_random_related/', {
					method:'get',
					parameters:{question_id:qid,type:new_type},
					evalScripts:true,
					onLoading: function(){
						$(type).innerHTML='<img class="loading-icon" src="'+media_url+'images/dn-home/ajax-loading.gif" alt="Loading..." />';
					}
	});
	
					
}

function get_related_list(type){
	if (type=='events'){
		new_type='events';
	} else if (type=='organizations'){
		new_type='organizations';
	} else if (type=='links'){
		new_type='links';
	}
	new Ajax.Updater(type+"_list",base_url+'ajax/questions/get_related_list/', {
					method:'get',
					parameters:{question_id:qid,type:new_type},
					evalScripts:true,
					onLoading: function(){
						$(type+"_list").innerHTML='<img class="loading-icon" src="'+media_url+'images/dn-home/ajax-loading.gif" alt="Loading..." />';
					}
	});
}

function load_item(type,item_id){
	if (type=='events'){
		new_type='events';
	} else if (type=='organizations'){
		new_type='organizations';
	} else if (type=='links'){
		new_type='links';
	}
	new Ajax.Updater(type,base_url+'ajax/questions/get_related_item/', {
					method:'get',
					parameters:{question_id:qid,type:new_type,item_id:item_id},
					evalScripts:true,
					onLoading: function(){
						$(type).innerHTML='<img class="loading-icon" src="'+media_url+'images/dn-home/ajax-loading.gif" alt="Loading..." />';
					}
	});
}

function toggle_list(type){
	if ($(type+"_list").visible()){
		hide_list(type);
	} else {
		show_list(type);
	}
}

function show_list(type){
	new Effect.SlideDown(type+"_list",0.5);
	
	if (type=='events'){
		hide_list('organizations');
		hide_list('links');
	} else if (type=='organizations'){
		hide_list('events');
		hide_list('links');
	} else if (type=='links'){
		hide_list('organizations');
		hide_list('events');
	}
}

function hide_list(type){
	if (exists[type]==true){
		if ($(type+"_list").visible()){
			new Effect.SlideUp(type+"_list",0.5);
		}
	}
}

function hide_all_lists(){
	if (exists['events']){ Element.hide('events_list'); }
	if (exists['links']){ Element.hide('links_list'); }
	if (exists['organizations']){ Element.hide('organizations_list'); }
}
		
	
