/******************************************************************/
//detect ie6
var IE6 = false 

var strChUserAgent = navigator.userAgent; 
var intSplitStart = strChUserAgent.indexOf("(",0); 
var intSplitEnd = strChUserAgent.indexOf(")",0); 
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd); 

if(strChMid.indexOf("MSIE 6") != -1) IE6 = true;
else if(strChMid.indexOf("MSIE 5") != -1) IE6 = true;
/******************************************************************/
function AddToCartAlert(){
	//window.alert("test");
	document.getElementById('add-to-cart-alert').style.display= "block";
	document.getElementById('add-to-cart-alert2').style.display= "block";
	setTimeout( 'AddToCartAlertClose()', 2000 );
}
function AddToCartAlertClose(){
	document.getElementById('add-to-cart-alert').style.display= "none";
	document.getElementById('add-to-cart-alert2').style.display= "none";
}
/******************************************************************/
/*DEBUT SLIMBOX*/
var Slimbox;(function(){var C=window,K=0,r,g,D,t,B,s,v,J,p,k=o.bindWithEvent(),n,q=new Image(),H=new Image(),F,a,h,G,e,E,c,x,I,u,i,d,z;C.addEvent("domready",function(){$(document.body).adopt($$(F=new Element("div",{id:"lbOverlay"}),a=new Element("div",{id:"lbCenter"}),E=new Element("div",{id:"lbBottomContainer"})).setStyle("display","none"));h=new Element("div",{id:"lbImage"}).injectInside(a).adopt(G=new Element("a",{id:"lbPrevLink",href:"#"}),e=new Element("a",{id:"lbNextLink",href:"#"}));G.onclick=y;e.onclick=f;var L;c=new Element("div",{id:"lbBottom"}).injectInside(E).adopt(L=new Element("a",{id:"lbCloseLink",href:"#"}),x=new Element("div",{id:"lbCaption"}),I=new Element("div",{id:"lbNumber"}),new Element("div",{styles:{clear:"both"}}));L.onclick=F.onclick=A});Slimbox={open:function(N,M,L){r=$extend({loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]},L||{});u=F.effect("opacity",{duration:r.overlayFadeDuration});i=a.effects($extend({duration:r.resizeDuration},r.resizeTransition?{transition:r.resizeTransition}:{}));d=h.effect("opacity",{duration:r.imageFadeDuration,onComplete:j});z=c.effect("margin-top",{duration:r.captionAnimationDuration});if(typeof N=="string"){N=[[N,M]];M=0}v=C.getScrollTop()+(C.getHeight()/2);J=r.initialWidth;p=r.initialHeight;a.setStyles({top:Math.max(0,v-(p/2)),width:J,height:p,marginLeft:-J/2,display:""});s=C.ie6||(F.currentStyle&&(F.currentStyle.position!="fixed"));if(s){F.style.position="absolute"}u.set(0).start(r.overlayOpacity);w();m(true);K=1;g=N;r.loop=r.loop&&(g.length>1);return b(M)}};Element.extend({slimbox:function(L,M){$$(this).slimbox(L,M);return this}});Elements.extend({slimbox:function(L,O,N){O=O||function(P){return[P.href,P.title]};N=N||function(){return true};var M=this;M.forEach(function(P){P.removeEvents("click").addEvent("click",function(Q){var R=M.filter(N,this);Slimbox.open(R.map(O),R.indexOf(this),L);Q.stop()}.bindWithEvent(P))});return M}});function w(){var M=C.getScrollLeft(),L=C.getWidth();$$(a,E).setStyle("left",M+(L/2));if(s){F.setStyles({left:M,top:C.getScrollTop(),width:L,height:C.getHeight()})}}function m(L){["object",C.ie?"select":"embed"].forEach(function(N){$each(document.getElementsByTagName(N),function(O){if(L){O._slimbox=O.style.visibility}O.style.visibility=L?"hidden":O._slimbox})});F.style.display=L?"":"none";var M=L?"addEvent":"removeEvent";C[M]("scroll",w)[M]("resize",w);document[M]("keydown",k)}function o(M){var L=M.code;if(r.closeKeys.contains(L)){A()}else{if(r.nextKeys.contains(L)){f()}else{if(r.previousKeys.contains(L)){y()}}}M.stop()}function y(){return b(t)}function f(){return b(B)}function b(L){if((K==1)&&(L>=0)){K=2;D=L;t=(D||(r.loop?g.length:0))-1;B=((D+1)%g.length)||(r.loop?0:-1);z.stop();$$(G,e,h,E).setStyle("display","none");a.className="lbLoading";n=new Image();n.onload=l;n.src=g[L][0]}return false}function l(){a.className="";d.set(0);h.setStyles({width:n.width,backgroundImage:"url("+g[D][0]+")",display:""});$$(h,G,e).setStyle("height",n.height);x.setHTML(g[D][1]||"");I.setHTML((((g.length>1)&&r.counterText)||"").replace(/{x}/,D+1).replace(/{y}/,g.length));if(t>=0){q.src=g[t][0]}if(B>=0){H.src=g[B][0]}J=h.offsetWidth;p=h.offsetHeight;var L=Math.max(0,v-(p/2));if(a.clientHeight!=p){i.chain(i.start.pass({height:p,top:L},i))}if(a.clientWidth!=J){i.chain(i.start.pass({width:J,marginLeft:-J/2},i))}i.chain(function(){E.setStyles({width:J,top:L+p,marginLeft:-J/2,visibility:"hidden",display:""});d.start(1)});i.callChain()}function j(){if(t>=0){G.style.display=""}if(B>=0){e.style.display=""}z.set(-c.offsetHeight).start(0);E.style.visibility="";K=1}function A(){if(K){K=0;n.onload=Class.empty;i.clearChain();[u,i,d,z].forEach(function(L){L.stop()});$$(a,E).setStyle("display","none");u.chain(m).start(0)}return false}})();
Slimbox.scanPage = function() {
	$$($$(document.links).filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	})).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
};
window.addEvent("domready", Slimbox.scanPage);
/******************************************************************/
/*CART*/
var cart_title = "Cart";
var ok_lbl="Continue";
var cancel_lbl="Cancel";
var notice_lbl="Notice";
/******************************************************************/
/*DEBUT MOOTOOLS*/
window.addEvent("domready", function( ){ 
	//abbr générique  
	//var abbrTools = new Tips( $$("a") );
	//Cart bulle dragable
	if (!IE6){
		var cartBox = $('cart');
		cartBox.makeDraggable({onDrag: function() {
			document.cookie = "cartX=" + escape(this.element.getStyle('left').toInt())+"; path=/;"; 
			document.cookie = "cartY=" + escape(this.element.getStyle('top').toInt())+"; path=/;";
		}});
		if (LireCookie("cartX")==null){
			document.cookie = "cartX= '-5'; path=/;"; 
			document.cookie = "cartY= '-5'; path=/;";	
		}
		if (escape(LireCookie("cartX").toInt())>0) {
			document.getElementById('cart').style.left = escape(LireCookie("cartX").toInt())+"px";
			document.getElementById('cart').style.top = escape(LireCookie("cartY").toInt())+"px";		
		}
		else {
			document.getElementById('cart').style.left = "-5px";
			document.getElementById('cart').style.top = "-5px";	
		}
	}
	//CartDetail
	if ($('cartTotal')){
	var slideCartDetail = new Fx.Slide('cartDetail', {wait:false});
	slideCartDetail.hide();
	$('cartTotal').addEvent('mouseenter', function(e){
		eCart = new Event(e);
		slideCartDetail.slideIn();
		eCart.stop();
	});
	$('cartTotal').addEvent('mouseleave', function(e){
		eCart = new Event(e);
		slideCartDetail.slideOut();
		eCart.stop();
	});
	}
	//login

	var slideLogin = new Fx.Styles('loginOption', {duration:250, wait:false});
	$('loginMain').addEvent('mouseenter', function(e){
		slideLogin.start({'margin-top': 0});
	});
	$('loginMain').addEvent('mouseleave', function(e){
		slideLogin.start({'margin-top': -70});
	});	

	//Menu sublevel
	var list = $$('#mainlevel li');
	list.each(function(el) {
		//el.setAttribute( 'id',i );
		el.getChildren().each( function(e) {
			if ( e.className == 'ul-sublevel') {
				var fx = new Fx.Styles(e, {duration:600, wait:false});
				el.addEvent('mouseenter', function(){
					fx.start({'margin-top': -50});
				});
				el.addEvent('mouseleave', function(){
					fx.start({'margin-top': -450});
				});
			}
		});
	});		
	//Gateau maison
	function getCookieVal(offset){ var endstr=document.cookie.indexOf (";", offset); if (endstr==-1) endstr=document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); }
	function LireCookie(nom){ var arg=nom+"="; var alen=arg.length; var clen=document.cookie.length; var i=0; while (i<clen){var j=i+alen; if (document.cookie.substring(i, j)==arg) return getCookieVal(j); i=document.cookie.indexOf(" ",i)+1; if (i==0) break;} return null; }
});
/*FIN MOOTOOLS*/
function flash(tag) {
	document.write(tag);
} 

