// JavaScript Document
<!--
defpos = '20px';
defbutton = "home";
defbutton1 = 'bloom';
defbutton2 = 'aboutus';
activeimg = 1;
primary = "home";
secondary = "aboutus";
framerate = 24;
speed = 1;
intervalDelay = 1000/(framerate*speed);
pos = 0;
interval = 0;
focused = 1;

function scrolltextup() {
	intervalid = setInterval(movetextup, intervalDelay);
}

function movetextup(){
 maxPos =  $("#txt").height() - 380; 
 //alert(maxPos);
 
 if (pos > -maxPos) {
	 $("#txt").animate({'margin-top':  '-=3'}, intervalDelay-20 ); 
	 pos = pos - 3;
 }
}
function scrolltextdown() {
	intervalid = setInterval(movetextdown, intervalDelay);
}

function movetextdown(){

 maxPos =  $("#txt").height() - 380; 
 //alert(maxPos);
 if (pos <= 0) {
	 $("#txt").animate({'margin-top':  '+=3'}, intervalDelay-20 ); 
	 pos = pos + 3;
 }
}

function scrolltextstop() {
  clearInterval(intervalid);

}

function loadtext(page) {
	$("#page-content").fadeOut(500, function() {
	
		$('#page-content').load(page, function() {
			 $("#page-content").fadeIn(2000);
			 
			  pos=0;			
			
			  if ($(".content-text-scrollable").length) {
					  
				  if ($('#txt').outerHeight() > "385") {
					  $("#page-content").height($('#txt').outerHeight()+110);
					  $(".content-text-scrollable").height($('#txt').outerHeight()+10);
					  $("#content").animate({height: ($('#txt').outerHeight()+177)+'px'}, 'slow');
				  } else {
				  
					  $(".content-text-scrollable").height(385);
					  $("#page-content").height(485);
					  $("#content").animate({height: (542+'px')}, 'slow');
			  	  }
			  } else {
					  $(".content-text-scrollable").height(385);
					  $("#page-content").height(485);
					  $("#content").animate({height: (542+'px')}, 'slow');
				  
			  }
			  
			  $('.error').hide();  
			   $(".sendfield").click(function() {  
				 // validate and process form here  
			   
				 $('.error').hide();  
				   var firstname = $("input#firstname").val();  
				 //  alert (name);
					 if (firstname == "") {  
					   $("label#name_error").show();  
					   $("input#name").focus();  
					   return false;  
					 }  
					var email = $("input#email").val();  
					if (email == "") {  
					   $("label#email_error").show();  
					   $("input#email").focus();  
					   return false;  
					}  
					var phone = $("input#phone").val();  
					var message = $("textarea#message").val();  
					if (message == "") {  
					   $("label#message_error").show();  
					   $("input#message").focus();  
					   return false;  
					} 
					dataString = 'name='+ firstname + '&email=' + email + '&phone=' + phone + '&message=' + message;  
				 	//alert (dataString);
					//return false;  
				 	$.ajax({  
						type: "POST",  
						url: "bin/process.php",  
						data: dataString,  
						success: function() {  
								 $('#contact_form').html("<div id='message'></div>");  
								 $('#message').html("<h3>enquiry form submitted</h>")  
								 .append("<p>We will be in touch soon.</p>")  
								 .hide()  
								 .fadeIn(1500);  
								 
						 }});  
			   		return false;
			   });  
			   
		});
		
	});
	
}


function newimgsinit(paths) {
	//if the focus is set 1
	// set the intial target as image1
	//set the new target as  image2
	if (focused == 1) {
		target = "#image1";		
		newtarget = "#image2"
		focused = 0;
	} else {
		target = "#image2";		
		newtarget = "#image1";	
		focused = 1;
	}
	// stop any current animations on the init target
	//alert(focused);
	$("#page-image").stop(true, false);
	
	
	//empty the new target
	$(newtarget + " img").remove();
	
	count = 0;	
	for (x in paths) {
	 var img1 = new Image();
		$(img1) 
		.load(function () {
			count++;
			//$(img1).hide()
			 $(newtarget)
				.append(this)			
       		    .removeClass('loading');
				if (count == paths.length) {
					
					$(target).animate({opacity: 0, speed: 3000});
					$(newtarget).animate({opacity: 1.0, speed: 3000});
//					alert ( target + "and " + newtarget);
					//alert (count);
				//	$(target).animate({opacity: 0.1, speed: 500});
					//$(newtarget).animate({opacity: 1.0, top: 0, left: 0, speed: 500});
					$(newtarget).cycle({speed: 2000, timeout: 4000, delay: 1500 });
				}
			})
		.error(function () {
		  // notify the user that the image could not be loaded
			})
		.attr('src', paths[x]);
		
	}
}



$( init );

