
//---------------------
//   GLOBALS
//---------------------

var title_orig = document.title;

var RecaptchaOptions = 
{
theme : 'white'
}


//---------------------
//---------------------


//---------------------
function mkIcoColorBWSwitch(e)
{
$(e).hover(
function() {
var img=$("img.img-col-switch", this);
var m=img.attr("src").match(/^(.*)img\/ico\/(.*)/);
if (m && m.length > 2)
{
if (img.attr("src_col"))
{
img.attr("src", img.attr("src_col"));
}
else
{
var nL=m[1]+"img/ico_col/"+m[2];
img.attr("src_col", nL);
img.attr("src_orig", img.attr("src"));
img.attr("src", nL);
}
}
},
function() {
var img=$("img.img-col-switch", this);
if (img.attr("src_orig")) img.attr("src", img.attr("src_orig"));
}
);
}

    
//---------------------
function makeA(c)
{

var cc="";
if (c && c.length > 0) cc = c+" ";

$(cc+"a.a-link").each(function(i)
{
if (!$(this).hasClass("done-a-link"))
{
$(this).prepend("<img class='e img-a img-a-link' src='sf_img/link.png' alt='link'/>");
$(this).addClass("done-a-link");
}
});

$(cc+"a.a-more").each(function(i)
{
if (!$(this).hasClass("done-a-link"))
{
$(this).prepend("<img class='e img-a img-a-more' src='sf_img/more.png' alt='more'/>");
$(this).addClass("done-a-link");
}
});

$(cc+"a.a-less").each(function(i)
{
if (!$(this).hasClass("done-a-link"))
{
$(this).prepend("<img class='e img-a img-a-less' src='sf_img/less.png' alt='less'/>");
$(this).addClass("done-a-link");
}
});

$(cc+"a.a-anch").each(function(i)
{
if (!$(this).hasClass("done-a-link"))
{
$(this).prepend("<img class='e img-a img-a-anch' src='sf_img/anch.png' alt='less'/>");
$(this).addClass("done-a-link");
}
});

}

//---------------------
function makeDivMore(c)
{
var cc="";
if (c && c.length > 0) cc = c+" ";
$(cc+"div.div-more").each(function(i)
{
$(this).hide();
var id="div-more-sysid-"+i;
$(this).attr("id",id);
$(this).before("<a id='a-"+id+"' href='' class='e a-more' onclick=\"$('#"+id+"').toggle(500);$('#a-"+id+"').toggle();event.preventDefault();\">more</a>");
if (!$(this).hasClass('more-no-less')) if ($(".more-toggle",this).size() < 1) $(this).append("<a id='a-less-"+id+"' class='e a-less more-toggle'>less</a>");
$(".more-toggle",this).each(function(i2)
{
$(this).attr("onclick","$('#"+id+"').toggle();$('#a-"+id+"').toggle(500);event.preventDefault();");
$(this).css("cursor","pointer");
});
});
}

//---------------------
function show_loading()
{
$('#div-content-content').html("<img class='e img-loading' src='sf_img/loading.gif' alt='loading...'/>");
}


//---------------------
function axl(e,t)
{
if(t)
{
if (e) e.preventDefault();
loadContent('sf_ajax/'+t+'.php');
}
}

//---------------------
function goa(e,a)
{
if (a)
{
if (e) e.preventDefault();
go(a);
}
}

//---------------------------------------------------------------
function go(i)
{
$(document).scrollTo('#'+i,500,{offset: {top:-30}});
}


//---------------------
function asf(e,f)
{
if (f)
{
var fm=$('#'+f);
if (fm)
{
if (e) e.preventDefault();
$.post(fm.attr('action'), 
       fm.serialize(), 
function(data) 
{
axl(0,'subscribe_ok');
});
}
}
}

//---------------------
function loadContent(u)
{
show_loading();
$('#div-content-content').load(u, function()
{
mkIcoColorBWSwitch($("#div-content-content").get());
});

var subTitle = "";
var m = u.match(/.*\/(.+)\.[a-zA-Z0-9]+$/);
if (m && m.length > 1) subTitle=m[1];
if (subTitle.length > 0) document.title = title_orig + " - " + subTitle.replace('_',' ');

go("div-content-content");
}


//---------------------
function mkCl(e)
{
var m = e.attr('id').match(/^h4\-(.*)$/);
if (m && m.length > 1)
{
var d=$('#div-'+m[1]);
if (d)
{
d.hide();
e.prepend("<img id='img-"+m[1]+"'src='sf_img/ex64.png' alt='+/-'/>");
e.attr("onclick","tog_l('"+m[1]+"')");
e.css("cursor","pointer");
}
}
}

//---------------------
function tog_l(id)
{
var d=$('#div-'+id);
if (d)
{
if (d.is(":hidden"))
{
$("#img-"+id).attr("src","sf_img/cl64.png");
d.show(500);
}
else
{
$("#img-"+id).attr("src","sf_img/ex64.png");
d.hide(500);
}
}
}
 

//---------------------
function makeAjaxyLinks(cid)
{
$(cid+' a[href^="sf_index.php?t="]:not(.no-ajaxy)').each(function(i)
{
var m=$(this).attr("href").match(/^sf_index.php\?t=([a-z0-9_]+)[#|$|&]/);
if (m && m.length > 1)
{
$(this).attr("href", "sf_ajax/"+m[1]+".php");
$(this).addClass("ajaxy");
$(this).removeAttr("onclick");
}
});
}  
 
 
//---------------------
function getNews()
{
$.getFeed(
{
//url:'temp/rss20.xml',
url:'rss.php',
success: function(feed) 
{  
var html = '';    
for(var i = 0; i < feed.items.length && i < 3; i++) 
{
var item = feed.items[i];
var itemStr = (item.description.length>140?item.description.substr(0,140)+'...  <a class="e a-link" href="'+item.link+'" title="show more...">more</a>':item.description);
html += '<div class="e div-news"><h3 class="e"><a class="e" href="'+item.link+'" title="show more..."> '+item.title+'</a></h3>';
html += '<span class="e span-news-date">'+item.updated+'</span>';
html += '<p class="e">'+itemStr.replace("exaLOT","<img class='e img-run-in img-logo-font' src='sf_img/logo_font64.png' alt='exaLOT'/>")+'</p></div>';      
}
$('#jfeed-result').append(html);
makeA("#jfeed-result");  
},    
error: function() 
{
return true;
}
});
}
 
//---------------------------------------------------------------
//---------------------------------------------------------------
$(document).ready(function() 
{

getNews();

//$('#div_good_karma_content').load('sf_ajax/good_karma.php');  Karma is hardloaded because only TXT

//prepare all links to work with ajaxy
makeAjaxyLinks("body");


$.Ajaxy.configure({
'Controllers':{
'_generic':{
request: function()
{
var hash = $.Ajaxy.currentState.hash;
if (hash.indexOf("sf_ajax/")==0) loadContent(hash);
return false;
}}}});

//make menu-links color-able
$("div.div-menu").each(function(i){mkIcoColorBWSwitch(this);});

//make top-menu color-able
$("div#div-top div.div-top").each(function(i){mkIcoColorBWSwitch(this);});

//make all blocks color-able
$("div.div-block").each(function(i){mkIcoColorBWSwitch(this);});

//make all blocks color-able
$("div#div-disqus,div#div-good-karma").each(function(i){mkIcoColorBWSwitch(this);});

//Make more-divs
makeDivMore("body");


//Make a-links
makeA("body");  


});



