var rootDir = '/'
var imagesDir = rootDir + 'images/'
var portfolioDir = imagesDir + 'portfolio/'
var ajax = ''
var loading = false
var modules = new Array()
var portfolios = new Array()
portfolios[1] = new Array("xtoolz.net.ru", "xtoolz.net.ru - 02.2007г. HTML/JS/PERL", "/works/xtoolznetru/", "white")
portfolios[2] = new Array("istugtu", "ИСТ УГТУ - 07.2008г. HTML/JS/PHP", "/works/ugtunetru/", "black")
portfolios[3] = new Array("bits", "BITS - 10.2008г. HTML/JS/PHP", "http://itcomp.ru/", "white")
portfolios[4] = new Array("lepixel", "LePixel - 11.2008г. HTML/JS/PHP", "/LePixel/", "white")
portfolios[5] = new Array("click4wm", "click4wm - 12.2008г. HTML", "/works/click4wm/", "white")
portfolios[6] = new Array("cha0s.ru", "cha0s.ru - 12.2008г. HTML/JS/PHP", "/cha0s.ru/", "white")
portfolios[7] = new Array("moneyeffect.ru", "moneyeffect.ru - 02.2009г. HTML/PHP", "/works/moneyeffect/", "white")
portfolios[8] = new Array("islit.ru", "islit.ru - 03.2009г. PHP", "http://islit.ru/", "white")
portfolios[9] = new Array("montajdveri.ru", "MontajDveri.ru - 03.2009г. HTML/PHP", "/works/montajdveri/", "black")
portfolios[10] = new Array("herbacin.ru", "herbacin.ru - 05.2009г. HTML/PHP", "/works/herbacin/", "white")
portfolios[11] = new Array("protvino-yut.ru", "protvino-yut.ru - 07.2009г. PHP", "http://protvino-yut.ru/", "black")
portfolios[12] = new Array("magic-holidays.ru", "magic-holidays.ru - 11.2009г. JS/PHP", "/works/magicholidays/", "white")
portfolios[13] = new Array("arslonga_sq", "ArsLonga - String quartet - 03.2011г. HTML/JS/PHP", "http://arslonga-sq.ru/", "white")
portfolios[14] = new Array("tp_komi", "Технологии покрытия - 06.2012г. HTML/JS/PHP", "http://tp-komi.ru/", "black")
portfolios[15] = new Array("pie.cha0s.ru", "Easy as PIE - php Framework - 11.2012г. HTML/PHP", "http://pie.cha0s.ru/", "black")
var pcount = portfolios.length - 1
var portfolioTimeout = 7 * 1000
var statusTimeout = 30 * 1000
var portfolioTimeoutId
var statusTimeoutId
var portfolioTimeoutEnabled = false
var statusTimeoutEnabled = true
;jQuery.loadMyImages = function(imgUrls, callback, delay)
{
var allImgs = [],
loaded = 0,
needto = imgUrls.length,
errorDelay = 999,
errorTimer
function onImgComplete()
{
if (++loaded == needto) callback()
else loadImg()
}
function loadImg()
{
allImgs[loaded] = new Image()
$(allImgs[loaded]).bind('error load', onImgComplete)
allImgs[loaded].src = imgUrls[loaded]
}
loadImg()
return 0
};
function InArray(el, arr)
{
for (e in arr)
{
if (e == el) return true
}
return false
}
function LoadedModule(module)
{
return InArray(module, modules)
}
function SaveModule(module, data)
{
if (!LoadedModule(module))
modules[module] = data
}
function SaveCurrentModule()
{
SaveModule($("span.selected").attr('id'), $("#body_content").html())
}
function GetModule(id)
{
ajax = id
$.get(rootDir + 'ajax/' + id, {}, GetModuleCallback)
}
function GetModuleCallback(data)
{
SaveModule(ajax, data)
ShowModule(ajax)
}
function FormContentError(error_obj)
{
error_obj.attr('class', 'error')
error_obj.focus()
error_obj.bind('keydown',
function()
{
me = $(this)
me.unbind('keydown')
me.attr('class', '')
}
);
}
function CheckFeedback()
{
$('form').bind('submit', function(){ return false; })
$('#feed_btn').click(
function()
{
name_obj = $('input:text[@name="name"]')
contact_obj = $('input:text[@name="contact"]')
feed_obj = $('textarea[@name="feed"]')
name = name_obj.attr('value')
contact = contact_obj.attr('value')
feed_t = feed_obj.attr('value')
if ((name == null) || (name == '')) FormContentError(name_obj)
else if ((contact == null) || (contact == '')) FormContentError(contact_obj)
else if ((feed_t == null) || (feed_t == '')) FormContentError(feed_obj)
else
{
loading = true
$.post(rootDir + 'ajax/feed',
{
name: name,
contact: contact,
feed: feed_t
}, function(data)
{
modules['feed'] = data
$("#body_content").fadeOut(600,
function ()
{
$("#body_content").html(modules['feed'])
$("#body_content").fadeIn(600,
function()
{
loading = false
}
);
}
);
}
);
}
}
)
}
function ShowModule(id)
{
var bth = $("td.block_content > table#marking").height()
var nth = Math.max($("td.header > img").height() + 80, $("#body_content > p").height() + 91)
$("td.block_content > table#marking").css('height', $("td.block_content > table#marking").height())
$("#body_content").fadeOut(600,
function ()
{
$("td.header > img").fadeOut(600,
function()
{
$(this).attr('src', imagesDir + id + '.gif')
$.get(imagesDir + id + '.gif', {},
function(data)
{
$("#body_content").html(modules[id])
$("td.block_content > table#marking").animate({height: Math.max($("td.header > img").height() + 80, $("#body_content > p").height() + 91)}, 400,
function()
{
$("td.header > img").fadeIn(600,
function()
{
$("#body_content").fadeIn(600,
function()
{
if (id == 'feed') CheckFeedback()
loading = false
}
)
}
)
}
)
}
)
}
)
}
)
}
function LoadModule(id)
{
if (!loading)
{
loading = true
statusTimeoutEnabled = (id == 'home')
if (id == 'home')
statusTimeoutId = setTimeout("RefreshStatus()", 3000);
else clearTimeout(statusTimeoutId);
var last = $("span.selected")
last.replaceWith("" + last.text() + "")
var current = $("#" + id)
current.replaceWith("" + current.text() + "")
if (!LoadedModule(id)) GetModule(id)
else ShowModule(id)
}
}
function SetPortfolioAutoChange()
{
if (!portfolioTimeoutEnabled)
{
portfolioTimeoutEnabled = true
portfolioTimeoutId = setTimeout("PortfolioAutoChange()", portfolioTimeout)
}
}
function ClearPortfolioTimeout()
{
if (portfolioTimeoutEnabled)
{
portfolioTimeoutEnabled = false
clearTimeout(portfolioTimeoutId)
}
}
function PortfolioAutoChange()
{
if (!loading)
{
LoadPortfolio($("a#next_page").attr("rel"))
} else {
ClearPortfolioTimeout()
SetPortfolioAutoChange()
}
}
function LoadPortfolio(id)
{
if (!loading) {
loading = true
ClearPortfolioTimeout()
ajax = id
$("#prev_page").fadeOut(400)
$("#next_page").fadeOut(400)
$("#portfolio_link").fadeOut(400,
function()
{
$("td#utop").css('height', $("td#utop").height())
$("div#top").fadeOut(500)
$("td#uinfo").css('height', $("td#uinfo").height())
$("td#uinfo > table").fadeOut(500)
$("td#uarrows").css('height', $("td#uarrows").height())
$("td#uarrows > table").fadeOut(500)
$("td#ubottom").css('height', '9')
$("div#bottom").fadeOut(500,
function()
{
$("tr[@id^='type_']").attr('id', 'type_' + portfolios[ajax][3])
$("div#top").css("background-image", 'url("' + portfolioDir + portfolios[ajax][0] + '/top.jpg")')
$("td#info").css("background-image", 'url("' + portfolioDir + portfolios[ajax][0] + '/info.jpg")')
$("td#arrows").css("background-image", 'url("' + portfolioDir + portfolios[ajax][0] + '/arrows.jpg")')
$("div#bottom").css("background-image", 'url("' + portfolioDir + portfolios[ajax][0] + '/bottom.jpg")')
var imgs = new Array(
portfolioDir + portfolios[ajax][0] + '/top.jpg',
portfolioDir + portfolios[ajax][0] + '/info.jpg',
portfolioDir + portfolios[ajax][0] + '/arrows.jpg',
portfolioDir + portfolios[ajax][0] + '/bottom.jpg'
)
$.loadMyImages(imgs, function()
{
$("div#top").fadeIn(500)
$("td#uinfo > table").fadeIn(500)
$("td#uarrows > table").fadeIn(500)
$("div#bottom").fadeIn(500,
function()
{
$("#portfolio_link").text(portfolios[ajax][1]).attr('href', portfolios[ajax][2]).fadeIn(400)
$("#prev_page").attr('rel', (parseInt(ajax) > 1) ? parseInt(ajax) - 1 : pcount).fadeIn(400)
$("#next_page").attr('rel', (parseInt(ajax) < parseInt(pcount)) ? parseInt(ajax) + 1 : 1).fadeIn(400)
loading = false
SetPortfolioAutoChange()
}
)
}
)
}
)
}
)
}
}
function GetPortfolioNumber(addr)
{
var len = addr.length
var ind = addr.lastIndexOf('/')
if (len > ind + 1) return addr.substr(addr.lastIndexOf('/') + 1)
else {
return GetPortfolio(addr.substr(0, ind))
}
}
function SetAIM(proto, status, text)
{
$("div[@rel='" + proto + "']").attr('class', proto + "_" + status).attr('alt', status).attr('title', "cтатус " + proto + " (" + text + ")");
}
function webAppsPresenceStatus(jStatus)
{
var riStatus;
switch (jStatus)
{
case "available":
case "chat":
riStatus = "online";
break;
default:
riStatus = "offline";
break;
}
rjStatus = (riStatus == "online") ? "доступен" : "недоступен";
SetAIM("icq", riStatus, rjStatus);
SetAIM("jabber", riStatus, rjStatus);
}
function RefreshAIM()
{
$.getScript("http://web-apps.ru/jabber-presence/js/xid/4e72176321e8459f91549f091fa443b4/")
}
function RefreshStatus()
{
id = Math.random();
icqStatusImg = "http://wwp.icq.com/scripts/online.dll?icq=847340&img=26&" + id;
skypeStatusImg = "http://mystatus.skype.com/smallicon/cha0s.ru?" + id;
statusImgs = new Array(skypeStatusImg, icqStatusImg);
icqImg = $("img[@rel='icq']");
skypeImg = $("img[@rel='skype']");
$.loadMyImages(statusImgs, function()
{
icqImg.attr('src', icqStatusImg);
skypeImg.attr('src', skypeStatusImg);
RefreshAIM();
if (statusTimeoutEnabled)
statusTimeoutId = setTimeout("RefreshStatus()", statusTimeout);
}
)
}
function Init()
{
$("a[@rel='menulink']").each(
function()
{
this.href = 'javascript:void(0);'
$(this).click(
function()
{
LoadModule(this.id)
}
)
}
)
$("a[@rel='p_nav']").each(
function()
{
this.rel = GetPortfolioNumber(this.href)
this.href = 'javascript:void(0);'
$(this).click(
function()
{
LoadPortfolio(this.rel)
}
)
}
)
SaveCurrentModule()
if ($('#feed_btn').attr('id') != null) CheckFeedback()
SetPortfolioAutoChange()
RefreshAIM();
statusTimeoutId = setTimeout("RefreshStatus()", statusTimeout);
}
$(document).ready(Init)