//JS COMMUN//
function ScrollTo(id){
    jQuery('html,body').animate({scrollTop:jQuery(id).offset().top},'1000','swing');
}

function add_panier(_ref){
	Overlay.display_from_url('/popup/panier-add.html?ref='+ _ref);
	
	//on cache le bouton fermer de base//
	$('#popup #close').hide();
	ScrollTo('popup');
}

function add_pub_clic(id){
	$.ajax({
		type: "GET",
		url: '/home/',
		async: false,
		data: 'action=add_pub_clic&id='+id,
		success: function(msg){
		}
	});
}

//utf8 é//
$(function(){
	$(".input-search").autocomplete("/recherche/", {extraParams: {action: 'recherche'}, minChars:'3', selectFirst:'false', max:'5', scroll:'false', scrollHeight:'300'});
	// $('.ac_results').css("overflow","hidden");
	// $('.ac_results').jScrollPane({showArrows:true,scrollbarWidth:14,dragMaxHeight :25});
	$(".input-search").result(function(event, data, formatted) {
		if (data)
			//$(this).next().find("input").val(data[1]);
			$(this).next().val(data[1]);
			$(this).next().next().val(data[2]);
		
	});
	
	//important : déterminer le path sinon la détection auto du path va taper sur le rewrite => 404//
	Shadowbox.path = '/assets/js/shadowbox/';
	Shadowbox.init({
		 players:    ["iframe","img"]
		}
	);

	//Gestion habillage//
	if(_habillage!=''){
		//recup de la hauteur de la page pour assigner au div de pub//
		var hauteurPage=$('#page').height() + parseInt($('#page').css('marginTop'));
		
		if($('#habillage').length==0)$('body').prepend('<div id="habillage"></div>');
		$('#habillage').css({height:hauteurPage+'px', marginBottom:'-'+hauteurPage+'px',cursor:'pointer'})
		.click(function(){
			add_pub_clic(_habillage_id);
			document.location = _habillage_lien;
			//window.open(_habillage_lien);
		});
	}
	
	$('#page').css('cursor','auto');
	
	//LIKE BOX (intégration ajax pour éviter erreurs valid W3C//
	$('#communiquer').html('<fb:like-box href="http://www.facebook.com/Kana.Video" width="167" show_faces="true" border_color="" stream="false" header="true"></fb:like-box>');
});

//FACEBOOK SDK//
window.fbAsyncInit = function(){
	FB.init({status: true, cookie: true,
	xfbml: true});
};
(function() {
	var e = document.createElement('script'); e.async = true;
	e.src = document.location.protocol +
	'//connect.facebook.net/fr_FR/all.js';
	document.getElementById('fb-root').appendChild(e);
}());
