// JavaScript Document //
//var level = 0;

/*function _createMenu (menuName) {
	var src ='';
	src += '<ul>';
	for (var i=0; i<menuName.length; i++) {
		src += '<li><a href="' + menuName[i][1] + '">' + menuName[i][0] + '</a>';
		//alert( i + '-' + level + '-' + menuName[i][0] );
		if (menuName[i][2].length > 0) {
			level += 1;
			src += createMenu (menuName[i][2]);
		}
		src += '</li>\n';
	}
	src += '</ul>';
	level -= 1;
	//alert (src);
	return (src);
}*/

function createMenu (menuName) {
	src = '<ul>' + createMenuItem (menuName, -1, 0, 0) + '</ul>' ;
	return (src) ;
}

function createMenuItem (menuName, parentIndex, itemIndex, level) {
	src = '' ;
	selected = '';
	if (menuName[itemIndex][3].length > 0) {
		src = '<ul>' + createMenuItem (menuName[itemIndex][3], itemIndex, 0, level + 1) + '</ul>';
	}
	
	if (parentIndex == -1) {
		if ( menuactive[level] == itemIndex ) {
			selected = ' class="select"' ;
		}
	} else {
		if ((menuactive[level] == itemIndex) && (menuactive[level - 1] == parentIndex)) {
			selected = ' class="select"' ;
		}
	}
	
	if ( itemIndex == menuName.length - 1 ) {
		src = '<li><a href="' + menuName[itemIndex][1] + '"' + selected + ' target="'+ menuName[itemIndex][2] +'">' + menuName[itemIndex][0] + '</a>\n' + src + '</li>\n' ;
	}else{
		src = '<li><a href="' + menuName[itemIndex][1] + '"' + selected + ' target="'+ menuName[itemIndex][2] +'">' + menuName[itemIndex][0] + '</a>\n' + src + '</li>\n' + createMenuItem (menuName, parentIndex, itemIndex + 1, level) ;
	}
	//alert (level + '\n-' + src) ;
	return (src) ;
}



var popUpWin=0;

function popUpWindow(URLStr, width, height)

{

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }
	
	_top = (screen.height - height)/2;
	left = (screen.width - width)/2;

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+_top+',screenX='+left+',screenY='+_top+'');

}

function swf(id,filename, width, height, flashvars, params, attributes)
{
	var arrayFlvars = new Array();
	for(var i in flashvars){ arrayFlvars.push(i+'='+flashvars[i]); }
	flashvars = arrayFlvars.join('&');
	
	var arrayAttrs = new Array();
	for(var i in attributes){ arrayAttrs.push(i + '="' + attributes[i] + '"'); }
	attributes = arrayAttrs.join(' ');
	
	var html = '<object id="'+id+'" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash" data="'+filename+'"><param name="movie" value="'+filename+'?'+flashvars+'"></param>';
	var arrayParams = new Array();
	for(var i in params){
		html += '<param name="'+i+'" value="' + params[i] + '" />';
		arrayParams.push(i+'="'+params[i]+'"');
	}
	html += '<param name="flashvars" value="' + flashvars + '" />';
	params = arrayParams.join(' ');
	html += '</object>';
	return html;
}

function pubSwitch(ni)
{
	if (pub_over == 0 || ni > 0)
	{
		var m_active = $('#anim-min-'+pub_imgs[pub_i]);
		var i_active = $('#anim-img-'+pub_imgs[pub_i]);
		if (ni > 0) { pub_i = ni-1; }
		else { if (pub_i == pub_imgs.length-1) pub_i = 0; else pub_i += 1; }
		var m_next = $('#anim-min-'+pub_imgs[pub_i]);
		var i_next = $('#anim-img-'+pub_imgs[pub_i]);

		m_active.removeClass('actif');
		m_next.addClass('actif');
		i_next.css({opacity: 0.0});
		i_active.addClass('last-actif');
		i_active.removeClass('actif');
		i_next.addClass('actif');
		i_next.animate({opacity: 1.0}, 1500, function() {
			i_active.removeClass('last-actif');
		});
	}
}


$(document).ready( function () 
{

	$(function() { setInterval( "pubSwitch()", 5000 ); });

	$('.minit').mouseover(function() { pub_over = 1; pubSwitch(parseInt($(this).attr('idx'))+1); }); 
	$('.minit').mouseout(function() { pub_over = 0; });

	$('#anim-image').mouseover(function() { pub_over = 1; }); 
	$('#anim-image').mouseout(function() { pub_over = 0; });

});


