market = {
	loadToday: function(){
		this.setOns('marketToday');
		$('market_cont').update('<div class="loading">Loading...</div>');
		new Ajax.Request('/home/loadToday/',{ method: 'get',onSuccess: function(t){ $('market_cont').update(t.responseText); }});
	},
	loadWeek: function(){
		this.setOns('marketWeek');
		$('market_cont').update('<div class="loading">Loading...</div>');
		new Ajax.Request('/home/loadWeek/',{ method: 'get',onSuccess: function(t){ $('market_cont').update(t.responseText); }});
	},
	loadMonth: function(){
		this.setOns('marketMonth');
		$('market_cont').update('<div class="loading">Loading...</div>');
		new Ajax.Request('/home/loadMonth/',{ method: 'get',onSuccess: function(t){ $('market_cont').update(t.responseText); }});
	},
	loadRising: function(){
		this.setOns('marketWeek');
		$('market_cont').update('<div class="loading">Loading...</div>');
		new Ajax.Request('/home/loadRising/',{ method: 'get',onSuccess: function(t){ $('market_cont').update(t.responseText); }});
	},
	loadFalling: function(){
		this.setOns('marketWeek');
		$('market_cont').update('<div class="loading">Loading...</div>');
		new Ajax.Request('/home/loadWeek/',{ method: 'get',onSuccess: function(t){ $('market_cont').update(t.responseText); }});
	},
	setOns: function(obj){
		tabs.setOn(obj)
	}
}

var StoryBox = Class.create({
	initialize: function(id){
		if(!$(id)) throw("Attempted to initalize accordion with id: "+ id + " which was not found.");
		this.box = $(id);
		this.isAnimating = false;
		new Effect.Opacity(this.box, { from: 0, to: 0, duration: 0 });
		this.box.observe('mouseover', this.show.bindAsEventListener(this));
		this.box.observe('mouseout', this.hide.bindAsEventListener(this));
		this.anim = false;
	},  
	show: function(){
		this.anim = new Effect.Opacity(this.box, { from: 0, to: .85, duration: .5, transition: Effect.Transitions.sinoidal });
	},
	hide: function(){
		this.anim = new Effect.Opacity(this.box, { from: 1, to: 0, duration: .2, transition: Effect.Transitions.sinoidal });
	}
});

function rebuild_twitter(){

	if($('twitter-content')){
		
		celeb_name = $('twitter-search-name').innerHTML;

		new Ajax.Request('/ajax/twitter_rebuild.php',{
			method: 'get',
			parameters: 'celeb='+celeb_name,
			onSuccess: function(t){
				$('twitter-content').update(t.responseText);
			}
		});

		setTimeout('rebuild_twitter()',30000);
		
	}
	
}

var join = {
	show_form: function(){
		$('join_form_wrap').blindDown({duration: .5});
	},
	close_form: function(){
		$('join_form_wrap').blindUp({duration: .5});
	},
	check_dup_username: function(){
		var username = $('join_username').value;
		$('dup_username_msg').removeClassName("good");
		$('dup_username_msg').removeClassName("bad");
		$('dup_username_msg').update("");
		if(!username){
			$('join_error').value = 1;
			$('dup_username_msg').addClassName("bad");
			$('dup_username_msg').update("Specify a Username");
			return 'false';
		}else{
			new Ajax.Request('/ajax/join.php',{
				method: 'get',
				parameters: 'fuse=check_dup_username&username='+username,
				onSuccess: function(t){
					if(t.responseText == 'ok'){
						$('dup_username_msg').addClassName("good");
						$('dup_username_msg').update("It's Available!");
						return 'true';
					}else{
						$('join_error').value = 1;
						$('dup_username_msg').addClassName("bad");
						$('dup_username_msg').update("It's Taken");
						return 'false';
					}
				}
			});
		}
	},
	check_email: function(){
		var email = $('join_email').value;
		$('join_email_msg').removeClassName("bad");
		$('join_email_msg').update("");
		if(!email){
			$('join_error').value = 1;
			$('join_email_msg').addClassName("bad");
			$('join_email_msg').update("Invalid Email Address");
			return 'false';
		}else{
			new Ajax.Request('/ajax/join.php',{
				method: 'get',
				parameters: 'fuse=check_email&email='+email,
				onSuccess: function(t){
					if(t.responseText == 'ok'){
						$('join_email_msg').update("");
						return 'true';
					}else{
						$('join_error').value = 1;
						$('join_email_msg').addClassName("bad");
						$('join_email_msg').update("Invalid Email Address");
						return 'false';
					}
				}
			});
		}
	},
	process: function(){
		$('join_error').value = '';
		join.check_dup_username();
		join.check_email();
		if($('join_error').value != 1){
			var data = $('join_form').serialize();
			$('join_form_wrap').update('<h2>Creating Account...</h2><p>Just one sec while we create your account.</p>');
			new Ajax.Request('/ajax/join.php',{
				method: 'get',
				parameters: 'fuse=process&'+data,
				onSuccess: function(t){
					$('join_form_wrap').update(t.responseText);
				}
			});
		}
	}
}


