// JavaScript Document
// JavaScript Document

$(document).ready(function() 
  {
	  if (jQuery.browser.version != '6.0' ) {
		  $('#branding').backgroundCanvas();
		  $('#main_content').backgroundCanvas();
		  $('#choix_service').backgroundCanvas();
		  $('#choix_media').backgroundCanvas();
	  }else {
		  $('div.contenu_service').css('opacity',0.7);
	  }

	  jQuery.ajax(
	   {
			type:'POST',
			dataType:'text',
			data:{dir:$('#media').attr('init')},
			url:'slide_index.php',
			success:slideInit
		}
	  );
	  
	  $('ul.liste_service li a').hover(
		 function(){
			 if ($(this).attr('state')=='off'){
			   li=this.parentNode;
			   $(li).css('background-image','url(images/bt_on_service.jpg)');
			 }
		 },
		 function() {
			 if ($(this).attr('state')=='off'){
			   li=this.parentNode;
			   $(li).css('background-image','url(images/bt_off_service.jpg)');
			 }
		  }
		);
	  
	  $('ul.liste_media li a').hover(
		 function(){
			 if ($(this).attr('state')=='off'){
			   li=this.parentNode;
			   $(li).css('background-image','url(images/bt_on_media.jpg)');
			 }
		 },
		 function() {
			 if ($(this).attr('state')=='off'){
			   li=this.parentNode;
			   $(li).css('background-image','url(images/bt_off_media.jpg)');
			 }
		  }
		);
  }
);

$(window).load(function() 
  {
	 DrawBackground();
  }
);

$(window).resize(function() 
  {
	 DrawBackground();
  }
);

function DrawBackground()
{
	$('#branding').backgroundCanvasPaint(BackgroundPaintTopRounded);
	$('#main_content').backgroundCanvasPaint(BackgroundPaintBottomRounded);
	$('#choix_service').backgroundCanvasPaint(BackgroundPaintService);
	$('#choix_media').backgroundCanvasPaint(BackgroundPaintMedia);
	
	$('#message').backgroundCanvasPaint(BackgroundPaintMessage);
}