function init() {

  $('#home').animate({opacity: 0.7}, 'fast' );
  $('#navabout').animate({opacity: 0.0}, '0' );
  $('#navproducts').animate({opacity: 0.0}, '0' );
  $('#navstockist').animate({opacity: 0.0}, '0' );
  $('#navproducts').hide();
  $('#navabout').hide();
  $('#navstockist').hide();
  $('#bloom').animate({opacity: 0.7}, '0' );
  $('#aboutus').animate({opacity: 0.7}, '0' );
  $('#tas').animate({opacity: 0.7}, '0' );
 
  
 /* $('#about').bind( 'mouseover', overabout );
  $('#home').bind( 'mouseover', overhome );
  $('#products').bind( 'mouseover', overproducts );
  $('#stockist').bind( 'mouseover', overstockist );
  $('#contact').bind( 'mouseover', overcontact );
  $('#blog').bind( 'mouseover', overblog );  
   $('#bloom').bind( 'mouseover', overbloom );
  $('#wood').bind( 'mouseover', overwood );
  $('#perspex').bind( 'mouseover', overperspex );
  $('#aboutus').bind( 'mouseover', overaboutus );
  $('#grandeliers').bind( 'mouseover', overgrandeliers );
  $('#tas').bind( 'mouseover', overtas );
  $('#vic').bind( 'mouseover', overvic );
  $('#qld').bind( 'mouseover', overqld );
  $('#act').bind( 'mouseover', overact );
  $('#sa').bind( 'mouseover', oversa );
  $('#nt').bind( 'mouseover', overnt );
  $('#wa').bind( 'mouseover', overwa );
  $('#nsw').bind( 'mouseover', overnsw );*/
  
  //$('#about').bind( 'mouseover', overabout );
// $('#about').bind( 'mouseout', outabout );
 
 $('#about').bind( 'mouseover', function() {overbutton ('about')} );
  $('#home').bind( 'mouseover', function() {overbutton ('home')} );
  $('#products').bind( 'mouseover', function() {overbutton ('products')} );
  $('#stockist').bind( 'mouseover', function() {overbutton ('stockist')} );
  $('#contact').bind( 'mouseover', function() {overbutton ('contact')} );
  $('#blog').bind( 'mouseover', function() {overbutton ('blog')} );
  $('#aboutus').bind( 'mouseover', function() {overbutton ('aboutus')} );
  $('#grandeliers').bind( 'mouseover', function() {overbutton ('grandeliers')} );
  $('#tas').bind( 'mouseover', function() {overbutton ('tas')} );
  $('#vic').bind( 'mouseover', function() {overbutton ('vic')} );
  $('#qld').bind( 'mouseover', function() {overbutton ('qld')} );
  $('#act').bind( 'mouseover', function() {overbutton ('act')} );
  $('#sa').bind( 'mouseover', function() {overbutton ('sa')} );
  $('#nt').bind( 'mouseover', function() {overbutton ('nt')} );
  $('#wa').bind( 'mouseover', function() {overbutton ('wa')} );
  $('#nsw').bind( 'mouseover', function() {overbutton ('nsw')} );
 
 
 
   $('#home').bind( 'mouseout', function() {outbutton ('about')} );
  $('#products').bind( 'mouseout', function() {outbutton ('products')} );
  $('#stockist').bind( 'mouseout', function() {outbutton ('stockist')} );
  $('#contact').bind( 'mouseout', function() {outbutton ('contact')} );
  $('#blog').bind( 'mouseout', function() {outbutton ('blog')} );
  $('#aboutus').bind( 'mouseout', function() {outbutton ('aboutus')} );
  $('#grandeliers').bind( 'mouseout', function() {outbutton ('grandeliers')} );
  $('#tas').bind( 'mouseout', function() {outbutton ('tas')} );
  $('#vic').bind( 'mouseout', function() {outbutton ('vic')} );
  $('#qld').bind( 'mouseout', function() {outbutton ('qld')} );
  $('#act').bind( 'mouseout', function() {outbutton ('act')} );
  $('#sa').bind( 'mouseout', function() {outbutton ('sa')} );
  $('#nt').bind( 'mouseout', function() {outbutton ('nt')} );
  $('#wa').bind( 'mouseout', function() {outbutton ('wa')} );
  $('#nsw').bind( 'mouseout', function() {outbutton ('nsw')} );
// $('#about').bind( 'click', clickabout );
 
  
	$('#about').bind( 'click', function() { clickit( 'about', 'aboutus.html', 'images/mains/aboutus.jpg', '85px', 'navabout', 'aboutus', '35px'); });
	$('#home').bind( 'click', function() { clickit( 'home', 'home.html', 'images/products/bloom/BLOOM PENDANT.jpg, images/mains/perspex.jpg, images/products/wood/BAROQUE PENDANT.jpg', '20px'); });
    $('#products').bind( 'click', function() { clickit( 'products', 'products.php', 'images/products/bloom/BLOOM PENDANT.jpg, images/mains/perspex.jpg, images/products/wood/BAROQUE PENDANT.jpg', '155px'); });
	$('#contact').bind( 'click', function() { clickit( 'contact', 'contact.html', 'images/mains/contactus.jpg', '320px'); });
	$('#stockist').bind( 'click', function() { clickit( 'stockist', 'stockist-tas.html', 'images/mains/stockist.jpg', '240px', 'navstockist', 'tas', '16px'); });
	$('#grandeliers').bind( 'click', function() { clicksub( 'navabout', 'grandeliers', 'grandeliers.html', '140px', 'images/mains/grandeliers.jpg'); });
	$('#aboutus').bind( 'click', function() { clicksub( 'navabout', 'aboutus', 'aboutus.html', '35px', 'images/mains/aboutus.jpg'); });
	$('#tas').bind( 'click', function() { clicksub( 'navstockist', 'tas', 'stockist-tas.html', '16px', 'images/mains/stockist.jpg'); });
	  $('#vic').bind( 'click', function() { clicksub( 'navstockist', 'vic', 'stockist-vic.html', '63px', 'images/mains/stockist.jpg'); });
	  $('#qld').bind( 'click', function() { clicksub( 'navstockist', 'qld', 'stockist-qld.html', '158px', 'images/mains/stockist.jpg'); });
	  $('#act').bind( 'click', function() { clicksub( 'navstockist', 'act', 'stockist-act.html', '207px', 'images/mains/stockist.jpg'); });
	  $('#sa').bind( 'click', function() { clicksub( 'navstockist', 'sa', 'stockist-sa.html', '250px', 'images/mains/stockist.jpg'); });
	  $('#nt').bind( 'click', function() { clicksub( 'navstockist', 'nt', 'stockist-nt.html', '332px', 'images/mains/stockist.jpg'); });
	  $('#wa').bind( 'click', function() { clicksub( 'navstockist', 'wa', 'stockist-wa.html', '295px', 'images/mains/stockist.jpg'); });
	  $('#nsw').bind( 'click', function() { clicksub( 'navstockist', 'nsw', 'stockist-nsw.html', '108px', 'images/mains/stockist.jpg'); });
	
	
   arr = new Array("images/products/bloom/BLOOM PENDANT.jpg", "images/mains/perspex.jpg", "images/products/wood/BAROQUE PENDANT.jpg");
  newimgsinit(arr);
}

