/**
 * 
 * SEARCHZONE
 * $.la.dekio.deco.searchzone.init()
 * $.la.dekio.deco.searchzone.setProfil(url)
 * $.la.dekio.deco.searchzone.submit(sSearch)
 * 
 * ADDRESS 
 * $.la.dekio.deco.address.setBreadcrumbFromCookie()
 * $.la.dekio.deco.address.createInfoWindowHtml()
 * 
 * 
 * BOOKMARKS
 *** PRODUCT
 * $.la.dekio.deco.bookmarks.product.add(url, sSelector)
 * $.la.dekio.deco.bookmarks.product.addWithoutModal(url, sSelector)
 * $.la.dekio.deco.bookmarks.product.setDocumentClass(iOffset)
 * $.la.dekio.deco.bookmarks.product.submitFilter()
 * $.la.dekio.deco.bookmarks.product.deleteFromList(url, redirectURL)
 * $.la.dekio.deco.bookmarks.product.moveFromList(url, redirectUrl, sFormSelector)
 * $.la.dekio.deco.bookmarks.product.sendEmails(url, sFormSelector)
 * $.la.dekio.deco.bookmarks.product.sendEmailsWithOutlook (url, subject, sLinkSelector)
 *** ADDRESS
 * $.la.dekio.deco.bookmarks.address.submitFilter()
 * $.la.dekio.deco.bookmarks.address.deleteFromList(url, redirectURL)
 * 
 * 
 * SEARCH
 * $.la.dekio.deco.search.init()
 *** HIT
 * $.la.dekio.deco.search.hit.click(aLink , sRedirectUrl, sDirectUrl)
 *** MODAL
 ***** BOOKMARK
 * $.la.dekio.deco.search.modal.bookmark.call(iOffset, sUrl)
 ***** DISPLAY
 * $.la.dekio.deco.search.modal.display.chooseMode(sDivForm, aLink, sRedirectUrl, sDirectUrl )
 ***** SOURCES
 * $.la.dekio.deco.search.modal.sources.update(type, offset)
 * 
 */
