if (typeof blog_spath != 'undefined')
{
	// Adapted from Dean Edwards's code @ http://dean.edwards.name/my/busted3.html
	// Safari
	if (/WebKit/i.test(navigator.userAgent)) {
		var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				clearInterval(_timer);
				delete _timer;
				initBlog(); // call the onload handler
			}
		}, 10);
	} // Mozilla, Opera 9
	else if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", initBlog, false);
	}

	// Internet Explorer (using conditional comments)
	/*@cc_on @*/
	/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			initBlog(); // call the onload handler
		}
	};
	/*@end @*/

	/* Other browsers */
	window.onload = initBlogWrapper;
}

var is_ie = 0;
var overture_status = false;
var _query = false;
var _GET = new Array();
buildGetArray();

/*
	Base, version 1.0.2
	Copyright 2006, Dean Edwards
	License: http://creativecommons.org/licenses/LGPL/2.1/
*/

var Base = function() {
	if (arguments.length) {
		if (this == window) { // cast an object to this class
			Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
		} else {
			this.extend(arguments[0]);
		}
	}
};

Base.version = "1.0.2";

Base.prototype = {
	extend: function(source, value) {
		var extend = Base.prototype.extend;
		if (arguments.length == 2) {
			var ancestor = this[source];
			// overriding?
			if ((ancestor instanceof Function) && (value instanceof Function) &&
				ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
				var method = value;
			//	var _prototype = this.constructor.prototype;
			//	var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
				value = function() {
					var previous = this.base;
				//	this.base = fromPrototype ? _prototype[source] : ancestor;
					this.base = ancestor;
					var returnValue = method.apply(this, arguments);
					this.base = previous;
					return returnValue;
				};
				// point to the underlying method
				value.valueOf = function() {
					return method;
				};
				value.toString = function() {
					return String(method);
				};
			}
			return this[source] = value;
		} else if (source) {
			var _prototype = {toSource: null};
			// do the "toString" and other methods manually
			var _protected = ["toString", "valueOf"];
			// if we are prototyping then include the constructor
			if (Base._prototyping) _protected[2] = "constructor";
			for (var i = 0; (name = _protected[i]); i++) {
				if (source[name] != _prototype[name]) {
					extend.call(this, name, source[name]);
				}
			}
			// copy each of the source object's properties to this object
			for (var name in source) {
				if (!_prototype[name]) {
					extend.call(this, name, source[name]);
				}
			}
		}
		return this;
	},

	base: function() {
		// call this method from any other method to invoke that method's ancestor
	}
};

Base.extend = function(_instance, _static) {
	var extend = Base.prototype.extend;
	if (!_instance) _instance = {};
	// build the prototype
	Base._prototyping = true;
	var _prototype = new this;
	extend.call(_prototype, _instance);
	var constructor = _prototype.constructor;
	_prototype.constructor = this;
	delete Base._prototyping;
	// create the wrapper for the constructor function
	var klass = function() {
		if (!Base._prototyping) constructor.apply(this, arguments);
		this.constructor = klass;
	};
	klass.prototype = _prototype;
	// build the class interface
	klass.extend = this.extend;
	klass.implement = this.implement;
	klass.toString = function() {
		return String(constructor);
	};
	extend.call(klass, _static);
	// single instance
	var object = constructor ? klass : _prototype;
	// class initialisation
	if (object.init instanceof Function) object.init();
	return object;
};

Base.implement = function(_interface) {
	if (_interface instanceof Function) _interface = _interface.prototype;
	this.prototype.extend(_interface);
};

function addSkyblogVisiblyStuff()
{
	var endroit = document.getElementById('pseudo_value');
	var p = document.createElement('p');
	var t = document.createTextNode('0%');

	p.id = 'skyblogvisibly-vote-percentage';
	p.style.marginTop = '1em';
	if (typeof skyblogvisibly_votes != 'undefined' && typeof skyblogvisibly_votes[pseudo] != 'undefined')
 		t.data = skyblogvisibly_votes[pseudo] + '%';
	p.appendChild(t);
	endroit.parentNode.insertBefore(p, endroit.nextSibling);

	endroit = p;
	p = document.createElement('div');
	p.id = "skyblogvisibly-vote-button";
	var str  = '<a href="http://www.skyblog.com/php/vote_skyblogvisibly.php/pseudo/' + pseudo + '" onclick="window.open(this.href, \'\', \'width=400,height=300\'); return false;">';
	    str += '<img src="http://www.skyblog.com/img/skyblogvisibly_boutonvote.jpg" alt="Vote pour ton Skyblog Visibly préféré" /></a>';
	p.innerHTML = str;
	endroit.parentNode.insertBefore(p, endroit.nextSibling);
}

