$(document).ready(function(){
	
	$('#pourquibulle').hide();
	
	$('#bulle_pourqui').mouseover(function(){
		$('#pourquibulle').show();
	});
	
	var flashvars = {};
	var stageW = 664;
	var stageH = 398;

	flashvars.imagePath				= 	"/img/still.jpg";
	flashvars.viewInfoButton 		=	"true";
	flashvars.viewFullscreenButton 	=	"true";
	flashvars.viewScaleButton 		=	"true";
	flashvars.viewVolumeControls 	=	"true";
	flashvars.viewTime				=	"true";
	flashvars.viewBigPlayButton 	=	"true";
	flashvars.viewRightClickMenu 	=	"true";
	flashvars.mouseHide				=	"true";
	flashvars.mouseHideTime			=	"3";
	flashvars.doubleClick			=	"true";
	flashvars.oneClick				=	"true";
	flashvars.spaceKey				=	"true";
	flashvars.videoLoop				=	"false";
	flashvars.videoAutoPlay			=	"false";
	flashvars.videoBufferTime		=	"0.1";
	flashvars.tlInterval			=	"100000";
	flashvars.soundVolume			=	"0.8";
	flashvars.fullSizeView			=	"3";
	flashvars.spacing 				=	"10";
	flashvars.controlHeight			=	"25";
	flashvars.volumeLengthW			= 	"50";
	flashvars.color1 				= 	"0x2e2e2e";
	flashvars.color2 				= 	"0x000000";
	flashvars.alpha1 				= 	"1";
	flashvars.alpha2 				= 	"1";
	flashvars.borderColor 			= 	"0x555555";
	flashvars.borderAlpha			= 	"1";
	flashvars.timeColor1			= 	"0x333333";
	flashvars.timeColor2			= 	"0x111111";
	flashvars.timeAlpha1			= 	"1";
	flashvars.timeAlpha2			= 	"1";
	flashvars.timeTextColor1		= 	"0xffffff";
	flashvars.timeTextColor2		= 	"0x888888";
	flashvars.scrubberHeight 		=	"3";
	flashvars.scrubberColor1		= 	"0x333333";
	flashvars.scrubberAlpha1		= 	"1";
	flashvars.scrubberColor2		= 	"0xC700FF";
	flashvars.scrubberAlpha2		= 	"1";
	flashvars.filterColor			= 	"0xC700FF";
	flashvars.filterAlpha			= 	"1";
	flashvars.titleColor			=	"0xC700FF";
	flashvars.descriptionColor		=	"0xD3D3D3";
	flashvars.infoBackgroundColor	=	"0x000000";
	flashvars.infoBackgroundAlpha	=	"0.5";

	var params 						= {};
	params.scale 					= "noscale";
	params.allowfullscreen 			= "true";
	params.salign 					= "tl";
	params.bgcolor 					= "000000";
	//params.wmode 					= "transparent";
	
	flashvars.videoPath = $('a.video').attr('rel');
	
	var attributes = {};
	swfobject.embedSWF("/flash/player/video-player.swf", "flashDiv", stageW, stageH, "9.0.0", false, flashvars, params, attributes);
	 	
	$('a.video').each(function(i){ 
		$(this).click(function(){ 
			$('a.video').removeClass('active_video');
			$(this).addClass('active_video');
			flashvars.videoPath = $(this).attr('rel');
			flashvars.title = $(this).attr('title');
			flashvars.videoAutoPlay = "true"; 
			swfobject.embedSWF("/flash/player/video-player.swf", "flashDiv", stageW, stageH, "9.0.0", false, flashvars, params, attributes); 
		}); 
	});
	
	sIFR.bAutoInit
	if(typeof sIFR == "function"){
		sIFR.replaceElement("h1", named({sFlashSrc: "/scripts/sIFR-2.0.7/avantgarde.swf", sColor: "#E73CCD",sWmode:"transparent"}));
		sIFR.replaceElement("h2", named({sFlashSrc: "/scripts/sIFR-2.0.7/avantgarde.swf", sColor: "#363535",sWmode:"transparent"}));
		sIFR.replaceElement("h3", named({sFlashSrc: "/scripts/sIFR-2.0.7/avantgarde.swf", sColor: "#FFFFFF",sWmode:"transparent"}));
		sIFR.replaceElement("h4", named({sFlashSrc: "/scripts/sIFR-2.0.7/avantgarde.swf", sColor: "#2C2C2C",sWmode:"transparent"}));
		sIFR.replaceElement("h5", named({sFlashSrc: "/scripts/sIFR-2.0.7/avantgarde.swf", sColor: "#E73CCD",sWmode:"transparent"}));
	};
	
	
	function mycarousel_initCallback(carousel)
	{
	    // Disable autoscrolling if the user clicks the prev or next button.
	    carousel.buttonNext.bind('click', function() {
	        carousel.startAuto(0);
	    });

	    carousel.buttonPrev.bind('click', function() {
	        carousel.startAuto(0);
	    });

	    // Pause autoscrolling if the user moves with the cursor over the clip.
	    carousel.clip.hover(function() {
	        carousel.stopAuto();
	    }, function() {
	        carousel.startAuto();
	    });
	};

		
    jQuery('#meusinvest_carousel').jcarousel({
    	wrap: 'circular',
    	start: 1,
    	auto: 2,
    	scroll: 1,
    	initCallback: mycarousel_initCallback
    });
    
    jQuery('#video_carousel').jcarousel({
    	vertical: true,
    	scroll: 5,
    	wrap: 'circular'
    });
    
    $('.bubble_top, .bubble_answer').hide();
    
    var answers = $('.bubble_answer');
    var tops = $('.bubble_top');
    var links = $('.question');
    
    links.each(function(i, item){
    	var link = $(item);
    	link.click(function(e) {
    		e.preventDefault();
    		tops.hide();
	    	answers.hide();
	    	$(tops[i]).fadeIn();
	    	$(answers[i]).fadeIn();
    	});
    });
    /**
    $('.question').click(function(){
    	$('.bubble_top, .bubble_answer').hide();
    	$(this).parent().parent().children(':first').fadeIn();
    	$(this).parent().parent().children(':first').next().fadeIn();
    });
    **/

/***********
 * DIALOG BOG ERROR MANAGEMENT	
 *******************/

		if($('.errors').val() != undefined)
		{
			$('#dialog').append($('.errors'));
			$("#dialog").dialog(
					{ 
						autoOpen: true,
						modal: true,
						minHeight: 150,
						width:500,
						show: 'slide',
						title: 'Message'
					}
			);
		}
		if($('.msg').val() != undefined)
		{
			$('#dialog').append($('.msg'));
			$("#dialog").dialog(
					{ 
						autoOpen: true,
						modal: true,
						minHeight: 150,
						width:500,
						show: 'slide',
						title: 'Message'
					}
			);
		}
		
/***********
 * PREVIEW
 *******************/	
	$('#preview').click(function(){
		var ref = $('#ref').val();
		var date = $('#publish_date').val();
		var title = $('#title').val();
		var desc = $('#desc').val();
		var file = $('#file').val();
		var tags = $('#tags').val();		
		
		var preview = 
			'Ref :' + ref + 
			'<br/> Date : ' + date + 
			'<br/> Title : ' + title +
			'<br/> Desc : ' + desc +
			'<br/> File : ' + file +
			'<br/> Tags : ' + tags;
		
		$('#dialog').html(preview);
		$("#dialog").dialog(
				{ 
					autoOpen: true,
					modal: true,
					minHeight: 550,
					width:500,
					show: 'slide',
					title: 'Message'
				}
		);
	});
	
	/***********
	 * SELECT de société participée
	 *******************/
	$('#form_entreprise select').selectmenu({
		style:'dropdown', 
		menuWidth: 400
	});	
	
});
