// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


/***************************Sliding navigation****************************************/
(function($) {

	$.fn.spasticNav = function(options) {
	
		options = $.extend({
			overlap :4,
			speed : 500,
			reset : 1000,
			
			easing : 'easeOutExpo'
		}, options);
	
		return this.each(function() {
		
		 	var nav = $(this),
		 		currentPageItem = $('#selected', nav),
		 		blob,
		 		reset;
		 		
		 	$('<li id="blob"></li>').css({
		 		width : currentPageItem.outerWidth(),
		 		height : currentPageItem.outerHeight() + options.overlap,
		 		left : currentPageItem.position().left,
		 		top : currentPageItem.position().top - options.overlap / 2,
		 		backgroundColor : options.color
		 	}).appendTo(this);
		 	
		 	blob = $('#blob', nav);
		 	
			$('li:not(#blob)', nav).hoverIntent(function() {
				// mouse over
				clearTimeout(reset);
				blob.animate(
					{
						left : $(this).position().left,
						width : $(this).width()
					},
					{
						duration : options.speed,
						easing : options.easing,
						queue : false
					}
				);
			}, function() {
				// mouse out	
				reset = setTimeout(function() {
					blob.animate({
						width : currentPageItem.outerWidth(),
						left : currentPageItem.position().left
					}, options.speed)
				}, options.reset);
	
			});
		
		}); // end each
	
	};

})(jQuery);


/****************************************************Popup Box**********************************************/

$(document).ready(function() {
	$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="assets/images/btn_close.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
	});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
	});

/************************************************Navigation hover********************/

$('#nav').spasticNav();

/************************************************About Us slideshow*****************/

$('#slideshowHolder').jqFancyTransitions({ width: 339, height: 256 });

/*************************************************Services & prices  show hide div ****************************************************/
   

		$('div.demo-show:eq(0)> div:gt(0)').hide();
		$('div.demo-show:eq(0)> h3').click(function() {
			$('div.demo-show:eq(0)> h3').each(function(){
				$(this).removeClass('current');
			});
			$(this).addClass('current');
			$(this).next('div:hidden').fadeIn('fast')
			.siblings('div:visible').fadeOut('fast');
		});
	  $('.demo-show div p').css('display','block');
	});
	
/****************************************grooming tips show hide Div**************************************/	
	
	
		$('div.groomingTips:eq(0)> div:gt(0)').hide();
		$('div.groomingTips:eq(0)> h3').click(function() {
			$('div.groomingTips:eq(0)> h3').each(function(){
				$(this).removeClass('current');
			});
			$(this).addClass('current');
		$(this).next('div:hidden').slideToggle(300)
		.siblings('div:visible').toggle(300);
		
});//End of document.ready////	

/******************************************gentleman said text rotator******************************/

$(document).ready(function(){ $('#features').jshowoff({speed:10000, controls:false, links: false}); });


/******************************************form validation******************************************/

/******************************************Contact us form******************************************/

$(document).ready(function(){
	  $('#enquiry').validate({
		rules: {
		  firstName: {
			required: true
		  },
		  lastName: {
			required: true
		  },
		  
		  username: {
			required: true
			
		  },
		  email: {
			required: true,
			email: true
		  },
		  phone: {
			required: true,
			number: true
			
		  },
		  enquiryDetails: {
			required: true
		  }
		},
		  messages:{
			enquiryDetails:"Please enter your enquiry",
			phone: "Numbers only please"
			},
		
		success: function(label) {
		  label.text('OK!').addClass('valid');
		}
	  
	});
});

/*******************************************************franchise opportunity form*********************************/	
	
	$(document).ready(function(){
	  $('#formFranchise').validate({
		rules: {
		  name: {
			required: true
		  },
		  email: {
			required: true,
			email: true
		  },
		  phone: {
			required: true,
			number: true
			},
		 message: {
			required: true
		  }  
		},
		 messages:{
			message:"Please enter your enquiry",
			phone: "Numbers only please"
			},
		
		success: function(label) {
		  label.text('OK!').addClass('valid');
		}
	  
	});
});

/********************************************************* admin login form ***********************************/	

$(document).ready(function(){
	$('#adminLogin').validate({
		rules: {
		  username: {
			required: true
			},
		  password: {
			required: true
		  }
		 },
		 
		
		success: function(label) {
		  label.text('OK!').addClass('valid');
		}
	  
	});
}); 

/********************************************************* change password form ***********************************/
	
	$(document).ready(function(){
	$('#changePassword').validate({
		rules: {
		  new_password: {
			required: true,
			minlength: 7
			},
		  confirm_password: {
			required: true
		  }
		  
		},
		 success: function(label) {
		  label.text('OK!').addClass('valid');
		}
	  
	});
}); 

/*********************************************************google map**********************************************/

function initialize() {
    var myLatlng = new google.maps.LatLng( -36.8499,174.7631);
    var myOptions = {
      zoom: 16,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var contentString = '<div id="content">'+
        '<div id="siteNotice">'+
        '</div>'+
        '<h1 id="firstHeading" class="firstHeading">Harleys Hair For Men</h1>'+
        '<p class="googleMap">Professional mens hair grooming in the heart of Auckland</p>'+
        '<p class="googleMap"><a href="http://www.harleyshairformen.com">'+
        'http://www.harleyshairformen.com</a> '+
        '</p>'+
        '</div>'+
        '</div>';
        
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: "Harley's Hair For Men"
    });
    google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    });
}