function addSkyblogTestStuff()
{
	var endroit = document.getElementById('pseudo_value');
	var p = document.createElement('p');
	var t = document.createTextNode('0%');

	p.id = 'skyblogtest-vote-percentage';
	p.style.marginTop = '1em';
	if (typeof skyblogtest_votes != 'undefined' && typeof skyblogtest_votes[pseudo] != 'undefined')
		t.data = skyblogtest_votes[pseudo] + '%';
	p.appendChild(t);
	endroit.parentNode.insertBefore(p, endroit.nextSibling);

	endroit = p;
	p = document.createElement('div');
	p.id = "skyblogtest-vote-button";
	var str  = '<a href="http://www.skyblog.com/php/vote_skyblogtest.php/pseudo/' + pseudo + '" onclick="window.open(this.href, \'\', \'width=400,height=300\'); return false;">';
	    str += '<img src="http://www.skyblog.com/img/skyblogvisibly_boutonvote.jpg" alt="Vote pour ton Skyblog test préféré" /></a>';
	p.innerHTML = str;
	endroit.parentNode.insertBefore(p, endroit.nextSibling);

	endroit = document.getElementById('faistourner');

	p = document.createElement('div');
	var str  = '<a style="display: block; text-align: center;" "href="http://www.apple.com/fr/itunes/" onclick="window.open(this.href); return false;"><img src="http://www.skyblog.com/pics/skyblogtest_logoitunes.gif" alt="iTunes" /></a>';
	if (typeof display_itunes_rss_from_js_file != 'undefined' && typeof flatrss_rap != 'undefined' && typeof flatrss_rnb != 'undefined')
	{
		str += '<dl>';
		str += '<dt>Top 3 Rap iTunes :</dt>';
		str += '<dd>' + display_itunes_rss_from_js_file(flatrss_rap) + '</dd>';
		str += '<dt>Top 3 R&amp;B iTunes :</dt>';
		str += '<dd>' + display_itunes_rss_from_js_file(flatrss_rnb) + '</dd>';
		str += '</dl>';
	}
	p.innerHTML = str;
	endroit.parentNode.insertBefore(p, endroit.nextSibling);
}

function addMiscInfo()
{
	var nb_infos = 0;
	var infos = document.getElementById('infos');
	var dl    = document.createElement('dl');
	var dt    = document.createElement('dt');
	var dd    = document.createElement('dd');
	var ul    = document.createElement('ul');
	var li;
	var txt;

	if (typeof nb_articles != 'undefined')
	{
		li  = document.createElement('li');
		txt = document.createTextNode(nb_articles + ' article' + (nb_articles > 1 ? 's' : ''));
		li.appendChild(txt);
		ul.appendChild(li);
		nb_infos++;
	}
        if (typeof nb_comments != 'undefined' && typeof blog_with_comments != 'undefined' && blog_with_comments == 1)
        {
                li  = document.createElement('li');
                txt = document.createTextNode(nb_comments + ' commentaire' + (nb_comments > 1 ? 's' : ''));
                li.appendChild(txt);
		ul.appendChild(li);
		nb_infos++;
        }
	if (typeof nb_amis != 'undefined' &&((typeof skyblog_ope == 'undefined') || skyblog_ope != 'skyblogtest'))
        {
                if (nb_amis > 0)
		{
			li  = document.createElement('li');
			txt = document.createTextNode(nb_amis + ' ami' + (nb_amis > 1 ? 's' : ''));
			li.appendChild(txt);
			ul.appendChild(li);
			nb_infos++;
		}
		else
		{
			if (document.getElementById('amis'))
				document.getElementById('amis').style.display = 'none';
		}
        }
	if (0 && typeof music_titres != 'undefined' && music_titres.length > 0)
        {
                li  = document.createElement('li');
                txt = document.createTextNode(music_titres.length + ' morceau' + (music_titres.length > 1 ? 'x' : ''));
                li.appendChild(txt);
		ul.appendChild(li);
		nb_infos++;
        }
	if (ul.childNodes.length == 0 || !infos)
		return;
	txt  = document.createTextNode('Autre' + (nb_infos > 1 ? 's' : '') + ' info' + (nb_infos > 1 ? 's' : '') + ' :');
	dt.appendChild(txt);
	dd.appendChild(ul);
	infos.appendChild(dt);
	infos.appendChild(dd);
}

