var a_class_display = new Array();
a_class_display[0] = 'display_block';
a_class_display[1] = 'display_none';

// array('url', 'file') : save img en cours d'affichage pour d'autres functions (ex. dl)
var select_activ = new Array();




function f_save_option_select(this_tag, tag) {

	if (!select_activ[tag])
		select_activ[tag] = new Array();

	select_activ[tag]['value'] = this_tag.options[this_tag.selectedIndex].value
		? this_tag.options[this_tag.selectedIndex].value
		: '';

}


function f_class_tag(tag, classname) {

	if (tag && document.getElementById(tag)) {
		
		if (classname == 'displaying')
			classname = a_class_display;

		if (typeof(classname) == "object") {
			document.getElementById(tag).className = document.getElementById(tag).className == classname[1]
				? classname[0]
				: classname[1];
		}
		else
			document.getElementById(tag).className = classname;
	
	}
	
	return false;

}











var a_fix_hidden = new Array();

jQuery.noConflict();
jQuery(function() {

	// target blank
	jQuery('a').click(function(){
		if (jQuery(this).hasClass('tgbk'))
			jQuery(this).attr("target", "_blank");
	});

	// popup
	jQuery('[rel^="ppb_rl"]').each(function(){
		if (jQuery(this).children('img').length && jQuery(this).children().length == 1) {
			jQuery(this).attr('href', jQuery(this).children().attr('src'));
			jQuery(this).attr('title', jQuery(this).children().attr('title'));
		}
	});

	jQuery('.ppb').bind('click', function(){
		return f_ppb(this, false, false, false, false, true);
	});

	if (jQuery('#ppb_ctn').html())
		f_ppb(false, jQuery('#ppb_ctn').html(), 'inline');


	jQuery('#ppb_div a.nv_close').live('click', function(){jQuery('#popup').css('display', 'none'); return false;});

	// credit
	jQuery('#ft_crea').removeClass('ft_hv');
	jQuery('#ft_crea .ft_ctt_a').click(function(){
		jQuery('#ft_crea div').css('display', 'block');
		return false;
	});

});


/* ----------------------------------------------- functions ----------------------------------- */


/* ------------ generique ------------ */

function f_ppb(obj, ctn, type, param, rel, bind) {
// colorbox
// BIND : true pr bind('click') > bizarerie (colorbox lancé avec open = false)

//	var overflow = jQuery('html').css('overflow');
//	jQuery('html').css('overflow', 'hidden');

	if (!type) {
		type = 'media';
		if (obj) {
			if (jQuery(obj).hasClass('ppb_in'))
				type = 'inline';
		}
	}

	if (type != 'inline')
		jQuery('#colorbox').removeClass('ppb_in');

	if (!param)
		var param = new Array();

	var maxWidth = '80%';
	var maxHeight = '80%';
	var opacity = 0.8;

	switch(type) {
		case 'inline' :	maxWidth = 700;
						maxHeight = '80%';
						opacity = 0.5;
						break;
		
		case 'media' :	break;
	}

/*	param['onClosed'] = function() {
		jQuery('html').css('overflow', overflow); jQuery('#ppb_inc').empty();
	};
*/

	param['transition'] = 'none';
	param['onCleanup'] = function(){jQuery.colorbox.remove(), jQuery.colorbox.init();};

	param['maxWidth'] = maxWidth;
	param['maxHeight'] = maxHeight;
	param['opacity'] = opacity;
	param['initialWidth'] = 50;
	param['initialHeight'] = 50;
	param['current'] = '{current} /{total}';
	
	onOpen = 'br_rad6' + (type == 'inline' ? ' ppb_in' : '');
	
	if (ctn) {
		param['html'] = ctn;
		
		if (type == 'inline')
			onOpen += ' ppb_notitle';
		else
			jQuery('#colorbox').removeClass('ppb_notitle');
		
		param['onOpen'] = function () {
			jQuery('#colorbox').addClass(onOpen);
			if (param['urlopened'] && !jQuery('#btn_urlopened').length)
				jQuery('<a href="'+param['urlopened']+'" id="btn_urlopened"></a>').appendTo('#cboxContent');
			return false;
		}
		
		jQuery.colorbox(param);
	}
	else {
		
		var obj_s = false;
		
		if (rel && !jQuery('[rel='+rel+']:first').length)
			rel = false;
		
		if (!rel)
			rel = jQuery(obj).attr('rel');

		jQuery(rel ? '[rel='+rel+']' : obj).each(function(){

			param['open'] = false;
			param['title'] = '';
			
			param['onClosed'] = rel
				? function(){jQuery('[rel='+rel+']').colorbox.remove();}
				: false;

			if (type == 'inline')
				onOpen += ' ppb_notitle';
			else {
				param['title'] = jQuery(this).attr('title');
				jQuery('#colorbox').removeClass('ppb_notitle');
			}
								
			param['onOpen'] = function () {
				jQuery('#colorbox').addClass(onOpen);
				if (param['urlopened'] && !jQuery('#btn_urlopened').length)
					jQuery('<a href="'+param['urlopened']+'" id="btn_urlopened"></a>').appendTo('#cboxContent');
				return false;
			}


			if (jQuery(this).attr('href') == jQuery(obj).attr('href') || jQuery(this).attr('href') == jQuery(obj).attr('src')) {
				if (rel)
					obj_s = this;
				else if (bind)
					param['open'] = true;
			}

			jQuery(this).colorbox(param);

		});

		if (rel)
			jQuery(obj_s ? obj_s : '[rel='+rel+']:first').colorbox({
				open:true,
			});

	}
	
	return false;

}

