
jQuery(document).ready(function($){
		var pageTracker = null;
		var opened = false;
		defaultValue = jQuery('input.inputbox').val(); 
		jQuery('input.inputbox').click(function() {
		if( this.value == defaultValue ) {
		jQuery(this).val("");
		}
		});
		$("#hero-slider").show();
		$("#hero-slider").easySlider({
			auto: true,
			continuous: true,
			speed: 800,
			pause: 10000
		});
		/*$("#case-studies").easySlider({
			auto: true,
			continuous: true,
			speed: 800,
			pause: 16000
		});*/
		$('.feature-screenshots a').colorbox();
		var signupUrl = window.location.hash;
		if (signupUrl == "#signup") {
			$.fn.colorbox({inline:true,
			href:"#sign-up-modal",
			overlayClose:false,
			onOpen: function() {
				if(!opened) {
					opened = true;
					pageTracker = _gat._getTracker("UA-7309828-2");
					pageTracker._trackPageview("/signup-step-one");
				}
			}});
		}
		
		var page = window.location.hash;
		if (page == "signup"){
			$.colorbox({
			inline:true,
			href:"#sign-up-modal",
			overlayClose:false,
			onOpen: function() {
				if(!opened) {
					opened = true;
					pageTracker = _gat._getTracker("UA-7309828-2");
					pageTracker._trackPageview("/signup-step-one");
				}
			}});
		}
		
		$('.sign-up').colorbox({
			inline:true,
			href:"#sign-up-modal",
			overlayClose:false,
			onOpen: function() {
				if(!opened) {
					opened = true;
					pageTracker = _gat._getTracker("UA-7309828-2");
					pageTracker._trackPageview("/signup-step-one");
				}
			}});
		$('.demo-link').colorbox({
			inline:true,
			href:"#demo-modal",
			overlayClose:false,
			onOpen: function() {
				if(!opened) {
					opened = true;
					pageTracker = _gat._getTracker("UA-7309828-2");
					pageTracker._trackPageview("/demo-show");
				}
			}});
		$('ul#submenu ul').parent().addClass("parent-link");
		$('table tbody tr:odd').addClass('odd');
		$("#sign-up-form").validate({
			rules: {
				name: "required",
				company: "required",
				phone: "required",
				password: {
					required: true,
					minlength: 6
				},
				verify: {
					required: true,
					minlength: 6,
					equalTo: "#password"
				},
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				name: "Please enter your full name",
				companyname: "Please enter your company name",
				phone: "Please enter your contact phone number",
				password: {
					required: "Please provide a password",
					minlength: "Your password must be at least 6 characters long"
				},
				verify: {
					required: "Please provide a password",
					minlength: "Your password must be at least 6 characters long",
					equalTo: "Please enter the same password as above"
				},
				email: "Please enter a valid email address"
			}
		});
		$("#demo-form").validate({
			rules: {
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				email: "Please enter a valid email address"
			}
		});
		
		$('#cboxContent').parent().append('<div style="right: 0px; position: absolute;"><a id="close-popup" href=""><img style="width: 30px;" src="http://my.justrosters.com.au/img/qtip/close.png"></a></div>');
		$('#close-popup').click( function() {
			$.fn.colorbox.close();
			return false;
		});
		$('#sign-up-form input, #demo-form input').change(function() {
			var inputValid = $("#sign-up-form").validate().element(this);
  			if(!(inputValid)) {
  				$(this).parent().find('span').hide();
  				$('.sign-up').colorbox.resize();
  			}
		});
		$('#get-started').click(function(){
			if($("#sign-up-form").valid()) {
				$('#sign-up-modal').css({backgroundPosition: "270px bottom"}).animate(
					{backgroundPosition:"(9999px bottom)"}, 
					{duration:2500});
				$('.sign-up').colorbox.resize();
				var signupsrl = $("#sign-up-form").serialize();
				$('#step-one').hide();
				$('#sign-up-modal .loading').fadeIn();
				pageTracker._trackPageview("/signup-step-two");
				$.post("/proxy.php", signupsrl, function(data){
					$('#sign-up-modal .loading').hide();
					$('#sign-up-modal').html(data);
					$('.sign-up').colorbox.resize();
					$('#sign-up-modal').find('#get-into').click( function() {
						pageTracker._trackPageview("/signup-finish");
						return true;
					});
				});
			}
			else{
				$('#sign-up-form .field span, #sign-up-form .half-field span').hide();
				$('.sign-up').colorbox.resize();
			}
			return false;
		});
		$('#demo-started').click(function(){
			if($("#demo-form").valid()) {
				$('#demo-one').hide();
				$('#demo-modal .loading').fadeIn();
				var signupsrl = $("#demo-form").serialize();
				pageTracker._trackPageview("/demo-finish");
				$.post("/proxy.php", signupsrl);
				setTimeout(function(){demoSubmit()}, 2000);
			}
			else{
				$('.sign-up').colorbox.resize();
			}
				return false;
		});
		function demoSubmit(){
			$('#demo-modal .loading').hide();
			$('#demo-one').fadeIn();
			$('#demo-one').html('<h3>A link to the demo account has been sent to your email. Happy Rostering!</h3><a href="javascript: void(0)" class="close-modal">Close</a>')
			$('.sign-up').colorbox.resize();
			$('a.close-modal').click( function() {
				$.fn.colorbox.close()
				return false;
			});
		}
		
		//$("#testimonials").easySlider({
		//	auto: true,
		//	continuous: true 
		//});
		
		//Get the height of the first item
		//$('#feature-list').css({'height':$('#dashboard-link-panel').height()});	

		//Calculate the total width - sum of all sub-panels width
		//Width is generated according to the width of #mask * total of sub-panels
		$('#feature-details').width(parseInt($('#feature-mask').width() * $('#feature-details div').length));

		//Set the sub-panel width according to the #mask width (width of #mask and sub-panel must be same)
		//$('#feature-details div').width($('#feature-mask').width());

		//Get all the links with rel as panel
		$('a[rel=panel]').click(function () {

		//Get the height of the sub-panel
		//var panelheight = $($(this).attr('href')).height();

		//Set class for the selected item
		$('a[rel=panel]').removeClass('selected');
		$(this).addClass('selected');

		//Resize the height
		//$('#feature-mask').animate({'height':panelheight},{queue:false, duration:500});			

		//Scroll to the correct panel, the panel id is grabbed from the href attribute of the anchor
		$('#feature-mask').scrollTo($(this).attr('href'), 800);		
		
		//Discard the link default behavior
		return false;
		});
		
		
		$("#affilaite-signup-form").validate({
			rules: {
				firstname: "required",
				lastname: "required",
				companyname: "required",
				address1: "required",
				city: "required",
				state: "required",
				postcode: "required",
				phonenumber: "required",
				promotion: "required",
				terms: "required",
				password: {
					required: true,
					minlength: 6
				},
				password2: {
					required: true,
					minlength: 6,
					equalTo: "#password"
				},
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				name: "Please enter your first name",
				lastname: "Please enter your last name",
				company: "Please enter your company name",
				address1: "Please enter your address",
				city: "Please enter your city",
				state: "Please enter your state",
				postcode: "Please enter your postcode",
				phonenumber: "Please enter your contact phone number",
				promotion: "Please enter information on how you plan to promote JustRosters",
				terms: "Please agree to the terms and conditions before continuing",
				password: {
					required: "Please provide a password",
					minlength: "Your password must be at least 6 characters long"
				},
				password2: {
					required: "Please provide a password",
					minlength: "Your password must be at least 6 characters long",
					equalTo: "Please enter the same password as above"
				},
				email: "Please enter a valid email address"
			}
		});	
		$('#affiliate-submit').click(function(){
			var form = $("#affilaite-signup-form");
			if(form.valid()) {
				var signupsrl = form.serialize();
				if(pageTracker == null) {					
					pageTracker = _gat._getTracker("UA-7309828-2");
				}
				pageTracker._trackPageview("/affiliate-program/affiliate-signup/done");
				form.slideUp();
				$.post("/proxy.php", signupsrl, function(data){
					if(data.match(/error/i)) {
						form.find('.error-container').html(data).show();
						form.slideDown();
					} else {
						form.parent().append(data);
					}
				});
			}
			return false;
		});
	});