function scrollToDiv(currentHeader) { //this is the function that will scroll to the current element (every element must have id attribute)
	$.scrollTo( $("#"+currentHeader), 600, { //scroll to this container 
		axis:'y' //only up or down
	});
};

function scrollAfterTimeOut(id) {
	var command = "scrollToDiv('"+id+"')";
	window.setTimeout(command, 1000); //scroll after timeout because we need time to close previous container
};

$().ready(function(){

	$('.container').css({display: "none"});
	$('.pics').css({height: "582px"});
	
	$('dt:first').css({border: "none"});
	$('dd:first').css({border: "none"});
	
	$("tr:nth-child(1)").css({backgroundColor: "black", Color:"white"});
 
	$('#accordion').accordion({
		autoheight: false,
		alwaysOpen: false,
		animated: 'easeslide'
	});
	
	$.scrollTo.defaults.axis = 'xy'; //define default axis - this is necessarily (can be 'yx' etc.)
	
	$('#accordion a.header').click(function() { 
		var id = $(this).parent().attr("id"); //find id of the div with current header
		if ($(this).next().css("display") == "none") { //if it is not already selected, then scroll...
			scrollAfterTimeOut(id);
		}
	});
	
	$("#accordion").accordion("activate", -1);
    
    $('.slides_start').cycle({
    });
	    
    $('.slideshow').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides').cycle({
        fx: 'scrollHorz',
    	prev: '.prev',
    	next: '.next',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow1').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides1').cycle({
        fx: 'scrollHorz',
    	prev: '.prev1',
    	next: '.next1',
    	speed: '10',
    	timeout: 0
    });
    
     $('.slideshow2').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides2').cycle({
        fx: 'scrollHorz',
    	prev: '.prev2',
    	next: '.next2',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow3').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides3').cycle({
        fx: 'scrollHorz',
    	prev: '.prev3',
    	next: '.next3',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow4').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides4').cycle({
        fx: 'scrollHorz',
    	prev: '.prev4',
    	next: '.next4',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow5').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides5').cycle({
        fx: 'scrollHorz',
    	prev: '.prev5',
    	next: '.next5',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow6').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides6').cycle({
        fx: 'scrollHorz',
    	prev: '.prev6',
    	next: '.next6',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow7').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides7').cycle({
        fx: 'scrollHorz',
    	prev: '.prev7',
    	next: '.next7',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow8').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides8').cycle({
        fx: 'scrollHorz',
    	prev: '.prev8',
    	next: '.next8',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow9').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides9').cycle({
        fx: 'scrollHorz',
    	prev: '.prev9',
    	next: '.next9',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow10').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides10').cycle({
        fx: 'scrollHorz',
    	prev: '.prev10',
    	next: '.next10',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow11').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides11').cycle({
        fx: 'scrollHorz',
    	prev: '.prev11',
    	next: '.next11',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow12').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides12').cycle({
        fx: 'scrollHorz',
    	prev: '.prev12',
    	next: '.next12',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow13').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides13').cycle({
        fx: 'scrollHorz',
    	prev: '.prev13',
    	next: '.next13',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow14').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides14').cycle({
        fx: 'scrollHorz',
    	prev: '.prev14',
    	next: '.next14',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow15').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides15').cycle({
        fx: 'scrollHorz',
    	prev: '.prev15',
    	next: '.next15',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow16').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides16').cycle({
        fx: 'scrollHorz',
    	prev: '.prev16',
    	next: '.next16',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow17').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides17').cycle({
        fx: 'scrollHorz',
    	prev: '.prev17',
    	next: '.next17',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow18').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides18').cycle({
        fx: 'scrollHorz',
    	prev: '.prev18',
    	next: '.next18',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow19').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides19').cycle({
        fx: 'scrollHorz',
    	prev: '.prev19',
    	next: '.next19',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow20').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides20').cycle({
        fx: 'scrollHorz',
    	prev: '.prev20',
    	next: '.next20',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow21').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides21').cycle({
        fx: 'scrollHorz',
    	prev: '.prev21',
    	next: '.next21',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow22').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides22').cycle({
        fx: 'scrollHorz',
    	prev: '.prev22',
    	next: '.next22',
    	speed: '10',
    	timeout: 0
    });
    
    $('.slideshow23').hover(
        function() { $('.controls').fadeIn(); },
        function() { $('.controls').fadeOut(); }
    );
    
    $('.slides23').cycle({
        fx: 'scrollHorz',
    	prev: '.prev23',
    	next: '.next23',
    	speed: '10',
    	timeout: 0
    });
		
});


//Contac Form Validation

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'が空欄です。\n'; }
    } if (errors) alert(''+errors);
    document.MM_returnValue = (errors == '');
} }
