var mycaroussel_itemList = new Array();

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycaroussel_itemList.length);
    carousel.add(i,mycaroussel_itemList[idx-1]);
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function iphoaned() {
	if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
		var swfbannerImage = '/photo/bandeaux/tpe_replace_swf.jpeg';
		var swfbannerElement = 'span[class=bandeau] object';
		var swfbannerIsHere = $(swfbannerElement);
		if (swfbannerIsHere !== undefined) {
			swfbannerIsHere.replaceWith('<img class="swfbannerimage" style="left:0px;top:4px" src="'+swfbannerImage+'"/>');
		}
	}
}

function bannerOverlay() {
  var bannerImage = '/photo/bandeaux/calque_corp.png';
  var bannerElement = 'span[class=bandeau] img';
  var bannerIsHere = $(bannerElement).attr("alt");
  var bannerTitle = $('ul#nav>li.current>a').text();
  //bannerTitle = $('head title:first').text();
  if (bannerTitle === undefined || bannerTitle === '') {
  	bannerTitle = $('#page_lib').val();
  }
  //toujours vide donc on est dans un cas pas de menu, pas de page (ex. Sitemap)
  if (bannerTitle === undefined || bannerTitle === '') {
	  bannerTitle = $('ul#container>li.title>h1').text();;
  }
  var bannerColor = '#C6D21D';
  var appendToElement = 'span[class=bandeau]';
  if (bannerIsHere !== undefined) {
     $('<img class="banneroverlay" style="position:absolute;left:0px;top:4px" src="'+bannerImage+'"/>').appendTo(appendToElement);
     var isIE = $.browser.msie;
     if(isIE)
     $('<span class="bannertitle" style="color:'+bannerColor+';font:24px Helvetica,Arial,sans-serif; letter-spacing:-2; position:absolute;left:10px;top:57px">'+bannerTitle+'</span>').appendTo(appendToElement);
     else
     $('<span class="bannertitle" style="color:'+bannerColor+';font:24px HN,Helvetica,Arial,sans-serif;position:absolute;left:10px;top:57px">'+bannerTitle+'</span>').appendTo(appendToElement);
  }
}

$(document).ready(function() { 

  var actu_html = $('#mycarousel').html();
  $('#mycarousel > li').each(function(ii){
	mycaroussel_itemList[ii] = $(this).html();
  });

/*
$('#cours_bourse').load('/cours_bourse.php?LANG='+lang);



  var refreshId = setInterval(function() {
     $('#cours_bourse').load('/cours_bourse.php?LANG='+lang);
    }, 30000);
*/

   $("div.archives ul li").hover(function(){
     $(this).addClass("hover");
   },function(){
     $(this).removeClass("hover");
   });

  testheight = $(document).height() + 4 +'px';
  testwidth = $(document).width() + 4 + 'px';
  theFrame = $("#iframeAuto", parent.document.body);
  theFrame.height(testheight);
  theFrame.width(980);

  $("a[href^='http://']").click(function(){
      if(($(this).attr("class"))=='internal'){
        return true;
      } 
      window.open(this.href);
      return false;
    }); 
    // jqueries
 // $(function(){
      // menus
      $('#nav').droppy({speed:250}); // nav
      $('#groupe').droppy({speed:250}); // footer
      
      // home:actus
      $('#mycarousel').jcarousel({
		scroll:1,
		wrap:'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
	  }); 

      //sidebar
	  $('#accordion .h3ction a').click(function() { 
			document.location.href=$(this).attr('href');  
	  });
      $("#accordion").accordion({active:true,collapsible:true,autoHeight:false,header:'.h3ction'});
      // validation:page contact uniquement
      $('#formid').validate();
    
   // });

  $("h3.current").addClass("h3ction current ui-accordion-header ui-helper-reset ui-state-active ui-corner-top");
  // flash : id de l'object
  swfobject.registerObject('indexFlashID');

   if ($('#boite_centre').length && $('#boite_droite').length) { 
      $('#boite_centre').width(430);
   }
$('#accordion h3').addClass('ui-accordion-header ui-helper-reset ui-state-default ui-corner-all');
$('#accordion div').addClass('ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom');
$('#accordion').addClass('ui-accordion ui-widget ui-helper-reset');

$('#accordion div.ui-accordion-content:not(:has(ul))').removeClass('on'); 
$('.sharethis_button a').click(function(){
     $('.sharethis_wid').slideToggle('slow');
       return false;
 });

$('#accordion h3 a').click(function() { 

	var checkElement = $(this).parent().next();
	var parent = this.parentNode.parentNode.id;
	if($('#' + parent).hasClass('noaccordion')) {
		$(this).next().slideToggle('normal');
		return false;
	}

	if(checkElement.is('div.ui-accordion-content') && (checkElement.is(':visible'))) {
		if($('#' + parent).hasClass('collapsible')) {
		$('#' + parent +  ' ul:visible').slideUp('normal');
		}
		return false;
	}

	if(checkElement.is('div.ui-accordion-content') && (!checkElement.is(':visible'))) {
		$('#' + parent + ' div.ui-accordion-content:visible').show();
		$('#' + parent + ' div.ui-accordion-content:visible').slideUp('normal');
		$('#' + parent + ' div.ui-accordion-content:visible').removeClass('on');
		if( $(checkElement).html() != ""){

			checkElement.slideDown('normal',function () {
				window.location=$(this).prev().find('a').attr('href');
			});
		}else{
			//console.log($(this).attr('href'));
			window.location=$(this).attr('href');
		}
		return false;
	}
});

bannerOverlay();
iphoaned();

});


function selectRealisationHover(image, lien, title, id_Li){
	$("#zoom_realisation_link_0").attr("href", lien);
	$("#zoom_realisation_link_1").attr("href", lien);
	$("#zoom_realisation_link_2").attr("href", lien);
	$("#zoom_realisation_img").attr("src", image);
	$(".home_zoom .title").html(title);
	$(".li_thumb").css("background-image", "url('/img/travauxpublics/realisations/cadrevignette_nosrealisations.png')");
	$("#li_thumb_"+id_Li).css("background-image", "url('/img/travauxpublics/realisations/cadrevignette_nosrealisations_active.png')");
}


 $(function() {

     $("#tabs-com").tabs();
             $("#tabs-art").tabs({ fxSlide: false});

});