function BackgroundPaintService(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{

		var options = {x:0, height: height, width: width, radiusTL:14,radiusTR:0,radiusBL:14,radiusBR:0,  border: 0 };
		
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		// Draw the gradient filled inner rectangle
		options.border = 0;context.fillStyle = "#666666";
		//context.fillStyle = backgroundGradient; 
		$.canvasPaint.roundedRect(context,options);
		
}
function BackgroundPaintMedia(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{

		var options = {x:0, height: height, width: width, radiusTL:0,radiusTR:14,radiusBL:0,radiusBR:14,  border: 0 };
		context.fillStyle = "#333333";
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		// Draw the gradient filled inner rectangle
		options.border = 0;
		//context.fillStyle = backgroundGradient; 
		$.canvasPaint.roundedRect(context,options);
		
}
function BackgroundPaintContent(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{

		var options = {x:0, height: height, width: width, radius:14,  border: 0 };
		context.fillStyle = "#ffffff";
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		// Draw the gradient filled inner rectangle
		options.border = 0;
		//context.fillStyle = backgroundGradient; 
		$.canvasPaint.roundedRect(context,options);
}
function BackgroundPaintMessage(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{

		var options = {x:0, height: height, width: width, radius:14, border: 0 };
		
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		// Draw the gradient filled inner rectangle
		options.border = 0;
		context.fillStyle = "#ffefdf";
		//context.fillStyle = backgroundGradient; 
		$.canvasPaint.roundedRect(context,options);
		
}
function BackgroundPaintTopRounded(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{
		var options = {x:0, height: height, width: width, radiusTL:14,radiusTR:14,radiusBL:0,radiusBR:0,border: 0 };
		
		context.fillStyle = "#660000";
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		
		// Draw the gradient filled inner rectangle
		options.border = 0;
		$.canvasPaint.roundedRect(context,options);
}

function BackgroundPaintBottomRounded(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) 
{
		var options = {x:0, height: height, width: width, radiusTL:0,radiusTR:0,radiusBL:14,radiusBR:14,border: 0 };
		//var backgroundGradient = context.createLinearGradient(0, 0, 0, height - 2);
		context.fillStyle = "#660000";
		
		// Draw the blue border rectangle 
		$.canvasPaint.roundedRect(context,options);
		
		// Draw the gradient filled inner rectangle
		options.border = 0;
		$.canvasPaint.roundedRect(context,options);
}

function choixService(elem) {
	
	if ($(elem).attr('state')=='off') {
		$('ul.liste_service li').css('background-image','url(images/bt_off_service.jpg)');
		$('ul.liste_service li a').attr('state','off');
		$('ul.liste_service li a').css('color','#ffffff');
	
		//activation content service
		$('div.contenu_service').css('display','none');
		$('div.contenu_service').css('width','20px');
		$('a.lien_service').attr('state','off');
		id=$(elem).attr('name');
		offset=$('#conteneur_media').position();
		$('#'+id).css('position','absolute');
		$('#'+id).css('top',offset.top);
		$('#'+id).css('left',offset.left);
		//$('#'+id).effect("scale", { percent: 1700, direction: 'horizontal' }, 1000);
		$('#'+id).css('width','350px')
	    $('#'+id).show();
		$(elem).attr('state','on');
		$(elem).css('color','#ffffff');
		li=elem.parentNode;
		$(li).css('background-image','url(images/bt_on_service.jpg)');  
		
		//activation choix media
		$('ul.liste_media').hide();
		id='galerie_'+$(elem).attr('name');
		
		//li=$('#'+id+' > li'); 
	  
		//lth=$(li).width();alert('3');
		//top=(400-(lth*30))/2;
		
		//offset=$('#choix_media').position();
		$('#'+id).css('position','absolute');
		$('#'+id).css('margin-top','100px');
		
		//$('#'+id).css('left',offset.left); 
		//$('#'+id).css('left',10); 
		
		$('#'+id).show();
	
		if ( $('#'+id).attr('init') ) {
			src=$('#'+id).attr('init');
			
			if ($('#'+id+ '>li[src='+src+']').attr('src')!=undefined){
			   li_init=$('#'+id+ '>li[src='+src+']');
			}
			else
			   li_init=null;
		}else{
			li_init=li[0];
		}
		
		if (li_init != null) {
		  al=li_init.firstChild;
		  $(al).attr('state','on');
		}
		
		loadMedia(li_init);
	}
}
function loadMedia(elem) {
    $('#media').html("");
	if (elem==null) {
		service=$('ul.liste_service li a[state=on]').attr('name');
		//alert($('ul.liste_service li a[state=on]').attr('name'));
		
		id='#galerie_'+$('ul.liste_service li a[state=on]').attr('name');
		ress=$(id).attr('name');
		src=$(id).attr('init');
		
		if (ress=='photo'){
			jQuery.ajax(
			   {
					type     :'POST',
					dataType :'text',
					data     : { dir :src },
					url      :'slide_index.php',
					success  :slideInit
				}
			 );
		}else{
			jQuery.ajax(
			   {
					type     :'POST',
					dataType :'text',
					data     : { dir :src },
					url      :'slide_index.php',
					success  :videoInit
				}
			 );
		}
	}else{
		//ul=elem.parentNode;
		
		//alert($(al).attr('state'));
		$('#choix_media ul li').each(function() {
			$(this).css('background-image','url(images/bt_off_media.jpg)');
			a=this.firstChild;
			$(a).attr('state','off');
			$(a).css('color','#ffffff');
			
		 }
		);
	
		al=elem.firstChild;
		$(al).css('color','#ffffff');
		$(al).attr('state','on');
		//alert($(al).attr('state'));
	
		$(elem).css('background-image','url(images/bt_on_media.jpg)');
		src=$(elem).attr('src');
		ress=$(elem).attr('name');
   
		if (ress=='photo'){
			jQuery.ajax(
			   {
					type     :'POST',
					dataType :'text',
					data     : { dir :src },
					url      :'slide_index.php',
					success  :slideInit
				}
			 );
		}else{
			jQuery.ajax(
			   {
					type     :'POST',
					dataType :'text',
					data     : { dir :src },
					url      :'slide_index.php',
					success  :videoInit
				}
			 );
		}
	}
}
function toggleParent(id) {
    elem=$('#'+id);

	if ( $('#'+id).attr('state')=='off') {
		divparent=$(elem).parent();
		toHide='show_'+$(divparent).attr('id');
		$('#'+toHide).hide();
		//$(parent).effect("scale", { percent: 10, direction: 'horizontal' }, 1000);
		$(divparent).css('width','30px');
		$(elem).attr('state','on');
		$(elem).css('background-image','url(images/fleche_avant.png)');
	}else {
		divparent=$(elem).parent();;
		//$(parent).effect("scale", { percent: 1000, direction: 'horizontal' }, 1000);
		$(divparent).css('width','350px');
		toHide='show_'+$(divparent).attr('id');
		$('#'+toHide).show();
		$(elem).attr('state','off');
		$(elem).css('background-image','url(images/fleche_arriere.png)');
	}
}

function videoInit(data,status) {
	
	if ( data!="") {
		$('#media').html("");

		myvideo=data.split("/");

		dossier=myvideo[0];
		film=myvideo[1];

		
		flash= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="700" height="402" title="video mariage" class="myvideo"><param name="movie" value="videoplayer_bis.swf?dossier='+dossier+'&titrefilm='+film+'"/><param name="quality" value="high"/><param name="wmode" value="transparent"/><embed src="videoplayer_bis.swf?dossier='+dossier+'&titrefilm='+film+'" quality="high" WMODE="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="700" height="402"></embed></object>';
		
	
		 $('#media').html(flash);
		
	}
}
function slideInit(data,status){
	
	if (data != '' ) {
		images=data.split(",");
		html="";
		$('#media').html(html);
		for (i=0;i<images.length;i++){
			html+='<img src="'+images[i]+'" />';
		}
		$('#media').html(html);
		$('#media').cycle({
			fx:'fade',
			timeout:       4000,  // milliseconds between slide transitions (0 to disable auto advance) 
			timeoutFn:     null,  // callback for determining per-slide timeout value:  function(currSlideElement, nextSlideElement, options, forwardFlag) 
			continuous:       0,      // true to start next transition immediately after current one completes 
			speed:           1000,  // speed of the transition (any valid fx speed value) 
			speedIn:       null,  // speed of the 'in' transition 
			speedOut:       null,  // speed of the 'out' transition 
			next:           null,  // selector for element to use as click trigger for next slide 
			prev:           null,  // selector for element to use as click trigger for previous slide 
			prevNextClick: null,  // callback fn for prev/next clicks:    function(isNext, zeroBasedSlideIndex, slideElement) 
			pager:           null,  // selector for element to use as pager container 
			pagerClick:       null,  // callback fn for pager clicks:    function(zeroBasedSlideIndex, slideElement) 
			pagerEvent:      'click', // name of event which drives the pager navigation 
			pagerAnchorBuilder: null, // callback fn for building anchor links:  function(index, DOMelement) 
			before:           null,  // transition callback (scope set to element to be shown):     function(currSlideElement, nextSlideElement, options, forwardFlag) 
			after:           null,  // transition callback (scope set to element that was shown):  function(currSlideElement, nextSlideElement, options, forwardFlag) 
			end:           null,  // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options) 
			easing:           null,  // easing method for both in and out transitions 
			easeIn:           null,  // easing for "in" transition 
			easeOut:       null,  // easing for "out" transition 
			shuffle:       null,  // coords for shuffle animation, ex: { top:15, left: 200 } 
			animIn:           null,  // properties that define how the slide animates in 
			animOut:       null,  // properties that define how the slide animates out 
			cssBefore:       null,  // properties that define the initial state of the slide before transitioning in 
			cssAfter:       null,  // properties that defined the state of the slide after transitioning out 
			fxFn:           null,  // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag) 
			height:          'auto', // container height 
			startingSlide: 0,      // zero-based index of the first slide to be displayed 
			sync:           1,      // true if in/out transitions should occur simultaneously 
			random:           0,      // true for random, false for sequence (not applicable to shuffle fx) 
			fit:           0,      // force slides to fit container 
			containerResize: 1,      // resize container to fit largest slide 
			pause:           true,      // true to enable "pause on hover" 
			pauseOnPagerHover: 0, // true to pause when hovering over pager link 
			autostop:       0,      // true to end slideshow after X transitions (where X == slide count) 
			autostopCount: 0,      // number of transitions (optionally used with autostop to define X) 
			delay:           0,      // additional delay (in ms) for first transition (hint: can be negative) 
			slideExpr:       null,  // expression for selecting slides (if something other than all children is required) 
			cleartype:       !$.support.opacity,  // true if clearType corrections should be applied (for IE) 
			nowrap:           0,      // true to prevent slideshow from wrapping 
			fastOnEvent:   0,      // force fast transitions when triggered manually (via pager or prev/next); value == time in ms 
			randomizeEffects: 1,  // valid when multiple effects are used; true to make the effect sequence random 
			rev:           0,     // causes animations to transition in reverse 
			manualTrump:   true,  // causes manual transition to stop an active transition instead of being ignored 
			requeueOnImageNotLoaded: true, // requeue the slideshow if any image slides are not yet loaded 
			requeueTimeout: 250   // ms delay for requeue 
		});
		
		$('#media').show();
	}
}

function slideIndex(data,status) {
	if (data != '' ) {
		images=data.split(",");
		src=Array();
		for (i=0; i< images.length;i++) {
			src[i]=images[i];
		}
	
		$('#media').crossSlide({
            sleep: 4,
            fade: 0.75
        }, [
             {src: src[0] },
			 {src: src[1] },
			 {src: src[2] }
			
           ]
		);
	 }
} 
