$(document).ready(function() {
	
	$('#testimonial ul').innerfade({
		animationtype: 'fade',
		speed: 1000,
		timeout: 10000,
		type: 'random_start',
		containerheight: '1em'
	});
	
	$(document).pngFix(); // ie6 png fix
	
	$("#preloader").hide();
	loadTab(0);
	$('#tab0').removeClass("first");
	$('#tab0').addClass("current");
	$('#tab0 span').addClass('current');
	
	$("#tab0").click(function()
	{
		current_tab = 0;
		loadTab(0);
		$('#tab0').removeClass("first");
		$('#tab0').addClass("current");
		$('#tab0 span').addClass('current');
		
		cleanBind(0);
	});

	$("#tab1").click(function()
	{
		current_tab = 1;
		loadTab(1);
		$('#tab1').removeClass("middle");
		$('#tab1').addClass("current");
		$('#tab1 span').addClass('current');

		cleanBind(1);
	});

	$("#tab2").click(function()
	{
		current_tab = 2;
		loadTab(2);
		$('#tab2').removeClass("middle");
		$('#tab2').addClass("current");
		$('#tab2 span').addClass('current');

		cleanBind(2);
	});

	$("#tab3").click(function()
	{
		current_tab = 3;
		loadTab(3);
		$('#tab3').removeClass("middle");
		$('#tab3').addClass("current");
		$('#tab3 span').addClass('current');

		cleanBind(3);
	});

	$("#tab4").click(function()
	{
		current_tab = 4;
		loadTab(4);
		$('#tab4').removeClass("middle");
		$('#tab4').addClass("current");
		$('#tab4 span').addClass('current');

		cleanBind(4);
	});
	
	$("#tab5").click(function()
	{
		current_tab = 5;
		loadTab(5);
		$('#tab5').removeClass("last");
		$('#tab5').addClass("current");
		$('#tab5 span').addClass('current');

		cleanBind(5);
	});

	$("#tab6").click(function()
	{
		current_tab = 6;
		loadTab(6);
		$('#tab6').removeClass("subfirst");
		$('#tab6').addClass("current");
		$('#tab6 span').addClass('current');

		cleanBind(6);
	});

	$("#tab7").click(function()
	{
		current_tab = 7;
		loadTab(7);
		$('#tab7').removeClass("sublast");
		$('#tab7').addClass("current");
		$('#tab7 span').addClass('current');

		cleanBind(7);
	});


//----- Promo Banner Open Close -----

	var $cropbox = $('.banner_bottom img.slide');
	$cropbox.after('<div id="openclose" style="bottom:20px;cursor:pointer;height:26px;left:350px;position:absolute;width:46px;"><span id="close" style="width:46px; height:26px;"><img src="/img/promo_banner_arrow_up.jpg" alt="Close promo banner" /></span><span id="open" style="display:none; width:46px; height:26px;"><img src="/img/promo_banner_arrow_down.jpg" alt="Open promo banner" /></span></div>');
		
	$('div#openclose').toggle(
				
		function(){
			$cropbox.fadeOut(400);
			$('div#banner img.slide').fadeOut(400);
			$('div#banner .corp p').fadeOut(400);
			$('#banner_bg').css("height", "22px");
			
			setTimeout(function(){
				$('div#billboards').animate({height: "65px"}, 500);
				$('span#open').fadeIn('medium');	
				$('span#close').hide();
//				$('span#close').fadeOut('medium');
			}, 410);
		},
		
		function(){
			$('div#billboards').animate({height: "230px"}, 500);
			$('span#close').fadeIn('medium');
			$('span#open').hide();
			$('#banner_bg').css("height", "89px");
			
			setTimeout(function(){
				$cropbox.fadeIn(600);
				$('div#banner img.slide').fadeIn(300);
				$('div#banner .corp p').fadeIn(400);
			}, 650);
			
		}

	);

}); // end ready


