

(function($) {
	$.fn.extend({
		hke_nav:function(o){
			return this.each(function(index,dom){				
				var $this = $(this);
				$this.find('li ol').each(function(){
					$(this).css({ width:$(this).parent().width()+'px' });
				});
				$this.find('img')
					.pi_roll()
					.each(function(){
						if ($(this).attr('src').indexOf('-1.gif')!=-1) {
							$(this).trigger('pi_roll_lock',[true]);
						}
				});
				$this.find('>li').mouseover(function(){
					$(this).find('ol').css({ 'display':'block' });
				}).mouseout(function(){
					$(this).find('ol').css({ 'display':'none' });
				});
			});
		}
	});
})(jQuery);

(function($) {
	$.extend({
		hke_tools:{
			xiti: function (part,spart) {
				console.log(part+' // '+spart);
				//$.hke_tools.xiti(part,spart);
			}
		}
	});
})(jQuery);

(function($) {
	$.fn.extend({
		hke_select:function(o){
			return this.each(function(index,dom){
				var $btn = $(this).find('ul');
				$btn.mouseover(function(){
					$btn.css({ 'clip':'rect(auto,auto,auto,auto)', 'height':'auto' });
				}).mouseout(function(){
					$btn.css({ 'clip':'rect(0,69px,16px,0)', 'height':'16px' });
				});
			});
		}
	});
})(jQuery);

(function($) {
	$.fn.extend({
		hke_medias:function(o){
			return this.each(function(index,dom){
				
			});
		}
	});
})(jQuery);

function selectDirectAccess(listId) {
	var url = $('#' + listId).val();
	if(url != '0') window.open(url);
}

function showMediatheque(folderId, returnUrl) {
	$.ajax({
		type: "POST",
		url: hke.url_site + "/Site/Includes/Ajax/Ajax.aspx",
		data: "task=ISLOGED&returnUrl=" + returnUrl,
		success: function (response) {
			var requestStatus = eval(response)[0];
			if (requestStatus.status) {
			    if (requestStatus.isLoged) {
			        $('body').pi_popin({ name: 'mediathequeDetail', url: hke.url_site + "/Site/Includes/Ajax/AjaxMediatheque.aspx", type: "POST", datas: {folderId:folderId} });

					/*$.ajax({
						type: "POST",
						url: hke.url_site + "/Site/Includes/Ajax/AjaxMediatheque.aspx",
						data: "folderId=" + folderId,
						success: function (response) {
							alert(response);
						}
					});*/
				} else {
					document.location.href = requestStatus.url;
				}
			} else {
                //alert(requestStatus.msg);

                
			}
		}
	});
}

function choiceLayerAge(value) {
	if (value == 'OUI') {
		$.ajax({
			type: "POST",
			url: hke.url_site + "/Site/Includes/Ajax/Ajax.aspx",
			data: "task=SETCOOKIE&val=1",
			success: function (response) {
				$('#layerMajeur').hide();
			}
		});
	}
	else if (value == 'NON') {
		$('#layerMajeurError').html('Vous devez &ecirc;tre majeur pour visiter le site.');
	}
}

function popThis(url, nom, isCenter, w, h, o) {
	if (isCenter) {
		var popHPos = (screen.availWidth / 2) - (w / 2);
		var popVPos = (screen.availHeight / 2) - (h / 2);
		pop = window.open(url, nom, 'width=' + w + ',height=' + h + ',top=' + popVPos + ',left=' + popHPos + ',' + o);
	} else {
		pop = window.open(url, nom, 'width=' + w + ',height=' + h + ',' + o);
	}
	pop.focus();
}

function forgetPassword() {
	$.ajax({
		type: "POST",
		url: hke.url_site + "/Site/Includes/Ajax/Ajax.aspx",
		data: "task=FORGETPASSWORD&email=" + $('#txtForgetPasswordEmail').val(),
		success: function (response) {
			var requestStatus = eval(response)[0];
			$('#forgetPasswordMessageError').html(requestStatus.msg);
		}
	});
}

var switchImgMediathequeId = null;
var switchImgMediathequeUrl = null;
function switchImgMediatheque(obj,id,url) {
	switchImgMediathequeId = id;
	switchImgMediathequeUrl = url;
	$('#lastFoldersI a')[0].onclick = null;
	$('#lastFoldersI a')[0].onclick = function(){
		showMediatheque(switchImgMediathequeId,switchImgMediathequeUrl);
	}
	$('#lastFolders span').html($(obj).find('img').attr('alt'));
    $('#lastFoldersI img').attr('src', $(obj).find('img').attr('src'));
}

function switchMediatheque(obj) {
    $('#mediathequeDetailVisu').attr('src', $(obj).attr('rel').substring(0, $(obj).attr('rel').indexOf('|')));	
	var rel = $(obj).attr('rel');
	$('#mediathequeDetailDL').attr('href', rel.substring(rel.indexOf('|')+1,rel.length) );
    $('#mediathequeDetailText').html($(obj).find('span').html());
}

function getParamValue(param, url) {
	var u = url == undefined ? document.location.href : url;
	var reg = new RegExp('(\\?|&|^)' + param + '=(.*?)(&|$)');
	matches = u.match(reg);
	if (matches != null) return matches[2] != undefined ? decodeURIComponent(matches[2]).replace(/\+/g, ' ') : '';
	else return '';
}

var pathFile = $('#path').clone();
function showPath(value) {
    if ($(pathFile).find(':last').is('a')) $(pathFile).find('a:last').replaceWith('<span>' + $(pathFile).find(':last').html() + '</span>');

    if (value != '') $(pathFile).find('span:last').replaceWith('<a href="' + document.location.href + '">' + $(pathFile).find('span:last').html() + '</a>');
    $('#path').html(pathFile.html()+"<span>"+value+"</span>");
}