function f_ppb_close() {
	jQuery.colorbox.close();
	return false;
}


function f_display_multiple(tag_close, tag_open, type) {
// tag_close : tag || array(tags)

	if (!type)
		type = 'toggle';

	if (typeof tag_close != 'object')
		tag_close = new Array(tag_close);

	for (tag in tag_close) 
		if (jQuery(tag_close[tag]).css('display') != 'none')
			f_display(tag_close[tag], type);


	if (jQuery(tag_open).css('display') == 'none')
		f_display(tag_open, type);
	
	return false;

}


function f_display(obj, type, disp, fix_hidden, del, func) {

	if (!type)
		type = 'fade';

	if (typeof obj == 'string' && fix_hidden)
		a_fix_hidden[obj.substring(1)] = true;

	if (typeof disp == 'undefined')
		disp = null;

	if (jQuery(obj).css('display') != 'none') {
		if (disp === null || !disp) {
			jQuery(obj).css('display', 'none');
			if (del)
				jQuery(obj).remove();
			if (typeof func == 'function')
				func();
		}
	}
	else if (disp === null || disp) {
		jQuery(obj).css('display', 'block');
		if (typeof func == 'function')
			func();
	}

	return false;

}


function f_close_result_box(obj) {

	obj_div = jQuery(obj).parents('.result_div');
	obj = obj_div.length ? obj_div : jQuery(obj).parents('.result_box');
	return f_display(jQuery(obj), 'toggle', false, false, true);

}


function f_scroll_tag(obj, tag) {
	
}


function f_ajax(param, ajaxcmd, funct, ppb_param) {

	return true;

}


function f_chain_input(tag, chain) {

}



function f_check_valueform(tag, a_tags, only_check) {

	var pass = true;
	
	if (a_tags) {
		tag = '';
		for(k in a_tags)
			tag += ','+a_tags[k];
		tag = tag.substring(1);
	}

	jQuery(tag).each(function() {

		if (!jQuery(this).val() || (jQuery(this).get(0).tagName == 'textarea' && !jQuery(this).html())) {
			pass = false;
			if (!only_check) {
				jQuery(this).addClass('fld_ntf');
				jQuery(this).focus();
			}
		}
		else if (!only_check)
			jQuery(this).removeClass('fld_ntf');

	});
	
	return pass;

}


function f_repository(url) {

	var r = '';

	var c = url.split("/").length - 1;
	for(i = 0; i < c; i++)
		r += '../';
	
	return r;

}