function addPagination()
{
	var pagination = document.getElementById('pagination');

	if (typeof blog_nb_page != 'undefined' && pagination)
	{
		if (blog_nb_page > 5)
		{
			var form   = document.createElement('form');
			var div    = document.createElement('div');
			var txt    = document.createTextNode('Sélectionne une page : ');
			var select = document.createElement('select');

			div.appendChild(txt);
			select.name = "chpage";
			select.onchange = sb_change_page;
			for (var c = 1; c <= blog_nb_page; c++)
			{
				var option = document.createElement('option');
				txt = document.createTextNode('Page n°' + c + ' sur ' + blog_nb_page);
				if (c == blog_cur_page)
					option.selected = "selected";
				option.value = c;
				option.appendChild(txt);
				select.appendChild(option);
			}
			div.appendChild(select);
			form.appendChild(div);
			pagination.appendChild(form);
		}
		return true;
	}
	return false;
}

// cette fonction d'init est appellée uniquement onload, et dans tous les cas, meme si on a pu
// faire un DOMContentLoaded ou équivalent. Ya ensuite un check dans initBlog pour pas refaire
// tout le bordel qu'on a deja fait, et ensuite dans celle la le resize et bordel.
function initBlogWrapper()
{
	initBlog();
	
	resizeColumns();
	addLegalLine(); // addLegalLine() est ici pour éviter de sauter plus bas avec le resizeColumns().
	window.onresize = resizedBlog;
}

function initBlog()
{
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	if (typeof is_music != 'undefined' &&
	    typeof generatePlayer != 'undefined' &&
	    typeof blog_cur_page != 'undefined' &&
	    is_music != 0 &&
	    blog_cur_page != 0)
	{
		generatePlayer(document, false);
	}
	if (typeof has_video != 'undefined' &&
	         typeof generateAllPlayersForVideos != 'undefined' &&
	         typeof blog_cur_page != 'undefined' &&
	         has_video != 0)
	{
		generateAllPlayersForVideos();
	}
	if (typeof amis_init != 'undefined')
	{
		// page avec la liste d'amis
		amis_init();
	}
	if (typeof download_music_init != 'undefined')
	{
		// page de telechargement du morceau
		download_music_init();
	}
}

function debug()
{
	var menu = document.getElementById('menu');
	var p    = document.createElement('p');
	var t;
	var br;

	p.style.border = '1px solid orange';
	p.style.backgroundColor = '#F3CE8E';
	p.style.color = '#000000';

	t  = document.createTextNode('preInit(): ' + (window.b.getTime() - window.a.getTime()) + ' ms')
	br = document.createElement('br');
	p.appendChild(t);
	p.appendChild(br);
	t  = document.createTextNode('initBlog(): ' + (window.c.getTime() - window.b.getTime()) + ' ms')
	p.appendChild(t);

	menu.insertBefore(p, menu.firstChild);
}

function preInitBlog()
{
	if (pseudo == "mat") // hack rapide pour tester les différents templates
	{
		initCMR();
	}
	if (/MSIE ((5\.5)|[6])/.test(navigator.userAgent) && navigator.platform == "Win32")
		is_ie = 1;
	if (typeof skyblog_ope != 'undefined' && skyblog_ope == 'skyblogtest')
		addSkyblogTestStuff();
	else if (typeof skyblog_ope != 'undefined' && skyblog_ope == 'skyblogvisibly')
		addSkyblogVisiblyStuff()
	if (typeof tpl_ver != 'undefined' && parseInt(tpl_ver) == 2)
	{
		nb_comments = getNbComments();
		addMiscInfo();
		addBv();
		addAddFriendLink();
		addComments();
	}
	addPagination();
}

var antikloop = false;
// si appelle par script ou pub...
function resizeBlog()
{
	if (typeof pub_is_megaban != 'undefined' && pub_is_megaban > 0)
		publog_changelogo();
	antikloop = false;
	resizeColumns();
}

// si appelle par onresize ça peut peut etre partir en kloop.
function resizedBlog()
{
	if (typeof pub_is_megaban != 'undefined' && pub_is_megaban > 0)
		publog_changelogo();
	resizeColumns();
}

