//Applies behaviour rules to the classes
//Author: Brian R Miedlar (c) 2006-2009

var AppBehavior = Class.create();
AppBehavior.Load = function() {
	
    OS.RegisterBehaviour(AppBehavior.CarouselRules);
}
AppBehavior.CarouselRules = {
    '#listeVideosGrandWidget': function(element) {
        //Simple profiles
        AppBehavior.ProfileCarousel = new Carousel('ProfileCarousel', element, 297, 116, AppBehavior, {
            setSize: 4,
            duration: .5,
            direction: 'vertical',
            itemParser: function(item) {
                //Given html element you can build a data object for the item if needed for later activation
                var sKey 			= item.down('.key').innerHTML;
                var sCaption 		= item.down('.caption').innerHTML;
				var fichierimage 	= item.down('.fichierimage').innerHTML;
                return { name: sCaption, fichierimage:fichierimage};
            },
            setItemEvents: function(carousel, itemElement, carouselItem, observer) {
                //This allows you to set events to the item like rollovers/mouse events
                Event.observe(itemElement, 'click', function() {
                    carousel.activate(carouselItem);
                });
                Event.observe(itemElement, 'mouseover', function() {
                    Element.addClassName(itemElement, 'hover');
                });
                Event.observe(itemElement, 'mouseout', function() {
                    Element.removeClassName(itemElement, 'hover');
                });
            },
            allowAutoLoopOnSet: true,
            allowAutoLoopOnIndividual: true
        });
        AppBehavior.ProfileCarousel.load();
    },
	'#listeVideosPetitWidget': function(element) {
        //Simple profiles
        AppBehavior.ProfileCarousel = new Carousel('HorizontalCarousel', element, 176, 196, AppBehavior, {
            setSize: 4,
            duration: .5,
            direction: 'horizontal',
            itemParser: function(item) {
                //Given html element you can build a data object for the item if needed for later activation
                var sKey = item.down('.key').innerHTML;
                var sCaption = item.down('.caption').innerHTML;
                return { name: sCaption};
            },
            setItemEvents: function(carousel, itemElement, carouselItem, observer) {
                //This allows you to set events to the item like rollovers/mouse events
                Event.observe(itemElement, 'click', function() {
                    //carousel.activate(carouselItem);
					window.location = carouselItem.value.name;
                });
            },
            allowAutoLoopOnSet: true,
            allowAutoLoopOnIndividual: true
        });
        AppBehavior.ProfileCarousel.load();
		AppBehavior.PetitVideos = AppBehavior.ProfileCarousel;
    },
    '#Cmd_NextItem': function(element) {
        Event.observe(element, 'click', function() {
            AppBehavior.ProfileCarousel.next();
        });
    },
    '#Cmd_PreviousItem': function(element) {
        Event.observe(element, 'click', function() {
            AppBehavior.ProfileCarousel.previous();
        });
    }
}

//EVENT OBSERVATION
AppBehavior.fireActiveCarouselLoaded = function(carousel) {
	if(carousel.carouselElement.identify() == 'listeVideosPetitWidget'){
		carousel.autoScroll = new PeriodicalExecuter(function(pe) {
			carousel.scrollForward();
		}, 6);
		Event.observe(carousel.backElement, 'click', function() {
			carousel.autoScroll.stop();
		});
		Event.observe(carousel.forwardElement, 'click', function() {
			carousel.autoScroll.stop();
		});
	}
}
AppBehavior.fireActiveCarouselItem = function(carousel, element, item) {
    element.addClassName('actif');

    // Here we can update any part of the DOM to represent our data
    // In this sample we will use the same generic viewer element for all carousels
    switch(carousel.key) {
        case 'ProfileCarousel': 
			//alert('idVideo : ' + item.value.name);
			changeVideo(item.value.name, item.value.fichierimage);
			//video = item.value.name;
			//blockVideo.addParam("flashvars","file=/Temp/videos/"+video);
			//blockVideo.write("zone_video");
            break;
            
        case 'HorizontalCarousel':
            //window.location = item.value.name;
            break;

        case 'GroupCarousel':
            $('ViewerCaption').update(item.value.name);
            $('ViewerData').update(item.value.email);
            Element.show('Viewer');
            break;
    }
}
AppBehavior.fireDeactiveCarouselItem = function(carousel, element, item) {
    element.removeClassName('actif');

    switch(carousel.key) {
        case 'ProfileCarousel': 
            break;

        case 'PictureCarousel': 
            Element.hide('Viewer');
            break;

        case 'GroupCarousel': 
            Element.hide('Viewer');
            break;
    }
}

AppBehavior.Load();

