// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults



function pause_featured(featured_id, total_posts, other_class, token)
{
    if (window.g_featured_paused == false)
    {
        $$('.feat-pause').each(function(elem) { elem.className = "feat-play"});
        window.g_featured_paused = true;
        window.g_featured_timer.stop();
    }
    else
    {
        $$('.feat-play').each(function(elem) { elem.className = "feat-pause"});
        window.g_featured_paused = false;
        window.g_featured_timer = new PeriodicalExecuter(function(pe){show_featured_post(g_cur_show += 1, total_posts, other_class, token);}, 7);
    }
    

}


function show_featured_post(featured_id, total_posts, other_class, token)
{

    
    
    if (window.g_featured_paused == false)
    {
        window.g_featured_timer.stop();
    window.g_featured_timer = new PeriodicalExecuter(function(pe){show_featured_post(window.g_cur_show += 1, window.g_total_posts, other_class, token);}, 7);   
    }

    if (window.g_cur_show >= window.g_total_posts || window.g_cur_show < 0)
    {
    
        
     //new Ajax.Updater('featured-slider', '/welcome/featured_posts?featured_type=' + other_class, {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent(token)});return 0;
     if (window.g_featured_type == 'o')
        {
            $('q-wrap').setStyle('display:inline');
            $('o-wrap').setStyle('display:none');
            window.g_featured_type = 'q';
            window.g_total_posts = 0;

            $$('.q-featured-post').each(function(elem) { window.g_total_posts +=1 ;});
            $('q-featured-header-link').addClassName('current');
            $('o-featured-header-link').removeClassName('current');
        }
        else
        {
        

            $('o-wrap').setStyle('display:inline');
            $('q-wrap').setStyle('display:none');
            window.g_featured_type = 'o';
             window.g_total_posts = 0;       
             $$('.o-featured-post').each(function(elem) { window.g_total_posts +=1 ;});
            $('o-featured-header-link').addClassName('current');
            $('q-featured-header-link').removeClassName('current');
        } 
        
        if (featured_id < 0)
        {
            window.g_cur_show = window.g_total_posts - 1;
        }
        else
        {
            window.g_cur_show = 0;
        }
        
    
    }

    $$('.q-featured-post').each(function (elem) { elem.style.display = 'none'});
    $$('.o-featured-post').each(function (elem) { elem.style.display = 'none'});
    $$('.featured-hide-title').each(function (elem) { elem.removeClassName('selected')});
    
    
    var selected_post = window.g_featured_type + "-featured-post-" + window.g_cur_show;
    $(selected_post).style.display = 'inline';
    
    var selected_title = window.g_featured_type + '-featured-hide-title-' + window.g_cur_show;
    $(selected_title).addClassName('selected');

}

function signup_foundus_other(elem) {

elem.innerHTML = "<input name='user[foundus]' />";


}

function set_current_profile_tab(elem) {
	
	$$('#profile_header_tabs li.current').each(function(element) { 
		 element.removeClassName('current')
	});
	
	elem.addClassName('current');
}

function set_current_profile_subnav_tab(elem) {
	
	$$('#subnav_tabs li.current').each(function(element) { 
		 element.removeClassName('current')
	});
	
	elem.addClassName('current');
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

var loaded = false;

  function startLoading() {
    loaded = false;
    window.setTimeout('showLoadingImage()', 1000);
  }

  function showLoadingImage() {
    var el = document.getElementById("loading_box");
    if (el && !loaded) {
        el.innerHTML = '<img src="/images/loading.gif">';
$ ( 'loading_box' ).show ( );
    }
  }

  function stopLoading() {
    Element.hide('loading_box');
    loaded = true;
  }

function alternateDisplayVisibility(elemid){
	var elem=document.getElementById(elemid);
	if (elem.style.display == 'none')
		elem.style.display = '';
	else
		elem.style.display = 'none';
	
	
}

function share_facebook(){
  var d=document,f='http://www.facebook.com/share',l=d.location,e=encodeURIComponent,p='.php?src=bm&v=4&i=1248885148&u='+e(l.href)+'&t='+e(d.title);1;try{if (!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);share_internal_bookmarklet(p)}catch(z) {a=function() {if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))l.href=f+p};if (/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}}void(0)
}

function share_digg(){

	var u = encodeURIComponent(document.location.href);
	var t = encodeURIComponent(document.title);
	var url='http://digg.com/submit?url=' + u + "&title=" + t;
	a=function() {if (!window.open(url,'sharer',''))document.location.href=url};if (/Firefox/.test(navigator.userAgent))setTimeout(a,0);else{a()}void(0)
}

function share_twitter_leftos_domain()
{
	
	string = encodeURIComponent("Just invited a bunch of friends to Leftos.com. It's definitely worth checking out! http://bit.ly/aPMdnC #Leftos");
    
    window.open("http://twitter.com/home?status=" + string);
	
}

function share_facebook_leftos_domain()
{
    window.open("http://www.facebook.com/sharer.php?u=http://leftos.com&t=Leftos.com - Lessons For The Opposite Sex")

}
function share_twitter()
{
	
	
	BitlyClient.shorten(document.location.href, 'BitlyCB.shortenResponse');
	
}

function share_select(id, deselect_id)
{
	var header = document.getElementById(id + '-title');
	var elem   = document.getElementById(id);
	var deselect_header = document.getElementById(deselect_id + '-title');
	var deselect_elem = document.getElementById(deselect_id);
	
	header.className = 'send-type stype-selected';
	deselect_header.className = 'send-type'; 
	elem.style.display = 'inline';
	deselect_elem.style.display = 'none';
	
	
}

function swapImages(elemid, img1, img2){
	
	if (document[elemid].src.search(new RegExp(img1)) != -1)
	{
		document[elemid].src = img2;
	}
	
	else{
		document[elemid].src = img1;
	}
}

function hideStateIfNotUS()
 {
   if (document.getElementById('user_country_id').value != '1')
     document.getElementById('state_div').style.display = 'none';
   else
     document.getElementById('state_div').style.display = 'block';
   
 }