function openMetier(id){
	if (id&&id!='') {
		$('#flMetier iframe')[0].src = $('#flMetier iframe')[0].src + '?idWorks=' + id;
	}
	$('body').pi_layin({ name: 'popMetier' });
}

(function($) {
	$.fn.extend({
		pi_layin:function(o){
			var  _settings = {
				alpha:50, background:'#000000', datas:{}
			};			
			if(o) $.extend(_settings,o);
			
			return this.each(function(index,dom){
				
				var $this = this, _popin = null,
					root = $(this).append('<div id="pi_popin'+o.name+'" style="position:absolute;top:-5000px;left:0;"></div>'),
					_index = root.children().next().length-1,
					content = $(root).find('#pi_popin'+o.name);
				
				$(this).bind('pi_popin_refresh',function(e){
					_setPos();
				});
				
				function _getPos (k) {
					return $(window)[k.scrollpos]()+($('html')[0][k.clientsize]/2)-($($(content).children()[1])[k.size]()/2);
				}
				
				function _setPos () {
					$.pi_axis.each(function(k){
						if (_popin[k.size]()>$(window)[k.size]()) return;
                       _popin[0].style[k.pos] = _getPos(k)+'px';
					});
				}
				
				function _setBg () {
					$.pi_axis.each(function(k){
						$(content).children()[0].style[k.size] = $('html')[0][k.scrollsize]<$(window)[k.size]() ?$(window)[k.size]()+'px' :$('html')[0][k.scrollsize]+'px';
					});
				}
				
				function close() {
                    $("body").append(_popin);
                    _popin.css({ visibility:'hidden',display:'none',left:0,top:0 });
					$(content).remove();
                    $(window).unbind('resize');
                    $(window).unbind('scroll');
                    $(window).unbind('keydown');
                    _popin.unbind('pi_popin_close');
				    _popin.unbind('pi_popin_refresh');	
				}
				
				function _onKeydown (e) {
					if (e.which==27) close();
				}

                $(content).html('<div style="z-index:'+(999+_index)+';position:absolute;top:0;left:0;background:'+_settings.background+';filter:alpha(opacity='+_settings.alpha+');-moz-opacity:0.'+_settings.alpha+';opacity:0.'+_settings.alpha+';"></div>');
				_popin = $('#'+o.name);

                $(content).append(_popin);

				_popin.css({ position:'absolute',visibility:'visible',display:'block', zIndex:1000+_index });
				$(content).css({ top:0, zIndex:1001+_index });
				_setBg();
				_setPos();
				_popin.bind('pi_popin_close',function(e){ close(); });
				_popin.bind('pi_popin_refresh',function(e){ _setPos(); });					
				$(window).resize(_setPos);
				$(window).scroll(_setPos);
				$(document).keydown(_onKeydown);
				
			});
		}
	});
})(jQuery);

var hke_print_link_pdf = null;
$(document).ready(function () {
	$('#nav').hke_nav();
	
	if ($('.exportContact').length>0||$('.contactPro').length>0||$('.offreBierePro').length>0) {
		$('#direct .selectSkin').pi_select();
		$('#content .selectSkin').pi_select({ cursorSizeY:35 });
	}
	else {
		$('.selectSkin').pi_select();
	}
	
	$('#s2340 img').pi_ie6().trigger('pi_ie6_pngfix');
	$('.simpleSelect').hke_select();
	$(':checkbox').pi_checkbox({ img: hke.url_site + '/Site/Includes/Images/checkbox-0.gif' });
	$('#content .scrollerSkin').pi_scroll({ name: 'scrollFolder', toolsY: true, toolsBtnsY: false, toolsBgY: true, setRealWidth: false });

	if (hke.majeur == 'OUI') $('#layerMajeur').hide();
	else {
		$('#layerMajeur').show();
		$('.prehome .marquee').pi_marquee({ speed:1, speedInterval:20 });
	}
	
	$('#tools').addClass($('#nav img')[1].src.indexOf('-1.gif')!=-1||$('#nav img')[2].src.indexOf('-1.gif')!=-1?'disablePrint':'enablePrint');
	
	if ($('#content #fl').length>0) {
		
		var interval = setInterval(function(){
			var fl = $('#fl')[0];
			if (fl.tagName.toLowerCase()=='object') {				
				
				var swf = '';
				if (fl.data=='') {
					var findFl = $('#fl')[0].innerHTML.toLowerCase();
					var findFlI = findFl.indexOf('<param name="src" value="');
					var findFlI_2 = findFl.indexOf('<param name="src" ');
					var findFlLast = findFl.substring(findFlI+25,findFl.length);
					swf = findFlLast.split('\"')[0];
					swf = swf.split('/');
				}
				else {
					swf = fl.data.split('/');
				}				
				
				var pdf = swf[swf.length-1];
				hke_print_link_pdf = pdf.substring(0,pdf.length-4);
				clearInterval(interval);
			}
		},1000);
		
		$('#tools #print').click(function(){
			if (hke_print_link_pdf)	window.open(hke.url_site+'/Site/Includes/Pdf/'+hke_print_link_pdf+'.pdf','PDF');
		});
	}
	else {
		$('#tools #print').click(function(){ print(); });
	}
	
	$('#search :button').click(function(){
		if ($('#searchI').val()=='') {
			if ($('#search div').length==0) {
				$('#search').append('<div>Veuillez saisir un texte puis cliquer sur le bouton de validation</div>');
			}
		}
		else {
			document.location = hke.url_search+'?search='+$('#searchI').val();
		}
	});
	
});

