// JavaScript Document 
var launchNuagesMove;
var launchStarsMove = false;
var blinkStarsState = false;
var trueFalse = false;
var msgPerso = '' +
	'La derni\350re version d\'Internet Explorer (8.0) ou tout autre navigateur (Firefox, Chrome, Safari)' + "\n" + 
	'est pr\351f\351rable pour pouvoir profiter pleinement de cette page. ' + "\n" + 
	'En cliquant sur "Oui", vous serez redirig\351(e) vers la page de t\351l\351chargement de cette version sur le site Microsoft.com.' + "\n" + 
	'En cliquant sur "Non", vous resterez sur le site mais ne pourrez malheureusement pas appr\351cier pleinement cette page.' + "\n" + 
	'Merci.'
	;

var tmpHour = new Date;
tmpHour = tmpHour.getHours();

function checkHour() 
{
	
	var thisHour = new Date;
	thisHour = thisHour.getHours();
	//if(thisHour == 0) alert('ok')
	
	
	if( thisHour != tmpHour ) 
	{
		//alert(thisHour)
		if( ( thisHour < 8 ) || ( thisHour > 20 ) ) 
		{
			blinkStarsState = true;	
		}
		else {
			blinkStarsState = false;	
		}
		//if( blinkStarsState ) blinkStars();
		//$('#my-stars').empty();
		//clearTimeout(launchStarsMove);
		/*blinkStarsState = ( ( thisHour < 8 ) || ( thisHour > 20 ) ) ? true : false;
		if( !trueFalse ) ( blinkStarsState ) ? blinkStars() : false;*/
		
		
		tmpHour = thisHour;
		var tmpDate = thisHour;
		var dateLength = tmpDate.toString().length;
		thisHour = ( dateLength > 1 ) ? thisHour : '0' + thisHour;
		changeBackground( thisHour );
	}
	
	setTimeout('checkHour()',1000);
}

function changeBackground( hour )
{
	$('#my-background').append('<div id="magicbg" class="h'+hour+'h"></div>');
	$('#my-background').find('#magicbg').fadeIn(3000);
}

function blinkStars() 
{
		//alert('blinkStarsState')
	if( blinkStarsState ) 
	{
		trueFalse = true;
		//alert('oui')
		if( $('#my-stars-2').css('backgroundImage') == 'none' ) $('#my-stars-2').css('backgroundImage','url(images/fonds/etoiles.png)');
		//if($('#my-stars').html()=='') {
			$('#my-stars').append( '<div id="magicbg2" class="show"></div>' );
			$('#my-stars').css('z-index','5');
			$('#my-stars').find('#magicbg2').fadeIn( ( Math.random() * 1000 ) ,function() 
			{
				$('#my-stars').find('#magicbg2').fadeOut( ( Math.random() * 1000 ) ,function() 
				{
					//$('#magicbg2').remove();
					$('#my-stars').empty();
					//launchStarsMove = setTimeout( "blinkStars()",100 );
					blinkStars();
					//return false;
				});
			});
		//}
	}
	else 
	{
		trueFalse = false;
		$('#my-stars').empty();
		$('#my-stars-2').css('backgroundImage','none');
		return false;
	}
}

var actualL = 0;
var actualH = 0;
var Milli = 15;

function moveNuages(MaxiL, MaxiH, Milli) 
{
	actualL = ( actualL >= MaxiL ) ? 540 : ( actualL + 5 );
	actualH = ( actualH >= MaxiH ) ? 0 : ( actualH - 0.25 );
	
	document.getElementById('my-nuages').style.backgroundPosition = actualL + "px " + actualH + "px ";
	launchNuagesMove = setTimeout( "moveNuages( "+MaxiL+","+MaxiH+","+Milli+" )",Milli );
}

function initRefresh()
{
	//$('.content-datas').addGlow({ textColor: '#EFAA43', haloColor: '#EFAA43', radius: 100 });

	
	var Instance3 = new ImageFlow();
	/*
	var isIE6or7 = $.browser.msie ? ( $.browser.version=="6.0" || $.browser.version=="7.0" ) ? true : false : false;
	var IEVersion = isIE6or7 ? $.browser.version : false;
	
	if( isIE6or7 && globalTitle )
	{
		if (confirm( 'Votre version actuelle d\'Internet Explorer : ' + IEVersion + "\n\n" + msgPerso ))
		{
			var URL = 'http://www.microsoft.com/france/windows/products/winfamily/ie/ie8/default.aspx';
			window.open( URL, 'Mettre_a_jour_Internet_Explorer', "menubar=no, status=no, scrollbars=no, menubar=no, width=200, height=100")
		}
		else
		{
			Instance3.init({ 
						 ImageFlowID:'graphikwebstudio_gallery',
						 captions:true,
						 buttons:true,
						 slider:true,
						 startID:1,
						 imageFocusMax:10,
						 imageFocusM:1.55,
						 xStep:230
			});
		}
	}
	else
	{
		Instance3.init({ 
					 ImageFlowID:'graphikwebstudio_gallery',
					 captions:true,
					 buttons:true,
					 slider:true,
					 reflections:true,
					 reflectionPNG:true,
					 reflectionP:0.2,
					 startID:1,
					 imageFocusMax:10,
					 imageFocusM:1.55,
					 xStep:230
		});
	}
	*/
	Instance3.init({ 
		 ImageFlowID:'graphikwebstudio_gallery',
		 captions:true,
		 buttons:true,
		 slider:true,
		 reflections:true,
		 reflectionPNG:true,
		 reflectionP:0.2,
		 startID:1,
		 imageFocusMax:10,
		 imageFocusM:1.55,
		 xStep:230
	});
		
	$("#send_Contact_button").click(function(){
		getFormsDatas( this.id );
	});
	$("#send_Devis_button").click(function(){
		getFormsDatas( this.id );
	});
	
	//checkHour();
	preloadCssImages();
	
	/*Shadowbox.setup($('a.myGraphikwebstudioGallery'), {
		overlayOpacity: 0.8
	});*/
}

function getFormsDatas( id )
{
	var from = id.split('_')[ 1 ];
	
	$('#'+id).css('display','none');
	/*$('#while_sending').css('display','block');*/
	
	$('#form_errors').empty();
	
	var name = $('#name').attr('value');
	var surname = $('#surname').attr('value');
	var society = $('#society').attr('value');
	var mail = $('#mail').attr('value');
	var city = $('#city').attr('value');
	var phone = $('#phone').attr('value');
	var askingFor = $('#ask').attr('value');
	//alert( name + "\n" + surname + "\n" + mail + "\n" + city + "\n" + phone + "\n" + askingFor + "\n");
	
	var pageToCall = "ajax/reception-contact.php";
	var datas = 'c_from=' + from + '&c_name=' + name + '&c_surname=' + surname + '&c_society=' + society + '&c_mail=' + mail + '&c_city=' + city + '&c_phone=' + phone + '&c_askingFor=' + askingFor;

	$.ajax({
		type: "POST",
		url: pageToCall,
		data: datas,
		success : function(functionReturn)
		{
			if (functionReturn) 
			{
				$('#'+id).css('display','block');
				$('#form_errors').append(functionReturn);
			}
			else 
			{
				$('#before_sending').css('display','none');
				$('#after_sending').css('display', 'block');
			}
		}
		
	});
}

