$(document).ready(function(){
	/** List déroulante **/ $('#marcheSelect').sSelect({ddMaxHeight: '300px'});
        /** lien Modale **/ $("ul#pages li a#a-propos").fancybox({'width':855,'height':500,'autoScale':false,'transitionIn':'none','transitionOut':'none','type':'iframe'});
        /** lien Modale **/ $("ul#pages li a#contactez-nous").fancybox({'width':455,'height':400,'autoScale':false,'transitionIn':'none','transitionOut':'none','type':'iframe'});
		/** Slider **/
        var currentPosition = 0;
        var slideWidth = 411;
        var slides = $('.slide_show');
        var numberOfSlides = slides.length;
        slides.wrapAll('<div id="slideInner"></div>').css({'float' : 'left','width' : slideWidth});
        $('#slideInner').css('width', slideWidth * numberOfSlides);

        manageControls(currentPosition); // Hide left arrow control on first load
        $('.control').bind('click', function(){ // Create event listeners for .controls clicks
            
			if(!$(this).hasClass('none')){
                currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1; // Determine new position
                manageControls(currentPosition); // Hide / show controls
                $('#slideInner').animate({'marginLeft' : slideWidth*(-currentPosition)});  // Move slideInner using margin-left
            }
        });

        function manageControls(position){ // manageControls: Hides and Shows controls depending on currentPosition
            //if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() } // Hide left arrow if position is first slide
            if(position==0){ $('#leftControl').addClass('none').fadeTo('0','0.5') } else{ $('#leftControl').removeClass('none').fadeTo('0','1') } // Hide left arrow if position is first slide
            //if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }  // Hide right arrow if position is last slide
            if(position==numberOfSlides-1){ $('#rightControl').addClass('none').fadeTo('0','0.5') } else{ $('#rightControl').removeClass('none').fadeTo('0','1') }  // Hide right arrow if position is last slide
        }

        /* Passe le id de liste au flash */
        $('#marcheSelect').change(function(){var idList = '';$('#marcheSelect option:selected').each(function(){idList += $(this).val();});$('#flash').externalInterface({method : 'ouvreFiche', args : idList});$('#rechercheInput').val('Tapez votre recherche ici...');});
        /* Champ de recherche */
        /* reset */$('#rechercheInput').click(function(){if($(this).val()== 'Tapez votre recherche ici...'){$(this).val('');}});
        /* redo */$('#rechercheInput').focusout(function(){if($(this).val()== ''){$(this).val('Tapez votre recherche ici...');}});
        /* recherche */
        $('#rechercheMarket').submit(function(){
            $.ajax({
                type: 'POST',
                url: 'search_market.php',
                data: {search_value: $('#rechercheInput').val()},
                success: function(data){$('#flash').externalInterface({method : 'selectMarche', args : data});},
                error: function(XMLHttpRequest, textStatus, errorThrown){$('#flash').externalInterface({method : 'selectMarche', args : 'NONE'});}
            });
			
            var optionFirstChild = $('#marcheSelect option:first-child').text();
            $('div#acces div.newListSelected div.selectedTxt').text(optionFirstChild);
            return false;
        });
        /* Liens des activités */
        /* recup des id */        
        $('#marcheSelect option').each(function(){
            if($(this).text()==$('div#content_left ul li:nth-child(1) p a').text()){
                $('div#content_left ul li::nth-child(1) p a').attr('href',$(this).val());
            }
            if($(this).text()==$('div#content_left ul li:nth-child(2) p a').text()){
                $('div#content_left ul li::nth-child(2) p a').attr('href',$(this).val());
            }
            if($(this).text()==$('div#content_left ul li:nth-child(3) p a').text()){
                $('div#content_left ul li::nth-child(3) p a').attr('href',$(this).val());
            }
            if($(this).text()==$('div#content_left ul li:nth-child(4) p a').text()){
                $('div#content_left ul li::nth-child(4) p a').attr('href',$(this).val());
            }
            if($(this).text()==$('div#content_left ul li:nth-child(5) p a').text()){
                $('div#content_left ul li::nth-child(5) p a').attr('href',$(this).val());
            }
        });
        /* link to flash */
        $('div#content_left ul li p a').click(function(){
            $('#flash').externalInterface({method : 'ouvreFiche', args : $(this).attr('href')});            
            var optionFirstChild = $('#marcheSelect option:first-child').text();
            $('div#acces div.newListSelected div.selectedTxt').text(optionFirstChild);
            return false;
        });
        /* lien logo accueil */
        $('div#header h1 a').click(function(){
            $('#flash').externalInterface({method : 'reset', args : ''});
            var optionFirstChild = $('#marcheSelect option:first-child').text();
            $('div#acces div.newListSelected div.selectedTxt').text(optionFirstChild);
            $('#rechercheInput').val('Tapez votre recherche ici...');
            return false;
        });
        /* reload */
        $('a#reload').click(function(){
            $('#flash').externalInterface({method : 'reset', args : ''});
            var optionFirstChild = $('#marcheSelect option:first-child').text();
            $('div#acces div.newListSelected div.selectedTxt').text(optionFirstChild);
            $('#rechercheInput').val('Tapez votre recherche ici...');
            return false;
        });

});

var categories = new Object();
var numberOfCard = 0;
var flashvars = {date : '2010-07-14'};
var params = {allowscriptaccess: 'always', wmode:'transparent'};
var attributes = {};
swfobject.embedSWF("CREMontreal.swf", "flash", "958", "582", "9.0.0", "expressInstall.swf", flashvars, params, attributes);

function onHowToGo(url){
			$.fancybox({'href':url,'width':855,'height':500,'autoScale':false,'transitionIn':'none','transitionOut':'none','type':'iframe'});
		}
