// preload certain images

var path = "../images/";
var prefix = "tacca-bt-";
var ext = ".gif";
	
var preload = new Array(
	"fleche",
	"soumettre",
	"details-plus",
	"details-moins",
	"siteofficiel",
	"myspace",
	"acheter",
	"billets",
	"play",
	"stop",
	"pause",
	"rew",
	"ff",
	"boutique",
	"licence"
);

// lists associated buttons expand and collapse;
var toggleButtons = new Array();
toggleButtons["details-plus"] = "details-moins";
toggleButtons["details-moins"] = "details-plus";

var preloadarray = new Array();
var length = preload.length;
for (var i=0; i<length; i++) {
	var id = preload[i];
	preloadarray[id] = new Array();
	preloadarray[id]["on"] = new Image();
	preloadarray[id]["on"].src = path + prefix + id + "-" + "on" + ext;
	preloadarray[id]["off"] = new Image();
	preloadarray[id]["off"].src = path + prefix + id + "-" + "off" + ext;
}

function returnGetAttribute(o,a)
{
	if (o.hasAttribute && o.hasAttribute(a)) {
		return o.getAttribute(a);
	} else {
		//hasAttribute not supported (IE)
		//incorrect management of class attributeName
		if(a == 'class') a = 'className';
		if (o.getAttribute(a, 2)) {
			return o.getAttribute(a, 2);
		} else {
			return false;
		}
	}
}

function img(o, state)
{
	//obj is either <a> or <input type="image"> element, change src of appropriate object
	// in both case, obj must have class attribute corresponding to a value in preloadarray
	//id = obj.getAttributeNode("class").value;

	var id = returnGetAttribute(o, 'class');

	if (id) {
		//if object has src attribute
		if (returnGetAttribute(o, 'src')) {
			imgObj = o;
		} else {
			//check if child has src attribute
			if (returnGetAttribute(o.childNodes[0], 'src')) {
				imgObj = o.childNodes[0];
			} else {
				return false;
			}
		}
		imgObj.src = preloadarray[id][state].src;
		return true;
	} else {
		return false;
	}
}

// expand or retract news block
function toggleNews(o, id)
{
	// o = anchor object
	// id = news div id 
	
	// id div is visible, hide, vice versa
	style = document.getElementById(id).style;
	if(style.display == 'none'){
		style.display = 'block';
	} else {
		if(style.display == '') {
			style.display = 'block';
		} else {			
			style.display = 'none';
		}
	}
	toggleNewsButton(o);
}

// now, take care of image button
// change plus sign for minus sign
// change src of image
function toggleNewsButton(o)
{

	var id = returnGetAttribute(o, 'class');
	if (id) {
		//change object's classname
		if(toggleButtons[id]) {
		
			// there is an association
			o.className = toggleButtons[id];
			// change child img src
			if (returnGetAttribute(o.childNodes[0], 'src')) {
				imgObj = o.childNodes[0];
			} else {
				return false;
			}
				
			//ie6 handles badly the javascript void function, image src does not render properly
			//use setTimeout instead
			if(!isIe6()) {
				imgObj.src = preloadarray[toggleButtons[id]]['on'].src;
			} else {
				setTimeout("toggleIe6Img(o, imgObj, '"+preloadarray[toggleButtons[id]]['on'].src+"')", 5);
			}
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function isIe6()
{
    var agt = navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	return is_ie6;
}

function toggleIe6Img(o, i, src)
{
	// ajouter detection si mouseover encore actif
	// petit glitch a corriger MAUDIT IE 6
	i.src = src;
	return true;
}

function checkall(strForm,strName,boolChecked) {
	for (var i = 0; i < strForm.elements.length; i++) {
		while (strForm.elements[i].name != strName+"[]") {
			i++;
			if (!strForm.elements[i]) {
				return;
			}
		}
		strForm.elements[i].checked = boolChecked;
	}
}

function sample(id) {
	document.getElementById("play").className = '';
	document.getElementById("equalizer").className = '';
	document.frm_radio.boolPlaying.value=0;
	var winl = (screen.width - 408) / 2;
	var wint = (screen.height - 207) / 2;
	wndwPopup = window.open('http://www.boutiquetacca.com/mp3/player.php?player=2&id='+id, 'taccaradio','width=408,height=207,top='+wint+',left='+winl+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no');
	wndwPopup.focus();
}

function radio(strAction,boolWindow) {
	intTrack = document.frm_radio.intTrack.value;
	strQuery = 'strAction=radio_'+strAction+'&intTrack='+intTrack;
	if (boolWindow) {
		radio_refresh(strQuery+'&boolAjax=1');
	} else {
		var winl = screen.width - 676;
		var wint = screen.height - 160;
		wndwPopup = window.open('../radio/?'+strQuery, 'taccaradio','width=626,height=110,top='+wint+',left='+winl+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no');
		wndwPopup.focus();
		var timer = setTimeout("window.focus()",1000)
	}
}

function videoplayer(id) {
	var winl = (screen.width - 783) / 2;
	var wint = (screen.height - 440) / 2;
	wndwPopup = window.open('../videos/?id='+id, 'taccavideo','width=783,height=440,top='+wint+',left='+winl+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no');
	wndwPopup.focus();
}


