/** ------------------------------------------------------
// Preload d'image
*/
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


jQuery.preLoadImages("http://www.pigier.tv/pigier/prehome/pigier/www/img/common/footer/logo-pigier-com-on.png",
		"http://www.pigier.tv/pigier/prehome/pigier/www/img/common/footer/perf-on.png",
		"http://www.pigier.tv/pigier/prehome/pigier/www/img/common/footer/crea-on.png",
		"http://www.pigier.tv/pigier/prehome/pigier/www/img/common/footer/question-on.png",
		"http://www.pigier.tv/pigier/prehome/pigier/www/img/common/footer/infos-on.png");

/** ------------------------------------------------------
// Initialisation 
*/
jQuery(document).ready(function(){
						   
		/* Demande de doc */
		if(jQuery('a.triggerDemandeDocumentation')) {
			jQuery('a.triggerDemandeDocumentation').click(function(evt) {
				showPopinDocumentation();
			});
		}
		
		if(jQuery('a.triggerClosePopinDocumentation')) {
			jQuery('a.triggerClosePopinDocumentation').click(function(evt) {
				closePopin('#popinDocumentation');
			});
		}
		
		/* Rappel */
		if(jQuery('a.triggerWebCallBack')) {
			jQuery('a.triggerWebCallBack').click(function(evt) {
				showPopinWebCallBack();
			});
		}
		
		if(jQuery('a.triggerClosePopinWebCallBack')) {
			jQuery('a.triggerClosePopinWebCallBack').click(function(evt) {
				closePopin('#popinCallBack');
			});
		}
		
		
		jQuery('.rollover').hover(function(){
			jQuery(this).attr('src', jQuery(this).attr('src').replace(/-off./,'-on.'));
		},
		function(){
			jQuery(this).attr('src', jQuery(this).attr('src').replace(/-on./,'-off.'));
		});
		

		if (jQuery.browser.msie && jQuery.browser.version <= 6) {
			jQuery('#navigation > li').hover(function(){
				jQuery(this).addClass('lihover');
			},
			function(){
				jQuery(this).removeClass('lihover');
			});
		}
		
		jQuery('body').addClass('jsOn');
		
		if(jQuery('#carousel-wrapper').size()>0){
			var myCarrousel = new Carrousel('#carousel', 
					'.bt-carousel-right', 
					'.bt-carousel-left', 
					'#carousel-wrapper', 
					500, 
					'H', 
					null);
			
			jQuery('#carousel > li > a').bind('click', function(e) {
				e.preventDefault();
				
				$(this).parents('ul').find(' > li a.active').removeClass('active');
				$(this).addClass('active');
				
				loadMedia($(this).attr('rel'));
			});
			
		}
});

function PlayerInitialised(){	
	jQuery('#carousel > li > a:first').trigger('click');
}

/** ------------------------------------------------------
// Affiche la popin de demande de documentation 
*/
function showPopinDocumentation()
{
  if (jQuery('#popinDocumentation'))
  {            
    if (jQuery('#iFrameDocumentation'))
    	jQuery('#iFrameDocumentation').attr('src', 'http://www.pigier.com/WebPigier/documentation.aspx');
	
    jQuery('#popinDocumentation').css ({'display' : 'block'});
	jQuery('#bgPopin').css ({'display' : 'block'});
  }
}

/** ------------------------------------------------------
// Affiche la popin de demande de rappel
*/
function showPopinWebCallBack()
{
  if (jQuery('#popinCallBack'))
  {            
    if (jQuery('#iFrameCallBack'))
    	jQuery('#iFrameCallBack').attr('src', 'http://3620.arcane-networks.com/3620statsV2/dispo_callback.php?id_client=516351895e4457a1edbdd9bae857cb35&id_bouton=193&id_position=information%20libre&urlFrom=http://www.pigier.com/WebPigier/qui-sommes-nous.aspx');
	
    jQuery('#popinCallBack').css ({'display' : 'block'});
	jQuery('#bgPopin').css ({'display' : 'block'});
  }
}


/** ------------------------------------------------------
// Cache les popin
*/
function closePopin(id)
{
  if (jQuery(id))
  {
	  jQuery(id).css ({'display' : 'none'});
	  jQuery('#bgPopin').css ({'display' : 'none'});
  }
}

function popupDocumentation(page)
{
	var largeur = 640;
	var hauteur = 577;
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+",menubar=\"no\",scrollbars=\"no\",resizable=\"no\",statusbar=\"no\"");
}
