///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// vignette.js
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
function oVignette(arr)
{

	this.idvign = arr[0];
// load indique si on a demandé le chargement de l'image
// loaded indique si l'image a été effectivement chargée...
	this.load = false;
	this.loaded = false;
	this.drawed = false;
	this.url = arr[1];
	this.name = arr[2];
	this.auteur = arr[3];
	this.note = arr[4];
	this.type = arr[5];

	this.maxlen = (typeof(arr[6]) == 'undefined')? 0 : parseInt(arr[6], 10);
	if (this.maxlen == 0) this.maxlen = 750;
	this.edstart = (typeof(arr[7]) == 'undefined')? 0 : parseInt(arr[7], 10);
	this.edlen = (typeof(arr[8]) == 'undefined')? 150 : parseInt(arr[8], 10);
	if (this.edlen > this.maxlen) this.edlen = this.maxlen;
	this.edend = this.edstart + this.edlen;
	this.edoffset = (typeof(arr[9]) == 'undefined')? 0 : parseInt(arr[9], 10);
	this.effect = (typeof(arr[10]) == 'undefined')? 1 : parseInt(arr[10], 10);
	if (this.effect == 0) this.effect = 1;

	this.image = null;
	this.fixed = true;
	this.md5 = '';
}

function GVG_Load(id)
{
	if (!this.load)
	{
		this.image = new Image();
		this.image.id = id;
		this.load = true;

		var im = getObj('imgb' + id);
		if (im)
			im.src = window.rsc_localpath + partnerName + '/loading.gif';

		this.image.src = this.url;
	}
}
oVignette.prototype.Load = GVG_Load;

function GVG_Display(id, dtype)
{
	
	var ident, iname, inote, html;
	var addBgColor = '';
	if (!this.drawed)
	{
		this.drawed = true;
		if (this.loaded)
			img = this.url;
		else if (this.load)
			img = window.rsc_localpath + partnerName + '/loading.gif';
		else
			img = window.rsc_localpath + partnerName + '/server.gif';
		ident = this.idvign;
		iname = this.name;
		inote = this.note;
		iauteur = this.auteur;
		itype = this.type;
		if (itype == 'A')
			var canal = 1;
		else
			var canal = 0;
		if (dtype == null)
		  alert(dtype);
		switch(dtype)
		{
		case 0:
    		html = "<img class='vign' id='imgb" + id + "' src='"+ img + "' style='background-image:url(" + window.rsc_localpath + partnerName + "/server.gif);' onmousedown='vign_begindragCnl" + canal + "(this, event);'><br/><b><a href='/media/view/" + ident + "'>" + iname + "</a></b><br/><img src='" + window.rsc_localpath + partnerName + '/rating' + inote + ".png'><br/>" + tBy + ' ' + "<a href='/user/" + iauteur + "'>" + iauteur + "</a>";
    	    break;
		case 1:
    		html = "<img class='vign' id='imgb" + id + "' src='"+ img + "' style='background-image:url(" + window.rsc_localpath + partnerName + "/server.gif);' onmousedown='vign_begindragCnl" + canal + "(this, event);'>";
    	    break;
		case 2:
    		html = "<img class='vign2' id='imgb" + id + "' src='"+ img + "' style='background-image:url(" + window.rsc_localpath + partnerName + "/server.gif);' onmousedown='vign_begindragCnl" + canal + "(this, event);'><div class='vign2b'><b><a href='/media/view/" + ident + "'>" + iname + "</a></b><br/><img src='" + window.rsc_localpath + partnerName + '/rating' + inote + ".png'>" + tBy + ' ' + "<a href='/user/" + iauteur + "'>" + iauteur + "</a>" + "</div>";
    	    break;
		case 3:
    		html = "<div class='vign3'><img class='vign3' id='imgb" + id + "' src='"+ img + "' style='background-image:url(" + window.rsc_localpath + partnerName + "/server.gif); background-repeat:no-repeat; background-position:center;' onmousedown='vign_begindragCnl" + canal + "(this, event);'></div><div class='vign3b'><b><a href='/media/view/" + ident + "'>" + iname + "</a></b><br/>" + tBy + ' ' + "<a href='/user/" + iauteur + "'>" + iauteur + "</a>" + "</div>";
    	    break;
		case 4:
		    ajaxLink = "new Ajax.Request('/beta/partnerpage/set_current_show/"+ident+"?a=1', {asynchronous:true, evalScripts:true, onComplete:function(request){window.oVignBnk.HighlightMedia("+ident+");}}); return false;" 
    		html = "<div class='vign3'><img class='vign3' id='imgb" + id + "' src='"+ img + "' style='background-image:url(" + window.rsc_localpath + partnerName + "/server.gif); background-repeat:no-repeat; background-position:center;' onclick=\""+ajaxLink+"\"></div><div class='vign3b'><b><a href='' onclick=\""+ajaxLink+"\">" + iname + "</a></b><br/>" + tBy + ' ' + "<a href='/user/" + iauteur + "'>" + iauteur + "</a>" + "</div>";
  	    break;
		}
		var oV = getObj('b' + id)
		if (oV)
			oV.innerHTML = html;
	}
}
oVignette.prototype.Display = GVG_Display;

function cloneObj(what) {
    for (i in what) {
        if (typeof what[i] == 'object') {
        }
        else
            this[i] = what[i];
    }
}
/*
function SetImage()
{
	var v = this.id;
	var im = getObj('imgb' + v);
	if (im)
	{
		im.src = window.oVignBnk.tVignette[v].url;
		window.oVignBnk.tVignette[v].loaded = true;
	}
}
*/