function overbutton (target) {
		$('#'+target).animate({opacity: 0.7}, 'slow');
}

function outbutton (target) {
	if ((defbutton1 !== target) && (defbutton2 !== target)) {
	  $('#'+target).animate({opacity: 1.0}, 'slow');
	}
}





function clicksub(secnav, secnavpage, secnavpageurl, secnavpos, secpageimages ){
if (secondary !== secnavpage) {

//set the primary and secondary pages
  secondary = secnavpage;	
  defbutton2 = secondary;
//stop the images scrolls and unfade all buttons all content
 $('#image1').stop(true, true);
 
 $('#navstockist img').animate({opacity:1.0}, 'fast');
  $('#navabout img').animate({opacity:1.0}, 'fast');

// stop the nav arrow sliding about	
  $('#'+secnav+'-nav-arrow').stop(true, true);
  
  $('#'+secnav+'-nav-arrow').animate({'padding-left': secnavpos}, 1000);

	$('#'+secnavpage).animate({opacity: 0.7}, '0' );
  
  
 // hide all secondary nav
   
  loadtext(secnavpageurl);
  arr = secpageimages.split(',');
  newimgsinit(arr);
 }	
}

function clickit( pagename, pageurl, pageimages, defpos, secnav, secnavpage, secnavpos ) {

// if the page primary page is another page then make the nav happen.	
if (primary !== pagename) {

//set the primary and secondary pages
  primary = pagename;	
  secondary = secnavpage;

// stop the images scrolls and unfade all buttons all content
 $('#image1').stop(true, true);
 $('#flashnav img').animate({opacity:1.0}, 'fast');
 $('#navstockist img').animate({opacity:1.0}, 'fast');
  $('#navabout img').animate({opacity:1.0}, 'fast');
// stop the nav arrow sliding about	
  $('#nav-arrow').stop(true, true);
  
  defbutton = primary;
// slightly fade the correct button
  $('#'+primary ).animate({opacity: 0.7}, 'slow');
  
// move the nave arrow into the correct space
  $('#nav-arrow').animate({'padding-left': defpos}, 1000);
  
  // hide all secondary nav
  if (secnav !== "navstockist") {
	  $('#navstockist').animate({opacity: 0.0}, 'slow' ); 
	  $('#navabout').hide();
  }
  
  if (secnav !== "navabout") {
	  $('#navabout').animate({opacity: 0.0}, 'slow' ); 
  }
  
  if (typeof (secnav) !== 'undefined') {
  	//hide other secondary navigation
	   $('#'+secnav).show();
	   $('#'+secnav).animate({opacity: 1.0}, 'slow' );
  	   $('#'+secnavpage).animate({opacity: 0.7}, '0' );
  	   $('#'+secnav+'-nav-arrow').animate({'padding-left': secnavpos}, 1000);
  
  }
  loadtext(pageurl);
  arr = pageimages.split(',');
  newimgsinit(arr);
 }
}



//-->
