//
// Scroll to div named same as '#href' (note #)
//
$(document).ready(function(e){
	
	$('#fluffy').fadeIn(900);
	//$("html,body").animate({ scrollTop: 0 }, "slow");
  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body').animate({scrollTop: targetOffset-20}, 1000);/// gives a wee bit of space to display div better - allows for padding of containing div
				$('.back_to_top a').fadeIn(300);
       return false;
      }
    }
  });
	// hide the back to top link after called
	$('.back_to_top a').click(function(){
		$('.back_to_top a').fadeOut(300);
				return false;
	});
	
		
		/*
		var myHeight = 300;
			if($("#lightbox_inner").height()>0){
				myHeight = $("#lightbox_inner").height();
			}
			*/
		//enquiry
		$("#enquiry").submit(function(){
			$('#response').height(0);
			$("#response").html('...loading');
			$("#response").load("/_custom/ajax_enquiry.php", 
			$("#enquiry").serializeArray(), function() {
				$("#response").height(0);
				$("#response").fadeIn(300, function(){
					$('#response').animate({height:100}, 500);
				});
				
				});	
			return false;
		});
		// find a consultant
		$("#consultant").submit(function(){
			$("#lightbox_inner").load("/_custom/location.php", 
				$("#consultant").serializeArray(), function() {
				$('#fl-lightbox-panel').animate({'height':410},500);
			});	
			$("#fl-lightbox").height($(document).height());
		  $("#fl-lightbox-panel").fadeIn(300);
			$("#fl-lightbox").fadeTo(300, 0.7);
			//alert (myHeight);
			myHeight = $("#lightbox_inner").height()+60;
			 return false;
		});
		
		// consultant login
		$("#login").click(function(){
			$("#lightbox_inner").load("/_custom/login.php", 
				$("#login").serializeArray(), function() {
				$('#fl-lightbox-panel').animate({'height':240},500);
			});	
			$("#fl-lightbox").height($(document).height());
		  $("#fl-lightbox-panel").fadeIn(300);
			$("#fl-lightbox").fadeTo(300, 0.7);
			 return false;
		});

		
		// search
		$("#search").submit(function(){
			//$("#main_content").fadeOut(300);
			$("#main_content").load("/_custom/search.php", 
				$("#search").serializeArray(), function() {
				$("#extra_content").html("<div id=\"extra_item\"><h3>Search Results</h3><p><strong>Please Note:</strong> Words of less than 4 characters are ignored and multiple words will return results matching any word.</p><p>So 'eye care' will only match 'care' (as 'eye' is 3 characters)</p><p>'retinal care' will return results for 'retinal' OR 'care'</p></div>");
			});	
			
			
			 return false;
		});
		//If you are requesting a "call back" please include your full telephone number and the approximate time you would prefer us to call in the box below
		$("#call_rbt").click(function(){
			var myVal='If you are requesting a "call back" please include your full telephone number and the approximate time you would prefer us to call in the box below';
			$('#response').html(myVal);
			$('#response').height(0);
			$("#response").fadeIn(300, function(){
			//$("#response").fadeIn(300), function(){
				$('#response').animate({height:100}, 500);
			//
			});
			var myVal2='Tel:\nTime:';
			$('#enquiry textarea').val(myVal2);
		});
		$("#appt_rbt, #enq_rbt").click(function(){
			var myVal='';
			$('#response').animate({height:0}, 500);
			$('#response').html(myVal);
			$("#response").fadeOut(300);
			
			var myVal2='';
			$('#enquiry textarea').val(myVal2);
		});
		 // LBox close button
		$("#fl-lightbox-panel .closer").click(function(){
		 	$("#fl-lightbox, #fl-lightbox-panel").fadeOut(300);
			//var myHeight = $("#lightbox_inner").height() + 60;
			$('#lightbox_inner').animate({height:myHeight,'background-color':'#fff'},500);
		  $('#lightbox_inner').css('backgroundColor','#fff');
		});
		  // LBox close outside of
		 $("#fl-lightbox").click(function(){ 
			$('#lightbox_inner').animate({height:myHeight,'background-color':'#fff'},500);
		 	$("#fl-lightbox, #fl-lightbox-panel").fadeOut(300);
		 });
		
		/////LIGHTBOX show button

		$(".show-panel").click(function(){
			$("#fl-lightbox").height($(document).height());
			$("#fl-lightbox-panel").fadeIn(300);
			$("#fl-lightbox").fadeTo(300, 0.7);
			 return false;
		});

		/// menu init
		
		ddsmoothmenu.init({
			mainmenuid: "nav", //Menu DIV id
			orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
			//customtheme: ["#804000", "#482400"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		})
		/////
		/// switch stylesheets
		$('a.styleswitch').click(function(){
			
				switchStylestyle(this.getAttribute("rel"));
				
				return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
		
		function switchStylestyle(styleName)
		{
			
			//$('input[name*="man"]')
			$('link[media*="screen"]').each(function(i)
			{
				this.disabled = true;
				if (this.getAttribute('title') == styleName) this.disabled = false;
			});
			createCookie('style', styleName, 365);
		}
		
/*
 // Activate the BG scrolling
  //$ (window).scroll (scroller);
	// $("html").scrollTop(0);
  // Hash links
  $ ("a[href^=#]").click (function (e) {
    ninjaScroll ($ (this).attr ("href"));
		//alert($ (this).attr ("href"));
    return false;
  });
*/
});		

	///END DocReady ///
	
	// cookie functions http://www.quirksmode.org/js/cookies.html
	function createCookie(name,value,days)
	{
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}


/*	

function scroller(e) {
  // Really simple
  $ ("body").css ("background-position", "0px " + ($ (this).scrollTop () / -5) + "px");
};

// ninjaScroll, what a film!
ninjaScroll = function (to, callback) {
  // ZERO (top) or element...
  var to = to ? ($ (to).offset ().top - 10) : 0;
  to = to < 0 ? 0 : to;
  // Opera fix (yes, this sucks)
  el = ($.browser.opera) ? $ ("html") : $ ("html, body");
  // Goo
  el.animate ({ scrollTop: to }, 1000, callback);
};

*/

