//This is the javascript library for www.handfordesign.co.uk
//All rights reserved, 2009 Porcelain Development www.porcelaindev.co.uk

	function loaded(pageName){
				
		if (pageName=="profile"){		
			makeInvisible();
			$('.text').css("opacity","0");
			$('.text').animate({ opacity:"1.0" },"fast", function(){fadeIn();});}//this is a custom bit
				
		else if(pageName=="contact"){			
			makeInvisible();//Make required elements invisble	
			$('.text').css("opacity","0");			
			$('.text').animate({ opacity:"1.0" },"slow", function(){fadeIn();});//this is a custom bit
			fadeIn();}
			
		else if(pageName=="index"){					
			makeInvisible();//Make required elements invisble
			refreshBigText();//start the big text rotation (this only applies to the main index page)							
			staggeredFadeIn(7);//Fade in the boxes, one by one		
			hoverMagic(pageName);}//Apply the hover effects					
			
		else if(pageName=="product-1box"){
			makeInvisible();
			staggeredFadeIn(1);}
			
		else if(pageName=="productIndex"){
			makeInvisible();
			staggeredFadeIn();}		
			
		else if(pageName=="Garden Solutions"){			
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
			
		else if(pageName=="Outdoor Classroom"){			
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
		
		else if(pageName=="Conservatory #1"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
		
		else if(pageName=="Conservatory #2"){
			makeInvisible();
			staggeredFadeIn(7)
			hoverMagic(pageName);}
		
		else if (pageName=="Leisure Products"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
			
		else if (pageName=="Functional Sculpture #1"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
			
		else if (pageName=="Functional Sculpture #2"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
			
		else if (pageName=="Sculpture #3"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}		
			
		else if (pageName=="Outdoor #1"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}
		
		else if (pageName=="Outdoor #2"){
			makeInvisible();
			staggeredFadeIn(7);
			hoverMagic(pageName);}			
			
		else{//if no page name is defined, or page name is not one of the above
			alert("You should define a page name.");}
	}//End of loaded function!

	function fadeBoxes2(variable){
	for (i=0;i<8;i++)
		{
		if (i == variable)
		$('.box'+i).stop().animate({opacity:"1.0"},"fast");
		if (i != variable)
		$('.box'+i).stop().animate({opacity:"0.4"},"slow");
		}
	}
	
	function fadeBoxes() {
		$('.box').animate({opacity:"0.2"},"slow");
	}
	
	function hoverMagic(pageName) //This defines what text will be displayed in the "statictext" div when you hover over a box
	{	
		if(pageName=='index')
		{
			$('.logobox').hover(function(){showFadeIn('<h1>simply balanced design </h1><span class="subMain">in harmony with nature</span>'); fadeBoxes(); $('.logobox').animate({opacity:"1"},"fast"); },function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>functional sculpture</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>outdoor classroom</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>garden solutions</h1>');  fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>leisure products</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>outdoor seating</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
			$('.box6 a').hover(function() {showFadeIn('<h1>conservatory</h1>'); fadeBoxes2(6);},function(){hideFadeIn(); });						
		}
		else if(pageName=='Leisure Products')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes(); },function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>loop</h1>'); fadeBoxes2(1); },function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>base weight</h1>');  fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>float</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>tree lounger</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
		}
		else if(pageName=='Outdoor Classroom')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>');  fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>story teller\'s chair</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>living seat</h1>'); fadeBoxes2(2); },function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>recycled bench</h1>');  fadeBoxes2(3); },function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>kiddies chair</h1>');  fadeBoxes2(4); },function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>junior bench</h1>');  fadeBoxes2(5); },function(){hideFadeIn();});
			$('.box6 a').hover(function() {showFadeIn('<h1>block table</h1>');  fadeBoxes2(6); },function(){hideFadeIn();});
			
		}
		else if(pageName=='Conservatory #1')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>');  fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>rock clock</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>stone roses</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>easy reader</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>rock chair</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>beanbag lounger</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
			$('.box6 a').hover(function() {showFadeIn('<h1>rock solid</h1>'); fadeBoxes2(6);},function(){hideFadeIn();});
		}
		else if(pageName=='Conservatory #2')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>bow tie chair</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>pedastal shelf</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>metal petals</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>sto-cage</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>bookend</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
			$('.box6 a').hover(function() {showFadeIn('<h1>coffee table</h1>'); fadeBoxes2(6);},function(){hideFadeIn();});
		}
		else if(pageName=='Functional Sculpture #1')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>cantilever</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>form decking</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>arch seat</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>monoseat</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>malham</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
		}
		else if(pageName=='Functional Sculpture #2')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>rainbow</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>posts</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>surf seat</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>D bench</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>beach bum</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
		}
		else if(pageName=='Sculpture #3')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>arch seat</h1>'); fadeBoxes2(1); },function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>recycled</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>beach bum</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>ogden</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>posts</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
		}
		else if(pageName=='Garden Solutions')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1><span style="text-transform:capitalize;">K</span>9 dwelling</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>parasol base</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>plinth</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>bird table round</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>bird table square</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
			$('.box6 a').hover(function() {showFadeIn('<h1>obelisk</h1>'); fadeBoxes2(6);},function(){hideFadeIn();});
		}
		else if(pageName=='Outdoor #2')
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>block bench</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>picnic bench</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>stone bench</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>natural rest</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>peda-stool</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
			//$('.box6 a').hover(function() {showFadeIn('<h1></h1>'); fadeBoxes2(6);},function(){hideFadeIn();});
			//$('.box7 a').hover(function() {showFadeIn('<h1>posts bench</h1>');},function(){hideFadeIn();});
		}
		else if(pageName=='Outdoor #1')
		
		{
			$('.logobox').hover(function() {showFadeIn('<h1>home</h1>'); fadeBoxes();},function(){hideFadeIn();});
			$('.box1 a').hover(function() {showFadeIn('<h1>newgale</h1>'); fadeBoxes2(1);},function(){hideFadeIn();});
			$('.box2 a').hover(function() {showFadeIn('<h1>provence</h1>'); fadeBoxes2(2);},function(){hideFadeIn();});
			$('.box3 a').hover(function() {showFadeIn('<h1>dales</h1>'); fadeBoxes2(3);},function(){hideFadeIn();});
			$('.box4 a').hover(function() {showFadeIn('<h1>rock-bottom seat</h1>'); fadeBoxes2(4);},function(){hideFadeIn();});
			$('.box5 a').hover(function() {showFadeIn('<h1>lakeland</h1>'); fadeBoxes2(5);},function(){hideFadeIn();});
			$('.box6 a').hover(function() {showFadeIn('<h1>urban seat</h1>'); fadeBoxes2(6);},function(){hideFadeIn();});
			//$('.box7 a').hover(function() {showFadeIn('<h1>cage table</h1>');},function(){hideFadeIn();});
		}
	}//end of hoverMagic function
	

	i=0; var t;//these get set up on the first run only	
	
	function refreshBigText(value) {//This rotates the big text every 5 seconds 
		
		if (i>4)i=0;	//If i gets to 5, reset it to zero. 
					//Fill in the text based on the value of i	
				
		if (i==1){
			$(".bigtext").animate({opacity:"0.0"},"slow",function()
				{$(".bigtext").html("<h1>design</h1>");});
			$(".bigtext").animate({opacity:"1.0"},"slow");			
		}
		else if (i==2){
			$(".bigtext").animate({opacity:"0.0"},"slow",function()
				{$(".bigtext").html("<h1>fabrication</h1>");});
			$(".bigtext").animate({opacity:"1.0"},"slow");					
		}
		else if (i==3){
			$(".bigtext").animate({opacity:"0.0"},"slow",function()
				{$(".bigtext").html("<h1>installation</h1>");});
			$(".bigtext").animate({opacity:"1.0"},"slow");		
		}
		else if (i==4){
			$(".bigtext").animate({opacity:"0.0"},"slow",function()
				{$(".bigtext").html("<h1>eco-friendly outdoor furniture</h1>");});
			$(".bigtext").animate({opacity:"1.0"},"slow");			
		}				
		i++;
		//Do it all again in 5 seconds time
		t=setTimeout("refreshBigText()",5000);
		
  	}
		
  	function makeInvisible() {
		$('.box').css("opacity","0");
		//$('.bigtext').css("opacity","0");
		$('.footer').css("opacity","0");
	}
	
	function fadeIn() {
		$('.box').animate({ opacity: "1.0" }, "slow");
		$('.bigtext').animate({ opacity:"1.0" },"slow");	
		$('.footer').animate({ opacity:"1.0" },"slow");			
	}
	
	function fadeOutandGoTo(url) {
		$('.box').animate({ opacity: "0.0" }, "slow");
		//$('.bigtext').animate({ opacity:"0.0" },"slow");
		$('.text').animate({ opacity:"0.0" },"slow");
		$('.statictext').stop().animate({ opacity:"0.0" },"slow");		
		$('.breadcrumb').animate({ opacity:"0.0" },"slow");
		$('.submenu').animate({opacity:"0.0" },"slow");
		$('.footer').animate({ opacity:"0.0" },"slow", function(){
			window.location = url;			
		});
		$('#menuLink').removeClass('selected');
	}
	
	function showFadeIn(string)
	{
		$(".bigtext").hide();
		$('.statictext').css("opacity","0");	
		$(".statictext").show();
	 	$(".statictext").html(string);
	 	$('.statictext').stop().animate({ opacity:"1.0" },"fast");	
	}
	
	function hideFadeIn()
	{
		
		//fade out the static text
		$('.statictext').stop().animate({ opacity:'0.0' },'slow', function(){
			$('.statictext').hide();
			$('.box').stop().animate({ opacity:"1.0" },'fast');	
			//when it has faded out, fade in the original text
			$('.bigtext').css('opacity','0');	
			$('.bigtext').show();
			$('.bigtext').stop().animate({ opacity:"1.0" },'fast');	
			
		});				
		
	}
	
	//this either fades boxes in based on an argument, or defaults to 6 boxes	
	function staggeredFadeIn(boxes) {
		
		$('.footer').animate({ opacity:"1.0" },"slow");	
		
		if (boxes==1){
		$(".box1").animate({opacity:"1.0"},"fast", function(){
				$(".bigtext").animate({opacity:"1.0"},"slow");
			});
		}
		else if(boxes==3){
		$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box3").animate({ opacity:"1.0" },"fast", function(){
							
								$(".bigtext").animate({ opacity:"1.0" },"slow");
							
						});
					});
				});	 
			}
		else if(boxes==4){
		$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box3").animate({ opacity:"1.0" },"fast", function(){
							$(".box4").animate({ opacity:"1.0" },"fast", function(){
								$(".bigtext").animate({ opacity:"1.0" },"slow");
							});
						});
					});
				});	 
			}
		else if(boxes==5){
		$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box2").animate({ opacity:"1.0" },"fast", function(){
					$(".box5").animate({ opacity:"1.0" },"fast", function(){
						$(".box3").animate({ opacity:"1.0" },"fast", function(){
							$(".box4").animate({ opacity:"1.0" },"fast", function(){
								$(".bigtext").animate({ opacity:"1.0" },"slow");
							});
						});
					});
				});
			});	 
		}
		else if(boxes==6){
			$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box6").animate({ opacity:"1.0" },"fast", function(){
					$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box5").animate({ opacity:"1.0" },"fast", function(){
							$(".box3").animate({ opacity:"1.0" },"fast", function(){
								$(".box4").animate({ opacity:"1.0" },"fast", function(){
									$(".bigtext").animate({ opacity:"1.0" },"slow");
								});
							});
						});
					});
				});
			});
		}
		else if(boxes==7){
			$(".bigtext").animate({ opacity:"1.0" },"fast");
			
				$(".box1").animate({ opacity:"1.0" },"fast", function(){
					$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box3").animate({ opacity:"1.0" },"fast", function(){
							$(".box4").animate({ opacity:"1.0" },"fast", function(){
								$(".box5").animate({ opacity:"1.0" },"fast", function(){
									$(".box6").animate({ opacity:"1.0" },"fast", function(){
										$(".box7").animate({ opacity:"1.0" },"slow");
									});
								});
							});
						});
					});
				});	
		}
		else if(boxes==8){
			$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box6").animate({ opacity:"1.0" },"fast", function(){
					$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box5").animate({ opacity:"1.0" },"fast", function(){
							$(".box3").animate({ opacity:"1.0" },"fast", function(){
								$(".box4").animate({ opacity:"1.0" },"fast", function(){
									$(".box7").animate({ opacity:"1.0" },"fast", function(){
										$(".box8").animate({ opacity:"1.0" },"fast", function(){
											$(".bigtext").animate({ opacity:"1.0" },"slow");
										});
									});
								});
							});
						});
					});
				});
			});
		}
		else if(boxes==9){
			$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box6").animate({ opacity:"1.0" },"fast", function(){
					$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box5").animate({ opacity:"1.0" },"fast", function(){
							$(".box3").animate({ opacity:"1.0" },"fast", function(){
								$(".box4").animate({ opacity:"1.0" },"fast", function(){
									$(".box7").animate({ opacity:"1.0" },"fast", function(){
										$(".box9").animate({ opacity:"1.0" },"fast", function(){
											$(".box8").animate({ opacity:"1.0" },"fast", function(){
												$(".bigtext").animate({ opacity:"1.0" },"slow");
											});
										});
									});
								});
							});
						});
					});
				});
			});
		}
		else if(boxes==10){
			$(".box1").animate({ opacity:"1.0" },"fast", function(){
				$(".box6").animate({ opacity:"1.0" },"fast", function(){
					$(".box2").animate({ opacity:"1.0" },"fast", function(){
						$(".box5").animate({ opacity:"1.0" },"fast", function(){
							$(".box3").animate({ opacity:"1.0" },"fast", function(){
								$(".box4").animate({ opacity:"1.0" },"fast", function(){
									$(".box7").animate({ opacity:"1.0" },"fast", function(){
										$(".box8").animate({ opacity:"1.0" },"fast", function(){
											$(".box10").animate({ opacity:"1.0" },"fast", function(){
												$(".box9").animate({ opacity:"1.0" },"fast", function(){
													$(".bigtext").animate({ opacity:"1.0" },"slow");
												});
											});
										});
									});
								});
							});
						});
					});
				});
			});
		}
		
		
	}
	
