
window.addEvent('load',function(){
    if($('loader')){
        var loader = new Fx.Morph($('loader'), {duration:400, wait:false,transition:Fx.Transitions.Expo.easeOut}).start({'opacity':'0'});
    }
});



function showAgenda()
{
    if(!$('agenda'))
        return;

    	var obj = new Swiff('/wp-content/themes/blastsite/agenda/agenda_blast.swf', {
	    id: 'agendaobj',
	    container:'agenda',
	    width: 931,
	    height: 555,
	    params: {
	        wmode: 'transparent',
	        bgcolor: '#ffffff',
	        allowscriptaccess:'always',
	        allowfullscreen:'true'
	    },
	    vars: {
//	       xmlPath:'/wp-content/themes/blastsite/agenda/assets/agenda1.xml',
xmlPath:'/agenda-webservice/',
	       title: 'blastagenda'

	       
	      }



	});



}



window.addEvent('domready',function(e){
        showAgenda();
	InputValue('search');
	InputValue('search2');
	InputValue('s');
	InputValue('cf_field_2')
	InputValue('cf_field_3');
        InputValue('email3');
        for(var i=2;i<=4;i++){
            InputValue('cf'+i+'_field_2');
            InputValue('cf'+i+'_field_3');
            InputValue('cf'+i+'_field_4');
            InputValue('cf'+i+'_field_5');
            InputValue('cf'+i+'_field_6');
            InputValue('cf'+i+'_field_7');
            InputValue('cf'+i+'_field_9');
            InputValue('cf'+i+'_field_10');
            InputValue('cf'+i+'_field_11');
        }

        GalleryOver();
	SearchArchives('searchform2');
	/*SearchOver();*/
	
	initShareBox();
	
	$$('input.cf_upload').each(function(el,i){
		
		
		if(el.get('value'))
		el.getPrevious().set('text',el.get('value').substr(0,15)+'...');
		});
		
	$$('input.cf_upload').addEvent('change',function(){
	
	this.getPrevious().addClass('chosen');
	this.getPrevious().set('text',this.get('value').substr(0,15)+'...');




	}); /* FIN DOM READY */

		var carrousel = new clrzSlider({
				perpage:1,
				setpage:2,
				marge:7,
				layout:'horizontal',
				container:'searchslider-content',
				items:'#searchslider-content ul li',
				contentslider:'searchslider_box',
				btnprev:'#previouslink',
				btnnext:'#nextlink',
				bordertransition:'quint:InOut',
				duration:600,
				srolling:true
				
				});
				
		var carrousel3 = new clrzSlider({
				perpage:4,
				setpage:0,
				marge:5,
				layout:'horizontal',
				container:'galleryslider-content',
				items:'#galleryslider-content ul li',
				contentslider:'galleryslider_box',
				btnprev:'#gpreviouslink',
				btnnext:'#gnextlink',
				bordertransition:'quint:InOut',
				duration:600,
				srolling:true
				
				});
	
	
	/*
	
	$$('.entry p').each(function(el,i){
		
		var content='';
		var oldcontent = el.get('html').tidy();
		
		var charcount = (oldcontent.length/2).toInt();
		
		for (c=1;c<=2;c++)
		{
			content = content+'<p class="testcol">';
			for (i=charcount-(charcount/c);i<=charcount;i++)
			{
			content = content+oldcontent[i];
			}		
			content = content+'</p>';
			
		}
		el.set('html',content);
	
		});
	
	*/

        carrouselcat();

	/* ACCORDEON SUBSCRIPTION 
	var myAccordion = new Fx.Accordion($$('.subpack'), $$('.form-pack'), {
            display: -1,
            alwaysHide: true
        });*/


        /* SUBMIT PAYPAL */
        submitPaypal();



       





	});
	
function initShareBox()
{
	var btns = $$('.openBoxBtn');
	var contents = $$('.openBoxContent');

	if(!btns)
	return;

	btns.each(function(btn,i){

	OpenSharebox(btn,contents[i]);

	});

}
	
function OpenSharebox(idlink,idbox) {

var boxH = $(idbox).getHeight();

 $(idbox).set('morph', {duration:600,transition:Fx.Transitions.Expo.easeOut,wait:false}).setStyles({'height':'0', 'opacity':'0'});
var elts = [$(idlink),$(idbox)];
ismousein = false;
// timer = null;
elts.each(function(el,i){

el.addEvents({ 
	'click': function(e){
		
			// $clear(timer);
//			if(Browser.Platform.mac)
//			var lefty = 19;
//			else
//			var lefty = 16;
			if ($(idlink).hasClass('opened')){$(idlink).removeClass('opened')} else {$(idlink).addClass('opened');}
			
			$(idbox).morph({'height':boxH,'opacity':'1'});
                        ismousein=true;
                        $$('.openBoxContent').each(function(box,inc){
                            
                            if(box!=$(idbox))
                                box.morph({'height':0,'opacity':'0'});

                        });
		
	},
	'mouseleave':function(e){
            ismousein=false;
            // timer = (function(){$(idbox).morph({'height':'0','opacity':'0'})}).delay(2000);
           /*$(document.body).addEvent('click',function(e){ $(idbox).morph({'height':'0','opacity':'0'}); });*/
          /*console.log("test");*/
	}
});

/*$(idbox).addEvent('click',function(e){ this.morph({'height':boxH,'opacity':'1'}); });*/

$(document.body).addEvent('click',function(e){ if(ismousein==false){ $$('.openBoxContent').morph({'height':'0','opacity':'0'}); $$('.openBoxBtn').removeClass('opened')}});

});



}