function resizeColumns()
{
	if (antikloop != false)
	{
		antikloop = false;
		return;
	}
	if (idtpl == 42)
		return;
	var root = document.documentElement;
	var main = document.getElementById('main');
	var menu = document.getElementById('menu');
	var top  = document.getElementById('top');

	if (!top || !menu || !main || !root)
		return;

	var want = parseInt(root.scrollHeight) - parseInt(top.offsetHeight) - 1;

	// IE n'interprete pas minHeight, mais ya deja un expression() qui fait la
	// meme chose dans la CSS pour lui, mais on repasse un coup derriere pour
	// pouvoir utiliser scrollHeight.
	if (is_ie)
	{
		main.style.height = want + 'px';
		menu.style.height = want + 'px';
		antikloop = true;
		// le changement ici provoque un onresize et donc ça "k loop"
	}
	else
	{
		main.style.minHeight = want + 'px';
		menu.style.minHeight = want + 'px';
	}
}

function buildGetArray()
{
	_GET = new Array();
	_query = location.search.substring(1);
	if (_query.length > 0)
	{
		var params = _query.split("&");
		for (var i = 0; i < params.length; i++)
		{
			var pos = params[i].indexOf("=");
			var name = params[i].substring(0, pos);
			var value = params[i].substring(pos + 1);
			_GET[name] = value;
		}
	}
}

function initCMR()
{
	if (typeof _GET['cmr'] != 'undefined')
	{
		idtpl = parseInt(_GET['cmr']);
		document.getElementsByTagName('link')[1].href = www_path + 'x-css/v2/' + idtpl + '.css';
	}
}

function addLegalLine()
{
	if (pseudo != 'mat')
		return;
	var line_content = '<ul id="skynetwork">';
	   line_content += '<li class="title">Skyrock Network :</li>';
	   line_content += '<li><a href="http://www.skyblog.com/" onclick="window.open(this.href); return false;">Skyblog</a></li>';
	   line_content += '<li><a href="http://www.skyrock.com/" onclick="window.open(this.href); return false;">Skyrock</a></li>';
	   line_content += '<li><a href="http://www.skymobile.com/" onclick="window.open(this.href); return false;">Skymobile</a></li>';
	   line_content += '<li><a href="http://www.skyrockmessager.com/" onclick="window.open(this.href); return false;">Skyrock Messager</a></li>';
	   line_content += '<li><a href="http://www.tasante.com/" onclick="window.open(this.href); return false;">Tasante</a></li>';
	   line_content += '<li><a href="http://www.ladiz.fr/" onclick="window.open(this.href); return false;">Ladiz</a></li>';
	   line_content += '<li><a href="http://www.tropmalin.com/" onclick="window.open(this.href); return false;">Tropmalin</a></li>';
	   line_content += '<li><a href="http://www.bonbiz.net/" onclick="window.open(this.href); return false;">Bonbiz</a></li>';
	   line_content += '</ul>';
	
	var div = document.createElement(div);
	div.innerHTML = line_content;
	document.body.appendChild(div);
}

function addComments()
{
	if (typeof articles_ids == 'undefined')
		return;
	if (typeof blog_with_comments != 'undefined' && !blog_with_comments)
		return;
	var len = articles_ids.length;

	// FIXME: pour le moment articles_ids est pas mis correctement
	// quand ya pas de commentaire
	for (var i = 0; i < len; i++)
	{
		addCommentsLink(parseInt(articles_ids[i]), 0);
	}
}

function openVocalWindow(e)
{
	if (this == window)
		var elm = e;
	else
		elm = this;
	window.open(elm.href, 'vocal_' + pseudo.replace(/-/g, '_'), 'location=no,toolbar=no,resizable=no,scrollbars=no,width=300,height=104');
	return false;
}

function openCommentsWindow(e)
{
	if (this == window)
		var elm = e;
	else
		elm = this;
	window.open(elm.href, 'rcommentaire_' + pseudo.replace(/-/g, '_'), 'location=no,toolbar=no,resizable=yes,scrollbars=yes,width=550,height=600');
	return false;
}

function openAddFriendWindow(e)
{
	if (this == window)
		var elm = e;
	else
		elm = this;
	window.open(elm.href, 'amisamis_' + pseudo.replace(/-/g, '_'), 'location=no,toolbar=no,resizable=yes,scrollbars=yes,width=750,height=600');
	return false;
}

