/**
 * 
 * MODALBOX $.la.modalbox.truc()
 */
(function($){

    $.la = $.la||{};
    $.extend(true,$.la,
    {
    	/* MODALBOX */
    	modalbox:{
    	/*
    	 * onclick="$.la.modalbox.ldapOpenLoginBoxRegistered();
    	 * 
    	 */	
			accordionSpeed: 'fast',
        	accordion:function(obj,callback){
    			//{'id1':false,'id2':true,etc}

				for(var id in obj) {
					$('#' + id).slideUp($.la.modalbox.accordionSpeed);
					$('#' + id).prev('h3').children('a').removeClass("opened");
				}
				for(var id in obj) {
				     if(obj[id] == true){
					 $('#'+ id).slideDown($.la.modalbox.accordionSpeed);
						$('#' + id).prev('h3').children('a').addClass("opened");
				     }
				}
    		},
    		
    		ldapOpenCloseLoginBoxRegistered:function(id){
    			// context : ldap, action : Open,  quelle modal ? : LoginBox quel onglet ? : Registered
    			//h3 a  + #ldapLoginBoxRegistered
			var obj = {};
			$("h3 + div").each(function(i){
				var currentId = $(this).attr('id');
				if(currentId !=''){
					obj[currentId] = false;
					if(currentId == id){
						if($('#' + id).css('display') == 'none'){
							obj[currentId] = true;
						}
					}
				}
			});
    			$.la.modalbox.accordion(obj,null);
    		}
		},
		promo: {
                container:'#container_full',
                interstitiel:{
                    localCss:function(obj){
                         if (obj.seanceUrl && obj.seanceUrl != '') {
                            return '';
                         } else {
                             return '#la-promo-interstitiel-div-container .bloc_interstitiel_bottom {display:none;}\n';
                         }
                    }
                },
                _adDefaultForceZoneDefer:{
		        'flottant': false, /* le mode de d�calage par d�faut pour une zone donn�e */
		        'page': false,
		        'slim_ban': 'ready',
		        'pave':  'ready',
		        'banner_footer':  'ready'                   
		    	},
		    	/* PUB IFRAME */
				pub_iframe: {
					sPosition:'',
					sTop : '',
					sRight : '',
					iFrameSelector: '#iframe_pub_droite',
					iFrameContainerSelector : '#pub_a2d_pave',
					eltSupSelectors:new Array(), 
					calcIframeSize: function (){
						var width = 0;
						var height = 0;
						var changed = false;
						
						//on cherche des elements particuliers
						for(var i=0;i<top.jQuery.la.promo.pub_iframe.eltSupSelectors.length;i++){
							if(!changed){
								top.jQuery(top.jQuery.la.promo.pub_iframe.eltSupSelectors[i],top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
									width = Math.max(width,parseInt(top.jQuery(this).css('width')));
									height = Math.max(height,parseInt(top.jQuery(this).css('height')));
									changed = true;
								});
							}								
						}
						//sinon, on cherche un element de type "iframe"				
						if(!changed){
							top.jQuery('iframe',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
								var w = this.width;
								var h = this.height;
								width = Math.max(width,w);
								height = Math.max(height,h);
								changed = true;
							});
						}
						//sinon, on cherche un element de type "object"
						if(!changed){
							top.jQuery('object',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
								if(top.jQuery.la.promo.pub_iframe.isVisible(top.jQuery(this))){
									width = Math.max(width,parseInt(top.jQuery(this).css('width')));
									height = Math.max(height,parseInt(top.jQuery(this).css('height')));
									changed = true;
								}
							});
						}						
						//sinon, on cherche un element de type "embed"
						if(!changed){
							top.jQuery('embed',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
								if(top.jQuery.la.promo.pub_iframe.isVisible(top.jQuery(this))){
									width = Math.max(width,parseInt(top.jQuery(this).css('width')));
									height = Math.max(height,parseInt(top.jQuery(this).css('height')));
									changed = true;
								}
							});
						}
						//sinon, on cherche un element de type "img"				
						if(!changed){
							top.jQuery('img',top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).get(0).contentDocument).each(function(){
								var w = this.width;
								var h = this.height;
								width = Math.max(width,w);
								height = Math.max(height,h);
								changed = true;
							});
						}
						//et on change la taille de l'iframe
						if(width != top.jQuery.la.promo.pub_iframe.initialWidth || height != top.jQuery.la.promo.pub_iframe.initialHeight){
							top.jQuery.la.promo.pub_iframe.initialWidth = width;
							top.jQuery.la.promo.pub_iframe.initialHeight = height;
							top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).attr('width',width);
							top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).attr('height', "300");						
							top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).attr('allowtransparency','true');
							if (top.jQuery.la.promo.pub_iframe.sPosition != '')
								top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).css('position',top.jQuery.la.promo.pub_iframe.sPosition);
							if (top.jQuery.la.promo.pub_iframe.sTop != '')
								top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).css('top',top.jQuery.la.promo.pub_iframe.sTop);
							if (top.jQuery.la.promo.pub_iframe.sRight != '')
								top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameSelector).css('right',top.jQuery.la.promo.pub_iframe.sRight);
							top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameContainerSelector).css('position','relative');
							top.jQuery(top.jQuery.la.promo.pub_iframe.iFrameContainerSelector).css('height', '300px');
						}
						//et on relance le script
						window.setTimeout(top.jQuery.la.promo.pub_iframe.calcIframeSize, top.jQuery.la.promo.pub_iframe.refresh);                        	
					}
				},
		        _testA2d:{
			    	'Test1' :{
		                    'flottant':8186,
		                    'page':8184,
		                    'slim_ban':8513,
		                    'pave':8516,
		                    'banner_footer':0
		                },
		            'Test2' :{
	                    'flottant':098789,
	                    'page':098801,
	                    'slim_ban':098792,
	                    'pave':098795,
	                    'banner_footer':108950
		             },
                    'Dev1' :{
	                    'flottant':122280 ,
	                    'page':110544 ,
	                    'slim_ban':110546 ,
	                    'pave':110548 ,
	                    'banner_footer':108950
		             }
		    	},
				container:'#container_full',
				containerBody:'body',
                localCss:function(obj){
                         if (obj.btn_ba_url) {
                                 $($.la.promo.container).css({overflow:'visible'});
                                 $($.la.promo.container).append('<a href="'+obj.btn_ba_url+'" style="position:absolute;top:-52px;right:0;width:217px;height:30px;"></a>');
                         }else if (obj.btn_seance_url){
                                 $($.la.promo.container).css({overflow:'visible'});
                                 $($.la.promo.container).append('<a href="'+obj.btn_seance_url+'" style="position:absolute;top:-52px;right:0;width:187px;height:30px;"></a>');
                         }
                      return '#la-promo-showskin-divswf object {margin: 5px 0 0 0;}\n';
                  }
         }
     });
 })(jQuery);