function GalleryOver(){

var tableover = [];
	$$('#galleryslider-content ul li img').each(function(element,i){
		tableover[i]= new Fx.Morph(element, {duration:900,wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':1})
	});

	$$('#galleryslider-content ul li').each(function(element,i){
		element.addEvents({
			'mouseover':function(e){tableover[i].start({'opacity':1});},
			'mouseleave':function(e){tableover[i].start({'opacity':1});}
		})
	});

}

function SearchOver(){

var tableover = [];
var textover = [];
	$$('#searchslider_box li img').each(function(element,i){
		tableover[i]= new Fx.Morph(element, {duration:900,wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':1})
	});

	$$('#searchslider_box li p').each(function(element,i){
		textover[i]= new Fx.Morph(element, {duration:900,wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':0})
	});

	$$('#searchslider_box li').each(function(element,i){
		element.addEvents({
			'mouseover':function(e){tableover[i].start({'opacity':1}); textover[i].start({'opacity':1});},
			'mouseleave':function(e){tableover[i].start({'opacity':1}); textover[i].start({'opacity':0});}
		})
	});

}

function SearchArchives(obj) {

	if(!$(obj))
	return;
	
	$('searchslider-content').setStyle('height',$('searchslider-container').getHeight());
	
	$(obj).addEvents({
		'submit': function (e){
			$('searchslider-content').set('html','').addClass('clrzloading');
			new Event(e).stop();
			
			var query = new Request.HTML( {url:'/webservice/?action=bottom_search&search='+$('search2').get('value'),update:'searchslider-content',evalResponse:true,method:'get',onComplete: function(Obj){
            
				$('searchslider-content').removeClass('clrzloading');
				/*SearchOver();   */
				
			var carrousel2 = new clrzSlider({
				perpage:5,
				setpage:0,
				marge:7,
				layout:'horizontal',
				container:'searchslider-content',
				items:'#searchslider-content ul li',
				contentslider:'searchslider_box',
				btnprev:'#previouslink',
				btnnext:'#nextlink',
				srolling:true
				
				});	   
               
           }}).send();
			
			return;
		}
		
		});
	

}

function InputValue(obj) {

	if(!$(obj))
	return;
	
	var defaultval = $(obj).get('value');
	
	$(obj).addEvents({
		
		focus:function()
		{
			if(defaultval==this.get('value'))
			this.setProperty('value','');
			
			
			
		},
		blur:function()
		{
			if(this.get('value')=='')
			this.setProperty('value',defaultval);
			
		}
		
		
		});
	

}


function loadtwitt(obj){

	var month =['01','02','03','04','05','06','07','08','09','10','11','12'];
	
		var date = new Date(obj[0].created_at);
	
		var date_string = date.getHours()+':'+date.getMinutes()+' le '+date.getDate()+'/'+month[date.getMonth()]+'/'+date.getFullYear();

                if ($('twitter_text')){
                    $('twitter_text').set('html',obj[0].text);
		}

		/* var _twitter_source = '<a class="twt_author" href="http://twitter.com/magazineblast" target="_blank">Blast Magazine</a> &agrave; '+date_string+' depuis '+obj[0].source;
		$('twitter_source').set('html',_twitter_source);
	
		var _avatar = obj[0].user.profile_image_url;
		var avatar = new Asset.image(_avatar, {id: 'twitter_avatar', title: 'Twitter avatar', onload: function(){
		 
			this.setProperty('align','absmiddle').inject($('twitter_source'),'top'); 
		 });}
		*/
}




function carrouselcat(){

    if(!$('fivebox'))
        return;
    
    var tablearticles = [];

    $$('#article-rubrique .post').each(function(el,i){
            tablearticles[i] = new Fx.Morph(el, {duration:300, wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':0, 'z-index':1});
    });
    tablearticles[0].set({'opacity':1, 'z-index':10});
    $$('#fivebox .post')[0].addClass('current-box');

    $$('#fivebox .post').each(function(el,i){
        el.addEvent('mouseover',function(e){
            nextSlideCat(i);
        });
    });

  
rotaterubriquetimer = this.nextSlideCat.periodical(2500,this);


    $('article-rubrique').addEvent('mouseenter',function(e){
        $clear(rotaterubriquetimer);

    });
    
}


function nextSlideCat(i){

    var stop = false;
    $$('#fivebox .post').each(function(el,j){
        if(el.hasClass('current-box')){

            if(typeof(i)=='undefined'){
                if(j<=1){
                    i=j+1;
                }else{
                   i=0;
                }
            }else if(j==i){
                stop = true;
            }
        }
    });

    if(stop==false){
        var tablearticles = [];

        $$('#article-rubrique .post').each(function(el,i){
                tablearticles[i] = new Fx.Morph(el, {duration:300, wait:false,transition:Fx.Transitions.Expo.easeOut}).set({'opacity':0, 'z-index':1});
        });

        $$('#article-rubrique .post').each(function(el,i){
                tablearticles[i].start({'opacity':0, 'z-index':1});
                $$('#fivebox .post')[i].removeClass('current-box');
        });
        tablearticles[i].start({'opacity':1, 'z-index':10});
        $$('#fivebox .post')[i].addClass('current-box');
    }
}



function submitPaypal(){
    $$('#formpaypal').each(function(el,i){
        el.submit();
    });
}

window.addEvent('load',function(e){
	
	var twitter = new Asset.javascript('http://twitter.com/statuses/user_timeline/magazineblast.json?callback=loadtwitt&count=2', {id: 'twitter'});

	
	});