function openAddCommentWindow(elm)
{
	var url = elm.href;
	if(typeof(is_music) != 'undefined' && is_music != 0) {
		url += '&is_music_tpl=' + escape(is_music);
	}
	url += '&display_pseudo=' + escape(pseudo);
	if (idtpl == 42)
		window.open(url, 'commentaire_' + pseudo.replace(/-/g, '_'), 'width=920,height=490');
	else
		window.open(url, 'commentaire_' + pseudo.replace(/-/g, '_'), 'width=680,height=480');
	return false;
}

function openFriendsAnonymeWindow(elm)
{
	window.open(elm.href, 'friendsAnonyme_' + pseudo.replace(/-/g, '_'), 'width=680,height=400');
	return false;
}

function openCybercopWindow(elm)
{
	window.open(elm.href, 'cybercop_' + pseudo.replace(/-/g, '_'), 'width=680,height=550');
	return false;
}

function openPhotoWindow(elm)
{
	window.open(elm.href, 'photo_' + pseudo.replace(/-/g, '_'), 'location=no,toolbar=no,resizable=yes,width=400,height=400');
	return false;
}

function openEnvoyerWindow(elm)
{
	window.open(elm.href, 'cybercop_' + pseudo.replace(/-/g, '_'), 'width=680,height=350');
	return false;
}

function addAddFriendLink()
{
	var amis = document.getElementById('amis');

	if (amis && pseudo != 'devteam')
	{
		var a = document.createElement('a');
		a.id = "add-friend-link";
		a.href = www_path + 'admBloger/amis_add.php?id_template=' + idtpl + '&id_skynaute=' + id_skynaute + '&display_pseudo=' + pseudo;
		a.appendChild(document.createTextNode('Ajouter à mes amis'));
		a.onclick = openAddFriendWindow;
		amis.parentNode.insertBefore(a, amis);
	}
}

function addCommentsLink(id, count)
{
	var sp = '';
	var txt;
	var d = document.getElementById('c-' + id);

	if (!d)
	{
		return;
	}
	if (typeof blog_spath != 'undefined')
		sp = blog_spath;
	if (typeof nbcommentaire != 'undefined')
	{
		var n = nbcommentaire[id];
		if (n)
		{
			var c = '';
			if (typeof idtpl != 'undefined')
				c = '?' + idtpl;

			var a     = document.createElement('a');
			a.href    = sp + id + '_comment_1.html' + c;
			a.onclick = openCommentsWindow;
			txt       = document.createTextNode(' [ ');
			d.appendChild(txt);
			txt       = document.createTextNode(n + ' commentaire' + (n > 1 ? 's' : ''));
			a.appendChild(txt);
			txt       = document.createTextNode(' ]');
			d.appendChild(a);
			d.appendChild(txt);
			return;
		}
	}
	txt = document.createTextNode(' [ Aucun commentaire ] ');
	d.appendChild(txt);
}

function getNbComments()
{
	if (typeof nbcommentaire != 'undefined')
	{
		var somme = 0;
		for (var i in nbcommentaire)
		{
			somme += nbcommentaire[i];
		}
		return somme;
	}
	return 0;
}

function openBvWindow(e)
{
	window.open(this.href, 'bv_online', 'width=300,height=104');
	return false;
}

function addBv()
{
	if (!(typeof bv_gen != 'undefined' && bv_gen && typeof id_skynaute != 'undefined'
		&& document.getElementById('rencontre')
		&& document.getElementById('menu')))
	{
		return;
	}
	var div   = document.createElement('div');
	var a   = document.createElement('a');
	var img = document.createElement('img');
	div.id = 'boitevocal';
	a.href  = 'http://www.skyblog.com/bv/?id_skynaute=' + escape(id_skynaute);
	img.src = 'http://www.skyblog.com/pics/ecoute.gif';
	img.alt = 'Boite Vocale';
	a.onclick = openVocalWindow;
	div.appendChild(a);
	a.appendChild(img);
	div.style.marginTop = '0.5em';
	div.style.marginBottom = '0.5em';
	document.getElementById('menu').insertBefore(div, document.getElementById('rencontre'));
}

function sb_change_page()
{
	document.location = ((this.value == 1) ? 'index.html' : this.value + '.html');
}

function right(e)
{
	var msg = 'Le clic droit sur les images est désactivé.';
	if ((navigator.appName == 'Microsoft Internet Explorer' && event.button == 2))
	{
		alert(msg);
		return false;
	}
	return true;
}

function trap()
{
	if (document.images)
	{
		for (var i = 0; i < document.images.length; i++)
		{
			document.images[i].onmousedown = right;
		}
	}
}