(function ($){
	$.la = $.la || {};
	$.la.dekio = $.la.dekio || {};
	$.la.dekio.deco = $.la.dekio.deco || {};


	$.extend(true, $.la.dekio,
	{
		options: {
			selectors: {
				header: {
					show: 'div.menu ul li.favoris, div.menu ul li.profil',
					hide: 'div.menu ul li.identifier, div.menu ul li.inscrire'
				}
			}
		},
		
		header: {
			showHide: function(aSelectors) {
				if (aSelectors == null) aSelectors = $.la.dekio.options.selectors.header;
			
				if( $.la.cookie.get('user_logged') == 'oui' && $.la.cookie.get('login_deco') != '') {
					if ( aSelectors.show != '' ) $( aSelectors.show ).addClass('on').removeClass('off');
					if ( aSelectors.hide != '' ) $( aSelectors.hide ).addClass('off').removeClass('on');
				}
				else {
					if ( aSelectors.show != '' ) $( aSelectors.show ).addClass('off').removeClass('on');
					if ( aSelectors.hide != '' ) $( aSelectors.hide ).addClass('on').removeClass('off');
				}
			},
			
			slide: {
				i: 1,
				cpt: 1,
				k: 0,
				l: 1,
				p: 70,
				t: 0,
				r: 0,
		       	
		       	init: function () {
		       		while (document.getElementById('slide'+this.cpt)) {
		       			document.getElementById('slide'+this.cpt).style.zIndex	= 1;
						document.getElementById('slide'+this.cpt).style.opacity	= this.k;
						document.getElementById('slide'+this.cpt).getElementsByTagName('img')[0].style.filter='alpha(opacity='+this.k*100+')';
						this.cpt++;
		      		}
					if (this.cpt > 1) this.fadein();
				},
		
		       	slideshow: function () {
					if (this.i>this.cpt-1) {
						this.i=1;
					}
					this.k=0;
					this.l=1;
					this.p=70;
					if (this.t>=5) {
						clearTimeout(timer);
						this.fadeout();
						return;
					}
					var timer = window.setTimeout("$.la.dekio.header.slide.slideshow()",1000);
					this.t++;
		       	},
		       	
		       	fadeout: function () {
		       		if (this.i>1) {
		       			this.r=this.i-1;
		       		}else{
		       			this.r=this.cpt-1;
		       		}
		       		if (this.l<=0) {
		       			clearTimeout(timer);
		       			this.fadein();
		       			return;
		       		}
		       		this.c=1;
		       		while (document.getElementById('slide'+this.c)) {
						document.getElementById('slide'+this.c).style.zIndex=1;
						/*document.getElementById('slide'+c).getElementsByTagName('span')[0].style.top=p+'px';*/
						this.c++;
		      		}
		       		document.getElementById('slide'+this.r).style.zIndex	= 999;
					document.getElementById('slide'+this.r).style.opacity	= this.l;
					document.getElementById('slide'+this.r).getElementsByTagName('img')[0].style.filter='alpha(opacity='+this.l*100+')';
					this.l=this.l-0.05;
					var timer = setTimeout("$.la.dekio.header.slide.fadeout()",50);
		       	},

		       	fadein: function () {
		       		if (this.k>=1) {
		       			clearTimeout(timer);
		       			this.move();
		       			return;
		       		}
		       		this.c=1;
		       		while (document.getElementById('slide'+this.c)) {
						document.getElementById('slide'+this.c).style.zIndex = 1;
						this.c++;
		      		}
		       		document.getElementById('slide'+this.i).style.zIndex	= 999;
					document.getElementById('slide'+this.i).style.opacity	= this.k;
					document.getElementById('slide'+this.i).getElementsByTagName('img')[0].style.filter='alpha(opacity='+this.k*100+')';
					this.k=this.k+0.05;
					var timer = setTimeout("$.la.dekio.header.slide.fadein()",50);
		       	},

		       	move: function () {
		       		if (this.p<=48) {
		       			clearTimeout(timer);
		       			this.t=0;
		       			this.i++;
		       			this.slideshow();
		       			return;
		       		}
					/*document.getElementById('slide'+i).getElementsByTagName('span')[0].style.top=p+'px';*/
		       		this.p=this.p-3;
					var timer = setTimeout("$.la.dekio.header.slide.move()",50);
		       	}
			}
		}
	});	


	$.extend(true, $.la.dekio.deco,
	{
		init: function() {
			$.la.dekio.init();

	        if ( $.la.cookie.get('user_logged') == 'oui' && $.la.cookie.get('login_deco') != '') {
	        	
	            if ($.la.cookie.get('login_deco') != '') {
	                var s = $.la.cookie.get('login_deco');
	                if (s.length > 9) $('#profildropdown_login').html(s.substring(0,9) + '...');
	                else $('#profildropdown_login').html(s);
	            } 
	            if ($.la.cookie.get('avatar_deco') != '') {
	                $('#profildropdown_img').attr('src', '/' + $.la.cookie.get('avatar_deco'));
	            }
	        }
	        
	        $.la.dekio.header.slide.init();
	        $.la.dekio.deco.searchzone.init();
		},
		
		/*utils: {
			ezurl: function(sUrl) {
				return $.la.sHost 
					+ (location.href.match( /deco\//g ) ? '/deco' : '') 
					+ (location.href.match( /deco_debug\//g ) ? '/deco_debug' : '') 
					+ sUrl
				;
			}
		},*/
		
		searchzone: {
			sProfil : '',
			
			aProfil: [
				{url: 'avantgarde',		value: 'Esthète avant-gardiste'},
				{url: 'eclectique',		value: 'Collectionneur éclectique'},
				{url: 'modernistes',	value: 'Moderniste joyeux'},
				{url: 'minimalistes',	value: 'Minimaliste intello'},
				{url: 'fonctionnel',	value: 'Fonctionnel chic'},
				{url: 'funkyd',			value: 'Funky design'},
				{url: 'campagne',		value: 'Nouvelle campagne'},
				{url: 'ecolo',			value: 'Ecolo-home'},
				{url: 'rustique',		value: 'Campagne rustique'},
				{url: 'confort',		value: 'Classique confort'},
				{url: 'classicisme', 	value: 'Classicisme impeccable'},
				{url: 'vintage',		value: 'Fan de vintage'},
				{url: 'pop',			value: 'Pop home'},
				{url: 'barocca',		value: 'Casa Barocca'},
				{url: 'funkyc',			value: 'Funky classic'},
				{url: 'ethnica',		value: 'Ethnic addict'},
				{url: 'ethnicm',		value: 'Ethnic modern'}
			],

			sDefaultInputText: 'Entrez votre recherche',
			
			init: function() {
		    	// Binding and initiating input value
			    var sDefaultInputText = this.sDefaultInputText;
			    $("input[id^=requete]")
			    	.val( sSearchZoneValue == '' ? sDefaultInputText : sSearchZoneValue )
				    .bind('click', function(event) {
				    	if ($(this).val() == sDefaultInputText) $(this).val('');
				    })
				    .bind('blur', function(event) {
				    	if ($(this).val() == '') $(this).val(sDefaultInputText);
				    })
			    ;

		    	var sLocation = window.location.href;
			    var sRegExp = this.aProfil[0].url;
			    for (var i = 1; i< this.aProfil.length; i++) sRegExp = sRegExp + "|" + this.aProfil[i].url;
			    
			    var reg1 = new RegExp("(" + sRegExp + ")_8");
			    if (sLocation.match(reg1)) {
			    	for (i = 0; i< this.aProfil.length; i++) {
			    		if (sLocation.match( new RegExp( this.aProfil[i].url + "_8" ) )) {
			    			$("input[id^='website']").val( this.aProfil[i].value );
			    			this.sProfil = this.aProfil[i].url; 
			    		}
			    	}
			    }

			    if( $.la.cookie.get('CoachingView') != '' && $.la.cookie.get('user_logged') == 'oui') {
			    	var sListBoxContent = '';
			    	for (i = 0; i< this.aProfil.length; i++) {
			    		sListBoxContent = sListBoxContent + '<li class="line'+ (i%2) +'"><label for="type_#search#_'+ i +'"><a href="#" rel="' + this.aProfil[i].url + '">' + this.aProfil[i].value + '</a></label></li>';
			    	}
			    	$("div[id^='showdropdown']")
			    		.bind('mouseout', function(event){
			    			$(this).css('display', 'none');
			    		})
				    	.each(function(index) {
				    		var sSearch = $(this).attr('id').replace("showdropdown", "");
				    		$(this).html('<ul id="listbox" class="listbox">' + sListBoxContent.replace("#search#", sSearch) + '</ul>');
				    	})
				    	.children('ul').bind('mouseover', function(event){
			    			$(this).parent().css('display', 'block');
			    		})
			    		.find('a').bind('click', function(event){
							event.stopPropagation();
							event.preventDefault();
							$.la.dekio.deco.searchzone.setProfil( $(this).attr('rel') );
			    		})
		    		;
				    $("span[id^='coachingLabel']").html( unescape($.la.cookie.get('CoachingView')) );
				    $("div[id^='search_zone_coaching']").attr( 'class', "profil_on" );
				}
			},
			
			setProfil: function(url) {
		    	for (i = 0; i< this.aProfil.length; i++) {
		    		if ( url == this.aProfil[i].url ) {
		    			$("input[id^='website']").val( this.aProfil[i].value );
		    			this.sProfil = this.aProfil[i].url; 
		    		}
		    	}
		    	return false;
			},
			
			submit : function(sSearch) {
				var s = '/rechercher/';
		        if ($('#requete' + sSearch).val() != 'Entrez votre recherche') var s = s + $('#requete' + sSearch).val();
			    if (this.sProfil != '') s = s + '/' + this.sProfil + '_8';
			    document.forms["search" + sSearch].action = s + '/';
			    document.forms["search" + sSearch].submit();
			}
		},
		
		address: {

			setBreadcrumbFromCookie: function() {
				var cookieValue = $.la.cookie.get('dekio_address_search');
			    if ( cookieValue == false || cookieValue == '' || cookieValue == 'none' ) {
			        $('#code').val('Ville/Code postal/Departement');
			    }
			    else {
			    	$('#code').val(cookieValue);
			        if ($('#ggl_map')) {
			            $('#ggl_map').attr('href', $('#ggl_map').attr('href') + '/(code)/' + cookieValue);
			        }
			    }
			},
			
			createInfoWindowHtml: function(categ, img, store_name, num, num_more, type, name, code, city, tel, url) {
			    var string = ' '
			    + '<div class="popup_googlemap">'
			    + '    <h1>' + categ + '</h1>'
			    + '    <div class="img"><img src="' + img + '" width="100" height="75" alt="" /></div>'
			    + '    <address>'
			    + '    <strong>' + store_name + '</strong><br />'
			    + '    ' + num + ' ' + num_more + ' ' + type + ' ' + name + '<br />'
			    + '    ' + code + ' ' + city + '<br />'
			    + '    T&eacute;l. ' + tel 
			    + '    </address>'
			    + '    <a href="' + url + '" class="savoir_plus">> en savoir plus sur cette adresse</a>'
			    + '    <a href="#" class="close_popup" onclick="javascript: map.closeInfoWindow(); return false;">Fermer</a>'
			    + '</div>';
			    return string;
			}

		},
		
		bookmarks: {
			
			product: {
				add: function(url, sSelector) {
					$.ajax({
						url: url,
			            type: "get",
			            data: $('#' + sSelector).serialize(),
				        success: function(transport, textStatus){
				            var reg1 = new RegExp("already","g");
				            if (transport.match(reg1)) {
				                $('#add_bookmarks_form').css( 'display', 'none');
				                $('#add_bookmarks_already').css( 'display', 'block');
				            }
				            else {
				                $('#add_bookmarks_form').css( 'display', 'none');
				                $('#add_bookmarks_done').css( 'display', 'block');
				            }
				            /*if (function_exists('setDocumentBookmarkClass')) setDocumentBookmarkClass(offsetBlock);*/
				            if (typeof offsetBlock != 'undefined') {
				            	$.la.dekio.deco.bookmarks.product.setDocumentClass(offsetBlock);
				            }
				            window.setTimeout("$.la.modalbox.close()",1500);
				        }
				    });
				},
				addWithoutModal: function(url, sSelector) {
					$.ajax({
						url: url,
						type: "get",
				        data: $('#' + sSelector).serialize(),
				        success: function(transport, textStatus){
				            var reg1 = new RegExp("already","g");
				            if (transport.match(reg1)) {
				                $('#add_bookmarks_form').css( 'display', 'none');
				                $('#add_bookmarks_already').css( 'display', 'block');
				            }
				            else {
				                $('#add_bookmarks_form').css( 'display', 'none');
				                $('#add_bookmarks_done').css( 'display', 'block');
				            }
				            window.setTimeout("$.la.dekio.deco.view.frame.shrink();", 2000);
				        }
				    });
				},
				setDocumentClass: function(iOffset) {
					$('#favoris-'+iOffset).addClass('on');
				},

				submitFilter: function() {
					url = filterSubmitUrl;
				    if ($('#category').val() != '') {
				        url = url + '/(categorie)/' + $('#category').val();
				    }
				    if ($('#price').val() != '') {
				        url = url + '/(prix)/' + $('#price').val();
				    }
				    window.location = url;	
				},
				
				deleteFromList: function(url, redirectURL) {
				    if (window.confirm("Attention, vous allez supprimer ce favori.")) {
				        $.ajax({
				        	url: url,
				            type: "get",
				            success: function(transport, textStatus){
				                window.location = redirectURL;
				            }
				        });
				    }
				},
				
				moveFromList: function(url, redirectUrl, sFormSelector) {
					$.ajax({
						url: url,
			            type: "get",
			            data: $(sFormSelector).serialize(),
				        success: function(transport, textStatus){
				            window.location = redirectUrl;
				        }
				    });
				},
				
				sendEmails: function(url, sFormSelector) {
					$.ajax({
						url: url,
			            type: "get",
				        data: $(sFormSelector).serialize(),
				        success: function(transport, textStatus){
							$.la.modalbox.close();
				        }
				    });
				},
				
				sendEmailsWithOutlook: function (url, subject, sLinkSelector) {
					$.ajax({
						url: url,
			            type: "get",
			            async: false,
			            success: function(transport, textStatus){
				            chaine_mail = "mailto:?subject=" + subject;
				            chaine_mail += "&body=" + transport;
				            $(sLinkSelector).attr('href', chaine_mail);
				            $(sLinkSelector).trigger('click');
				        }
				    });
				}

			},
			
			address: {
				
				submitFilter: function() {
				    url = filterSubmitUrl;
				    if ($('#category').val() != '') {
				        url = url + '/(categorie)/' + $('#category').val();
				    }
				    window.location = url;
				},
				
				deleteFromList: function (url, redirectURL) {
				    if (window.confirm("Attention, vous allez supprimer cette adresse.")) {
				    	$.ajax({
							url: url,
				            type: "get",
				            success: function(transport, textStatus){
				                window.location = redirectURL;
				            }
				        });
				    }
				}
				
			},
			
			changeLinks: function() {
				$.la.dekio.header.showHide();
		        $('.loggued').css('display', 'block');
		        $('.not_loggued').css('display', 'none');
		        $('.ajouterEnFavoris').css('display', 'none');
			}
			
		},
		
		search: {

			aOptions: {
				sModule: '',
				sQuerytext: '',
				sParamUri: '',
				iOffset: 0,
				
				sSourceUrl: '',
				sSourceUrlAjax: ''
			},
			
			noFrames: [
				"www.cotemaison.fr",
			    "madame.lefigaro.fr",
			    "www.marieclairemaison.com",
			    "www.elle.fr"
			],
			
			init: function(aOptions) {
				$.extend(true, this.aOptions, aOptions);

				this.spryWidgetCollapsiblePanel.init();

				//alert( $('a[href^=http], a[href^=/]').size() );
				
				$(".retour a[id^='favoris']").bind('click', this.hit.clickHandler);
				$(".retour a[id^='sourceid']").each(function(i){
					var aId = $(this).attr('id').split('-');
					$(this).attr('href', $.la.utils.ezurl('redirection/direct') + '/' + aId[1] + '/?url=' + $(this).attr('href') );
				});
				
				switch (this.aOptions.sModule) {
					case 'diaporama':
						this.diaporama.init();
						break;
					case 'images':
						this.gimages.init();
						break;
					case 'rechercher':
					default:
						this.list.init();
						break;
				}
				this.blocRef.init();
				this.images.init();
				
				//alert( $('a[href^=http], a[href^=/]').size() );
			},
			
			spryWidgetCollapsiblePanel: {
				aOptions: {
					brothers: {contentIsOpen: false},
					more: {
						getContentIndex: 0,
						getTabIndex: 1,
						contentIsOpen: false
					}
				},
				init: function() {
				    var self = this;
					$("div[id^=CollapsiblePanel]").each(function(i){
						if ($(this).attr('id').match( /Revelateur/gi )) new Spry.Widget.CollapsiblePanel( $(this).attr('id') , self.aOptions.brothers);
						else if ($(this).attr('id').match( /_more/gi )) new Spry.Widget.CollapsiblePanel( $(this).attr('id') , self.aOptions.more);
						else {
							new Spry.Widget.CollapsiblePanel( $(this).attr('id') );
						}
					});
				}
			},
			
			blocRef: {
				init: function() {
					$('#wrapper').append( '<div class="bloc_ref"><div class="bloc_ref_top"></div><div class="bloc_ref_cnt">' + $('.bloc_ref_off').html() + '</div><div class="bloc_ref_bottom"></div>');
				}
			},
			
			images: {
				sSelector : '.retour img.tocheck',
				init: function() {
					$( this.sSelector ).each(function(i){ 
						var oImage = this;
						var im = new Image();
					    im.onerror = function() {
					        $(oImage).attr('src', "http://www.dekio.fr/var/storage/sources/" + $(oImage).attr('rel') + ".jpg");
					    };
					    im.src = $(oImage).attr('src');
					});
				}
			},
			
			list: {
				init: function() {
					if ( $.la.cookie.get('user_logged') == 'oui' ) {
						$('.one_line .favoris').each(function(i){
							var aId = $(this).attr('id').split('-');
							$(this).append('<a href="#" class="ajoutFavoris loggued" onclick="$.la.dekio.deco.search.modal.bookmark.call(' + aId[1] + ', \'' + $.la.dekio.deco.search.bookmark.loggued(aId[1]) + '\'); return false;" alt="Ajouter à vos favoris Dékio" title="Ajouter à vos favoris Dékio"></a>');
						});

			    		$('.ajouterEnFavoris').css('display', 'none');
					}
					else {
						$('.one_line .favoris').append('<a class="ajoutFavoris not_loggued" href="' + $.la.dekio.deco.search.bookmark.notloggued() + '" title="Ajouter à vos favoris Dékio" alt="Ajouter à vos favoris Dékio"></a>');
						
						$('.ajouterEnFavoris').css('display', 'block');
					}
				}
			},
			
			gimages: {
				init: function() {}
			},
			
			diaporama: {
				init: function() {
					this.bookmarks.init();
					this.visuel.init();
				},
				bookmarks: {
					init: function(aOptions) {
						if ( $.la.cookie.get('user_logged') == 'oui' ) {
							var aId = $('.media .visuel').attr('id').split('-');
							$('.media .visuel').append('<p><span><a href="#" onclick="$.la.dekio.deco.search.modal.bookmark.call(' + aId[1] + ', \'' + $.la.dekio.deco.search.bookmark.loggued(aId[1]) + '\'); return false;" alt="Ajouter à vos favoris Dékio" title="Ajouter à vos favoris Dékio">Ajouter aux favoris</a></span></p>');
						}
						else {
							$('.media .visuel').append('<p><span><a href="' + $.la.dekio.deco.search.bookmark.notloggued() + '" title="Ajouter à vos favoris Dékio" alt="Ajouter à vos favoris Dékio">Ajouter aux favoris</a></span></p>');
						}
					}
				},
				visuel: {
					aOptions: {
						iAnimateTempo: 500,
						oCallback: function() {
			            	$('.media .visuel div .loading').remove();
		                }
					},
					
					init: function() {
						var self = this; 
						
				        var im = new Image();
				        im.onload = function() {
				            $('.media .visuel div').append('<img class="loading" src="/extension/lajavascript/design/standard/images/jquery/thickbox/loading.gif" />');
	
				            var iRatio = im.width / im.height;
				            var iImgWidth   = im.width > 390 ? 390 : im.width;
				            var iImgHeight  = im.height > 291 ? 291 : im.height;
				            
				            var aProperties = {
			                    width:  iRatio < 390/291 ? Math.floor(iImgHeight * iRatio) + 'px'	: iImgWidth + 'px',
			                    height: iRatio < 390/291 ? iImgHeight + 'px'						: Math.floor(iImgWidth / iRatio) + 'px'
			                };
			                $('.media .visuel div a img').animate(aProperties, self.aOptions.iAnimateTempo, self.aOptions.oCallback);
				        };
				        im.src = $('.media .visuel div a img').attr('src');
					}
				}
			},
			
			bookmark: {
				loggued: function(iOffset) {
					return $.la.utils.ezurl('favoris/ajouter') + '/' + iOffset + '/'
						+ $.la.dekio.deco.search.aOptions.sQuerytext + '/'
						+ ( $.la.dekio.deco.search.aOptions.sParamUri.length > 0 ? $.la.dekio.deco.search.aOptions.sParamUri + '/' : '')
					;
				},
				notloggued: function() {
					return $.la.utils.ezurl('action/login?ReturnUrl=') + $.la.utils.ezurl('diaporama')
						+ '/' + $.la.dekio.deco.search.aOptions.sQuerytext + '/'
						+ ( $.la.dekio.deco.search.aOptions.sParamUri.length > 0 ? $.la.dekio.deco.search.aOptions.sParamUri + '/' : '')
						+ ( $.la.dekio.deco.search.aOptions.iOffset > 0 ? '(offset)/' + $.la.dekio.deco.search.aOptions.iOffset : '')
					;
				}
			},
			
			hit: {
				clickHandler: function(event) {
					event.stopPropagation();

					var sDirectUrl = $.la.w.decrypt( $(this).attr('rel') );

					var aId = $(this).attr('id').split('-');
					var self = $.la.dekio.deco.search;
					var sRedirectUrl = $.la.sHost 
						+ (location.href.match(new RegExp("@deco/@","g")) ? '/deco' : '') + '/visualiser/preview/'
						+ aId[1] + '/'
						+ self.aOptions.sQuerytext + '/'
						+ ( self.aOptions.sParamUri.length > 0 ? self.aOptions.sParamUri + '/' : '')
						+ '?sType=' + $.la.dekio.deco.search.aOptions.sModule
					;
				
				    for (i=0; i < $.la.dekio.deco.search.noFrames.length; i++) {
				        if (sDirectUrl.match(new RegExp($.la.dekio.deco.search.noFrames[i],"gi"))) {
				        	$(this).attr('href', sDirectUrl);
				        	return true;
				        }
				    }
	
				    var choixAffichage = $.la.cookie.get('choix_affichage');
				    if( choixAffichage ) {
				        if( choixAffichage == 1) { // Acces Dekio
				        	$(this).attr('href', sRedirectUrl).attr('target', "_self");
				        	//$.la.w.go( $(this).attr('rel') );
				            return true;
				        }
				        else { // Acces POPUP
				        	$(this).attr('href', sDirectUrl).attr('target', "_blank");
				        	//$(this).attr('target', "_blank");
				        	//$.la.w.go( $(this).attr('rel') );
				            return true;
				        }
				    }
				    else { // Ouverture de la ModalBox
				        $.la.modalbox.call($.la.sHost + '/rechercher/choix_affichage' + '?sRedirectUrl=' + sRedirectUrl + '&sDirectUrl=' + sDirectUrl, {title: 'Inscription', height: 700, width: 900});
				    }
				    event.preventDefault();
				},
				click: function( aLink , sRedirectUrl, sDirectUrl ) {

				    for (i=0; i<$.la.dekio.deco.search.noFrames.length; i++) {
				        var reg = new RegExp($.la.dekio.deco.search.noFrames[i],"gi");
				        if (sDirectUrl.match(reg)) {
				            aLink.href = sDirectUrl;
				            aLink.target = "_self";
				            return true;
				        }
				    }

				    var choixAffichage = $.la.cookie.get('choix_affichage');
				    if( choixAffichage ) {
				        // Acces Dekio
				        if( choixAffichage == 1) {
				            aLink.href = sRedirectUrl;
				            aLink.target = "_self";
				            return true;
				        }
				        // Acces POPUP
				        else {
				            aLink.href = sDirectUrl;
				            aLink.target = "_blank";
				            return true;
				        }
				    }
				    // Ouverture de la ModalBox
				    else {
				        $.la.modalbox.call($.la.sHost + '/rechercher/choix_affichage' + '?sRedirectUrl=' + sRedirectUrl + '&sDirectUrl=' + sDirectUrl, {title: 'Inscription', height: 700, width: 900});
				    }
				    return false;
				}
			},
			
			modal: {
				bookmark: {
					call: function (iOffset, sUrl) {
					    offsetBlock = iOffset;
					    $.la.modalbox.call(sUrl, {title: 'Ajouter un favoris', height: 700, width: 800});
					}
				},
				display: {
					chooseMode: function(sDivForm, aLink, sRedirectUrl, sDirectUrl ) {
					    var bBool = false;
					    $.ajax({
							url: $.la.sHost + '/rechercher/choix_affichage',
				            type: "post",
				            data: $('#' + sDivForm).serialize(),
				            async: false,
				            beforeSend: function(XMLHttpRequest) {
						    	$('#modal').css('display', 'none');
					            $('#divLoading').css('display', 'block');
					    	},
					        success: function(transport, textStatus) {
					    	 	$.la.modalbox.close();
					    	 	bBool = $.la.dekio.deco.search.hit.click( aLink , sRedirectUrl, sDirectUrl );
					        }
					    });
					    return bBool;
					}
				},
				sources: {
					call: function () {
						$.la.modalbox.call($.la.w.decrypt( $.la.dekio.deco.search.aOptions.sSourceUrl ), {title: 'Sources', height: 700, width: 800});
					},
					update: function(type, offset) {
					    var url = $.la.w.decrypt( $.la.dekio.deco.search.aOptions.sSourceUrlAjax );
					    if (type != null && type != '') {
					        url = url + '/(type)/' + type;
					    }
					    if (offset != null && offset != '') {
					        url = url + '/(offset)/' + offset;
					    }
					    $.ajax({
							url: url,
				            type: "get",
					        success: function(transport, textStatus) {
					    		$('#toutes_les_sources').html(transport);
					        }
					    });
					}
				}
			}
		}
		
	});
	
	$.extend(true, $.la.promo.google.adsense, {
		_params: {
			google_max_num_ads: "2"
	    }
	});

})(jQuery);
