var browserName=navigator.appName; 

var ie=false
var ie6=false
if (browserName=="Microsoft Internet Explorer"){
    ie=true

    if (!window.XMLHttpRequest)
        ie6=true
}


window.addEvent('domready',function(){
	$$('.imageGallery').each(function(elemento, indice)
	{
        initImageGallery(elemento.id)
	});
	
	$$('.jurados-module').each(function(elemento, indice)
	{
	   if(ie)
		changeVisibleDivJur(elemento)
        else
        changeVisibleDiv(elemento)
	});
})

function initImageGallery(id){
	var gallery = $(id)
    
	var handles_more = $$('#'+id+' .handles_more span');

    var size = $$('#'+id+' .imageGallery-img')[0].height
    var btnPlay = $$('#'+id+' .play')[0]
	   
    var nS = new noobSlide({
		box: $$('#'+id+' .box')[0],
		items: handles_more,
		interval: 3000,
		mode: 'vertical',
		size:size,
		fxOptions: {
			duration: 1000,
			wait: false
		},
        /*
		addButtons: {
			play: btnPlay
		},
        */
		onWalk: function(currentItem,currentHandle){
			$$(this.handles,handles_more).removeClass('active');
			$$(currentHandle,handles_more[this.currentIndex]).addClass('active');
		}
	
	});
	nS.addHandleButtons(handles_more);
    /*
    if(gallery.hasClass('autoplay')){
        setTimeout(function(){btnPlay.fireEvent('click')},5000);
    }
    */

}

function changeVisibleDivJur(el){
    var el1 = el.childNodes[1]
	

	el.addEvents({
	    'mouseover': function(){
			el1.style.visibility = "visible"
	    },
	    'mouseout': function(){
   			el1.style.visibility = "hidden"
	    }
	});
}

function changeVisibleDiv(el){
	var el1 = (el.childNodes[1].style.visibility == "hidden") ? el.childNodes[1] : el.childNodes[3]
    var el2 = (el.childNodes[1].style.visibility == "hidden") ? el.childNodes[3] : el.childNodes[1]

	if(ie){
    var tmp1 = el1
        el1  = el2
        el2  = tmp1
    }

	el.addEvents({
	    'mouseover': function(){
            el2.style.visibility = "hidden"
            el1.style.visibility = "visible"
	    },
	    'mouseout': function(){
            el1.style.visibility = "hidden"
            el2.style.visibility = "visible"
            
	    }
	});
    
}
var newsName
var newsCant
var newsPosition
var newsMoves
var dx = 240
if(ie6){
    dx = 224
}

function newsGallery(id){

    var ajax = new Request({
         method: 'post',
		 url:    "config/config.php",
         data:   "id="+id,

		 onRequest: function(){
		 },

         onSuccess: function(data){
            $("right-column-news-gal").set("html", data);
            $$('.newsGallery a').each(function(elemento, indice)
            	{
                    elemento.setStyle("background-position", " 0px 0px")
                    if("news-"+id==elemento.id){
                        elemento.setStyle("background-position", " 0px -22px")  
                    }
            	});
             
              newsName                  = $("right-column-news-gal")
              newsName.style.marginLeft = 0
              newsPosition              = 0
              newsCant                  = $$('#right-column-news-gal .news-module').length
              if(newsCant>2){
                newsMoves                 = newsCant/2
                newsMoves                 = (Math.floor(newsMoves) ==1)? 1 : Math.floor(newsMoves)-1;
              }else{
                newsMoves=0
              }
              	$$('.news-module').each(function(elemento, indice)
            	{
                    changeVisibleDiv(elemento)
            	});
              
		
	 	},
		 
         onFailure: function(){alert('Error al cargar la seccion');}
		 
      }).send();  
    
}

function moveRight(){
   var position = newsName.style.marginLeft.toInt()
   if(isNaN(position))
        position = 0
        
        //alert(newsPosition+" - "+newsMoves)
   if(newsPosition<newsMoves){
       var myFx = new Fx.Tween(newsName);
           myFx.start('marginLeft', (position-dx)+'px');
           newsPosition++
   }
}

function moveLeft(){
    var position = newsName.style.marginLeft.toInt()
   if(isNaN(position))
        position = 0
   if(newsPosition>0){
   var myFx = new Fx.Tween(newsName);
        myFx.start('marginLeft', (position+dx)+'px');
        newsPosition--
   }
}