function replaceHtml(el, html) {
        var oldEl = typeof el === "string" ? document.getElementById(el) :el;
        if (oldEl == null) return null;
        var newEl = oldEl.cloneNode(false);
        newEl.innerHTML = html;
        oldEl.parentNode.replaceChild(newEl, oldEl);
        return newEl;
};

	
	var pageUrl = new Array();
	pageUrl[0] = "tab0.php"; //comment ça marche
	pageUrl[1] = "tab1.php"; //plan 3d
	pageUrl[2] = "tab2.php"; //ids
	pageUrl[3] = "tab3.php"; //pano
	pageUrl[4] = "tab4.php"; //video
	pageUrl[5] = "tab5.php"; //website
	pageUrl[6] = "tab6.php"; //save money
	pageUrl[7] = "tab7.php"; //secure

	function loadTab(id)
	{
		
		cleanTab();
		if (pageUrl[id].length > 0)
		{
			$("#preloader").show();
			$.ajax(
			{
				url: pageUrl[id], 
				cache: false,
				success: function(message) 
				{			            	
					//$("#overview_content").empty().append(message);
//					$("#overview_content").replaceWith("<div id='overview_content'>"+message+"</div>");
//					$("#overview_content").empty().append(message);
					replaceHtml('overview_content', '');
//					replaceHtml('overview_content', message);
//					$("#overview_content").load(pageUrl[id]);
					document.getElementById('overview_content').innerHTML = "<div id='overview_content'>"+message+"</div>";
					if (id == 1) {
								hs.slideshowGroup =  'group1';													
								
								$('.demo').css('filter', 'alpha(opacity=40)');							
								$(".demo a").append("<span></span>");
								$(".demo a").hover(function(){
									$(this).children("span").fadeIn(600);
								},function(){
									$(this).children("span").fadeOut(200);
								});
					}
					if (id == 2) {
								hs.slideshowGroup =  'group2';
								
								$('.demo').css('filter', 'alpha(opacity=40)');							
								$(".demo a").append("<span></span>");
								$(".demo a").hover(function(){
									$(this).children("span").fadeIn(600);
								},function(){
									$(this).children("span").fadeOut(200);
								});
								
								$.getScript('commun/js/tab2.js');
					}
					
					if (id == 3) {
								hs.slideshowGroup =  'group3';
								
								$('.demo').css('filter', 'alpha(opacity=40)');							
								$(".demo a").append("<span></span>");
								$(".demo a").hover(function(){
									$(this).children("span").fadeIn(600);
								},function(){
									$(this).children("span").fadeOut(200);
								});
/*
								hs.allowSizeReduction = false;
								hs.preserveContent = false;

								hs.swfOptions = {
									version:			  "8",
									expressInstallSwfurl: "expressInstall.swf",
									flashvars:			{xml_file : "files/xml/a.xml"},
									params:			   {menu: 'false', wmode: 'opaque', bgcolor: '#f7f7f7', allowFullScreen: 'true'},
								};
*/								
					}

					if (id == 4) {
								$('.demo').css('filter', 'alpha(opacity=40)');							
								$(".demo a").append("<span></span>");
								$(".demo a").hover(function(){
									$(this).children("span").fadeIn(600);
								},function(){
									$(this).children("span").fadeOut(200);
								});
					}

					$("#preloader").hide();
				}
			});
		}
	}


// tabs

	var current_tab = 0;
	function cleanTab()
	{
		$('#tab0 span').removeClass('current');
		$('#tab1 span').removeClass('current');
		$('#tab2 span').removeClass('current');
		$('#tab3 span').removeClass('current');
		$('#tab4 span').removeClass('current');
		$('#tab5 span').removeClass('current');
		$('#tab6 span').removeClass('current');
		$('#tab7 span').removeClass('current');
		$('#tab'+current_tab).removeClass("first");
		$('#tab0').addClass("first");	
		$('#tab1').addClass("middle");	
		$('#tab2').addClass("middle");	
		$('#tab3').addClass("middle");	
		$('#tab4').addClass("middle");	
		$('#tab5').addClass("last");			
		$('#tab6').addClass("subfirst");			
		$('#tab7').addClass("sublast");			
	}
	
	function cleanBind(id)
	{

		$( ".overview_menu li" ).each(
		  
			 function( intIndex ){
				 $('#tab'+intIndex).bind (
				 "click",
				 function(){
					current_tab = intIndex;
					loadTab(intIndex);
					
					switch (intIndex) {
						case 0 :
						  $('#tab'+intIndex).removeClass("first");
						  break;
						case 5 :
						  $('#tab'+intIndex).removeClass("last");
						  break;
						case 6 :
						  $('#tab'+intIndex).removeClass("subfirst");
						  break;
						case 7 :
						  $('#tab'+intIndex).removeClass("sublast");
						  break;
						default :
						  $('#tab'+intIndex).removeClass("middle");
						  break;
					  }
				
					$('#tab'+intIndex).addClass("current");
					$('#tab'+intIndex+' span').addClass('current');
					cleanBind(intIndex);
				 }
				 );		  
			 }		  
		);

		 $('#tab'+id).removeAttr("onclick").unbind("click");
	}

// custom fade
(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

// HighSlide settings
	hs.showCredits = 0;
	hs.graphicsDir = 'commun/highslide/graphics/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.outlineType = 'rounded-white';
	hs.wrapperClassName = 'dark borderless floating-caption';
	hs.fadeInOut = true;
	hs.dimmingOpacity = .65;

	if (hs.addSlideshow) hs.addSlideshow({
		slideshowGroup: 'group1',
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .6,
			position: 'bottom center',
			hideOnMouseOut: true
		}
	});
	
	if (hs.addSlideshow) hs.addSlideshow({
		slideshowGroup: 'group2',
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .6,
			position: 'bottom center',
			hideOnMouseOut: true
		}
	});

	if (hs.addSlideshow) hs.addSlideshow({
		slideshowGroup: 'group3',
		interval: 5000,
		repeat: false,
		useControls: false,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .6,
			position: 'bottom center',
			hideOnMouseOut: true
		}
	});

//