var login = {
	show_form: function(){
		if($('login_form_wrap').style.display == 'none'){
		$('login_form_wrap').blindDown({duration: .2});
		}else{
			$('login_form_wrap').blindUp({duration: .2});
		}
	},
	close_form: function(){
		$('login_form_wrap').blindUp({duration: .5});
	},
	process: function(){
		var data = $('login_form').serialize();
		$('login_form_wrap').update('<h2>Logging In, One second please...</h2>');
		new Ajax.Request('/ajax/login.php',{
			method: 'post',
			parameters: 'fuse=login&'+data,
			onSuccess: function(t){
				$('login_form_wrap').update(t.responseText);
				if(t.responseText == 'Invalid Username / Password'){
					$('login_form_wrap').blindUp({
						delay: 2, duration: .3,
						afterFinish: function(){
							new Ajax.Request('/ajax/login.php',{
								parameters: 'fuse=login_form',
								method: 'post',
								onSuccess: function(t){ 
									$('login_form_wrap').update(t.responseText); 
									$('login_form_wrap').blindDown({ duration: .3 }); 
								}
							});
					}});
				}else{
					$('login_form_wrap').blindUp({
						duration: .3,
						afterFinish: function(){
							$('login_nav').update(t.responseText);
							new Ajax.Request('/ajax/login.php',{
								parameters: 'fuse=settings_menu',
								method: 'post',
								onSuccess: function(t){
									$('login_form_wrap').update(t.responseText); 
								}
							});
						}
					});
				}
			}
		});
	}
}

var search_in_progress = false;
var search_hide_now = false;

search = {
	run: function(){
		search_hide_now = false;
		var search_string = $('search_q').value;
		if(search_string.length > 2){
			if(search_in_progress == false){
				$('search_results').appear();
			}
			search_in_progress = true;
			$('search_results').update("<div class='empty-result'>Loading Search Results for '" + search_string + "'</div>");
			var search_results = new Ajax.Request('/search/get_results',{
				method: 'post',
				parameters: 'search_q='+search_string,
				onSuccess: function(t){
					$('search_results').update(t.responseText);
				}
			});
		}
	},
	hide: function(){
		setTimeout('search.do_hide()',1500);
		search_hide_now = true;
	},
	do_hide: function(){
		if(search_hide_now == true){
			search.close();
		}
	},
	close: function(){
			$('search_results').fade({
				duration: .2,
				afterFinish: function(){
					search_in_progress = false;
					$('search_results').update('');
				}
			});	
	},
	show: function(){
		search_hide_now = false;
		$('search_results').appear();
	}
}

function geoTagInit() {
	
	if($('mapCanvas')){
	  	var latLng = new google.maps.LatLng(40.77180275899053,-100.89843775000001);
	  	var map = new google.maps.Map(document.getElementById('mapCanvas'), {
	    	zoom: 4,
	    	center: latLng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
	  	});
	}
	
	if($('mapCanvasData')){
		$$('#mapCanvasData .locStats').each(function(s){
			var parts = s.innerHTML.split('|');
			var latLng = new google.maps.LatLng(parts[0],parts[1]);
  			var marker = new google.maps.Marker({
	    		position: latLng,
	    		title: parts[2],
	    		map: map
	  		});
			var infowindow = new google.maps.InfoWindow({
        		content: "<div style='width: 220px;height: 220px;'><img src='"+parts[3]+"' border='0' /></div>"
    		});
    		google.maps.event.addListener(marker, 'click', function() {
      			infowindow.open(map,marker);
    		});
		});
	}
  
}

function showClass(cn){
	$$('.'+cn).each(function(s){
		s.appear();
	});
}
/*
tabs = {
	init: function(){
		$('marketCurrent').observe('mouseover',function(){
			this.up().setStyle('background-position-y: -33px');
		});
		$('marketCurrent').observe('mouseout',function(){
			this.up().setStyle('background-position-y: 0px');
		});
		$('marketRising').observe('mouseover',function(){
			this.up().setStyle('background-position-y: -66px');
		});
		$('marketRising').observe('mouseout',function(){
			this.up().setStyle('background-position-y: 0px');
		});
		$('marketFalling').observe('mouseover',function(){
			this.up().setStyle('background-position-y: -99px');
		});
		$('marketFalling').observe('mouseout',function(){
			this.up().setStyle('background-position-y: 0px');
		});
	},
	setOn: function(obj){
		if(obj == ''){
			
		}
	}
}
*/


document.observe("dom:loaded", function(){
//	tabs.init();
	$$('.celebName').each(function(s){
		s.setOpacity(.5);
		s.up().observe('mouseover',function(){
			s.setOpacity(1);
		});
		s.up().observe('mouseout',function(){
			s.setOpacity(.5);
		});
	});
});

