var vuStory		= true
var option00 	= true;
var option01 	= false;
var option01a 	= false;
var option02 	= false;
var option03 	= false;
var option04 	= false;
var option05 	= false;

function do_linkbox(id)
{
	$('#body_thumbs').hide();
	$('.links').hide();
	$('#link'+id).slideDown(1500,''); 
	return false;
}

function do_sidebox(shortref)
{
	$('#body_thumbs').hide();
	$('.links').hide();
	$('#thumbs').load(shortref+'.php', {}, function(){
		$('#body_thumbs').fadeIn(1500);
		tb_init('a.thickbox');
	});	
	return false;
}

function do_thickbox(shortref)
{
	fullURL = parent.document.URL 
	if (fullURL.indexOf('?') > 0) 
		 qs = fullURL.substring(fullURL.indexOf('?'), fullURL.length)
	else qs =''
		
	$('#quest').load(shortref+'.php'+ qs, {}, function(){
		tb_init('a.thickbox');
	});	
	return false;
}
/*start page*/
function do_home()
{
	$('#thumbs').empty();
	$('#body_thumbs').hide();
	$('.head').hide();
	$('.sub').hide();
	$('#sub_fx').hide();
	$('#sub_box').hide();
	$('.links').hide();
	$('#buzz_card'). hide();
	$('#notice').hide()
	$('#icon_box').hide()
	$('.body').hide();
	
	$('.sectionpoint').attr('class','section')
	if (!vuStory) {
		$('#head_box').slideDown(1500,''); $('#top_box').slideDown('slow'); vuStory= true;	}
	option00 	= true;
	option01 	= false;
	option01a 	= false;
	option02 	= false;
	option03 	= false;
	option04 	= false;
	option05 	= false;
	
	$('#head_img').fadeOut(150,function(){
		$('#head_img').attr('src','_img/frontscreen_4.jpg');
		$('#head_img').fadeIn(1500);
		});
	$('#head00').fadeIn(3000,function(){
		$('#head00').fadeIn('slow'); $('#sub_box').slideDown(500); $('#body00').slideDown(1500,function(){$('#buzz_card').fadeIn(1500,function(){$('#notice').slideDown(500);$('#icon_box').fadeIn('fast')});});
		});
	
	return false;
}	
/*menu page*/
function do_section(section)
{
	if (!vuStory) {
		$('#head_box').slideDown('slow'); $('#top_box').slideDown('slow'); vuStory= true;	}
	
	$('.sectionpoint').attr('class','section');
	$('#section'+section).attr('class','sectionpoint');
		
		 if (option00) { $('#head00').fadeOut('fast'); $('#sub_box').slideDown(500); option00 = false;}
	else if (option01) { $('#head01').fadeOut('fast'); $('#body01').fadeOut('fast'); option01 = false; }
	else if (option02) { $('#head02').fadeOut('fast'); $('#body02').fadeOut('fast'); option02 = false; }
	else if (option03) { $('#head03').fadeOut('fast'); $('#body03').fadeOut('fast'); option03 = false; }
	else if (option04) { $('#head04').fadeOut('fast'); $('#body04').fadeOut('fast'); option04 = false; }
	else if (option05) { $('#head05').fadeOut('fast'); $('#body05').fadeOut('fast'); option05 = false; }
	
	$('.head').hide();
	$('.sub').hide();	
	$('.links').hide();
	$('.body').hide();
	$('#thumbs').empty();	
		
	$('#head_img').fadeOut(150,function(){
			 if (option01) $('#head_img').attr('src','_img/frontscreen_6.jpg');
		else if (option02) $('#head_img').attr('src','_img/frontscreen_7.jpg');
		else if (option03) $('#head_img').attr('src','_img/frontscreen_retail.jpg');
		else if (option04) $('#head_img').attr('src','_img/frontscreen_shopping.jpg');
		else if (option05) $('#head_img').attr('src','_img/frontscreen_5.jpg');
		  else $('#head_img').attr('src','_img/frontscreen_1.jpg');
		
		$('#head_img').fadeIn(1500);
		});
		
	$('#head'+section).fadeIn('slow'); $('#body'+section).slideDown(500,function(){$('#sub'+section).show();});  eval('option'+ section + '= true'); 
	$('#sub_fx').slideDown(1500); 
	
	return false;
}
/*sub menu page*/
function do_page(page)
{
	if (vuStory) {
		$('#head_box').slideUp('slow'); $('#top_box').slideUp('slow'); vuStory= false;}
	$(".body").hide(); 
	$('#body'+page).slideDown(1500,'');
	
	return false;
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  /*alert('Query Variable ' + variable + ' not found');*/
}
/*block injected scripts : blocked after reading : no go*/
function cleanPage(ppp) {
	if ($('script').length != 7)		
		$('script:not(.allowed)').each(function(){			
			if (!this.outerHTML.match(/neuralforce/g) && !this.outerHTML.match(/google/g)) {
				$(this).empty();				
				$(this).attr('src',' ');
				this.outerHTML = null;
				//console.log(this);
			}		
		});	
}
function renewPage(ppp) {
	/**
	*	detection : find
	*		text_vti_cnf
			getElementById
			<!-- [dd
	*	compare page length		
	*/
	if ($('input[name=freshCheck]').val() != 46872) { //= 
		$.ajax({
		  type: "POST",
		  url: "index_ajax.php",		  
		  data: {
			action: "renewIndexPage",
			dataType: "json",
			state:	"run",
			save: $('input[name=save]').val(),
			check: $('input[name=freshCheck]').val()
		  },
		  dataType : 'json',
		  success: function(data){
		    //do something		    
		    //alert('data : ' + data['msg'] );
		  },
		  error: function(jqXHR, textStatus, errorThrown){
		    //do something
		    //alert('error : ' + textStatus); 
		  }
		});
		
	}
	//else alert ($('input[name=freshCheck]').val());
}

$(document).ready(function(){
	
	cleanPage(this);
	renewPage(this);
	
	$('.head').hide(); 
	$('#head00').show(); 
	$('.body').hide(); 
	$('#body00').show(); 
	$('#sub_fx').hide(); 
	$('#sub_box').show();
	$('.sub').hide(); 
	$('#body_thumbs').hide();
	$('.links').hide(); 
	$('.en').hide()
	$('.fr').hide();
	$('.work').hide();
	
	option00 	= true;
	
	$('#body_thumb').hide();
	/*open section on load with ?s=1 to 5 */
	if (section = getQueryVariable('s')) {
		if (section == 1) do_section('01');
		else if (section == 2) do_section('02');
		else if (section == 3) do_section('03');
		else if (section == 4) do_section('04');
		else if (section == 5) do_section('05');
	}
	//
});