/*****************************************************************************************************/
/*THEME.JS*/
function loadNewPage( el, url ) {
	var theEl = $(el);
	var callback = {
		success : function(responseText) {
			theEl.innerHTML = responseText;
			if( Lightbox ) Lightbox.init();
		}
	}
	var opt = { method: 'get', onComplete: callback.success }
	new Ajax( url + '&only_page=1', opt ).request();

}
function handleGoToCart() { document.location = live_site + '/index.php?option=com_virtuemart&page=shop.cart&product_id=' + formCartAdd.product_id.value ; }
function handleAddToCart( formId, parameters ) {
	formCartAdd = document.getElementById( formId );
	var callback = function(responseText) {	
		updateMiniCarts();
		AddToCartAlert();
		document.boxB = new MooPrompt(notice_lbl, responseText, { buttons: 2, width:400, height:150, overlay: false, button1: ok_lbl, button2: cart_title, onButton2: handleGoToCart });	
		setTimeout( 'document.boxB.close()', 3000 );
	}
	var opt = { method: 'post', data: $(formId), onComplete: callback, evalScripts: true }
	new Ajax(formCartAdd.action, opt).request();
}
/*This function searches for all elements with the class name "vmCartModule" and updates them with the contents of the page "shop.basket_short" after a cart modification event*/
function updateMiniCarts() {
	var callbackCart = function(responseText) {
		carts = $$( '.vmCartModule' );
		if( carts ) { try { for (var i=0; i<carts.length; i++) carts[i].innerHTML = responseText; } catch(e) {} }
	}
	var option = { method: 'post', onComplete: callbackCart, data: { only_page:1,page: "shop.basket_short", option: "com_virtuemart" } }
	new Ajax( live_site + '/index2.php', option).request();
} 
/** This function allows you to present contents of a URL in a really nice stylish dhtml Window* It uses the WindowJS, so make sure you have called*/
function fancyPop( url, parameters ) {
	parameters = parameters || {};
	popTitle = parameters.title || '';
	popWidth = parameters.width || 700;
	popHeight = parameters.height || 600;
	popModal = parameters.modal || false;
	window_id = new Window('window_id', {className: "mac_os_x", title: popTitle, showEffect: Element.show, hideEffect: Element.hide, width: popWidth, height: popHeight}); 
	window_id.setAjaxContent( url, {evalScripts:true}, true, popModal );
	window_id.setCookie('window_size');
	window_id.setDestroyOnClose();
}