$('html').addClass('js');

$(function() 
{	
	setInterval( "slideSwitch(1)", 5000 );
	setInterval( "slideSwitch(0)", 5000 );
	
	var currentImage = '';
	$('a').click(function(e) {
		if($(this).hasClass('reallink'))
		{
		
		}
		else
		{
		    e.preventDefault();
		}
    });
	//MENU BUTTONS
	$(".menulink").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).css("color", "#808080");
	}).mouseleave(function(event)
	{	
		$(this).css("color", "#FFFFFF");
	});
	
	//FOOTER BUTTONS
	$(".privacy, .contact, .about").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		if($(this).hasClass('mainabout'))
		{
			$(this).css("color", "#FFFFFF");
		}
		else
		{
			$(this).css("color", "#000000");
			$(this).parent('li').css("background-color", "#FFFFFF");
		}
		
	}).mouseleave(function(event)
	{	
		$(this).css("color", "");
		$(this).parent('li').css("background-color", "");
	});
	
	//SPLASH
	$("#investments").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).children('img').attr('src', 'images/investments-red-roll.png');
	}).mouseleave(function(event)
	{	
		$(this).children('img').attr('src', 'images/investments-red.png');
	});
	
	$("#finance").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).children('img').attr('src', 'images/finance-blue-roll.png');
	}).mouseleave(function(event)
	{	
		$(this).children('img').attr('src', 'images/finance-blue.png');
	});
	
	$("li a").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		var aImage = $(this).children('img').attr('src').split('.');
		currentImage = $(this).children('img').attr('src');
		var sImage = aImage[0] + '-roll.png';
		$(this).children('img').attr('src', sImage);
	}).mouseleave(function(event)
	{	
		$(this).children('img').attr('src', currentImage);
	});
	
	$("#investments").click(function(event)
	{
		$("#splash").fadeOut(250, function() {
			$("#div-investments .default").show();
			//$("#div-investments .submenu").show();
			$("#div-investments").fadeIn(250);
		});
	});
	
	$("#finance").click(function(event)
	{
		$("#splash").fadeOut(250, function() {
			$("#div-finance .default").show();
			$("#div-finance").fadeIn(250);
		});
	});

	//FOOTER BUTTONS
	$(".footerlink").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).css("color", "#808080");
	}).mouseleave(function(event)
	{	
		$(this).css("color", "#FFFFFF");
	});
	
	//BIND THE CLICK ON SUBNAV
	$('.sub_nav_wrap a').click(function(event){
		var aSelected = $(this).attr('href').split('_');
		$('.containerdiv').hide();
		$($(this).attr('href')).fadeIn(250);
	});	
	
	$("body").delegate('.back', 'click', function(event) {
		HidePanels();
		$("#splash").fadeIn(250);
	});
	
	$("body").delegate('.back', 'mouseenter', function(event) {
		$(this).css("cursor", "pointer");
	});
	
	$("body").delegate('.about', 'click', function(event) {
		HidePanels();
		$("#about .containerdiv").show();
		$("#about").fadeIn(250);
	});
	
	$("body").delegate('.privacy', 'click', function(event) {
		HidePanels();
		$("#privacy .containerdiv").show();
		$("#privacy").fadeIn(250);
	});
	
	$("body").delegate('.contact', 'click', function(event) {
		HidePanels();
		$("#contact .containerdiv").show();
		$("#contact").fadeIn(250);
	});
	
	$("body").delegate('.centertarget', 'mouseenter', function(event) {
		$(this).css("background-color", "#808080");
		$(this).css("cursor", "pointer");
	});
	$("body").delegate('.centertarget', 'mouseleave', function(event) {
		$(this).css("background-color", "");
	
	});
	
	$("body").delegate('.centertarget', 'click', function(event) {
		HidePanels();
		if($(this).hasClass('contactreventon'))
		{
			$("#feedback .containerdiv").show();
			$("#feedback").fadeIn(250);
		}
		else
		{
			$("#booknow .containerdiv").show();
			$("#booknow").fadeIn(250);
		}
		
	});
	
	$(".bodylink2").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).css("color", "#808080");
	}).mouseleave(function(event)
	{	
		$(this).css("color", "#000000");
	});
	
	$(".bodylinkstandard").mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
		$(this).css("color", "#808080");
		$(this).css("font-size", "16px");
	}).mouseleave(function(event)
	{	
		$(this).css("color", "#000000");
		$(this).css("font-size", "16px");
		
	});
	
	$("#contactrev").click(function(event)
	{
		var name = $(".contactform #contactname").val();
		var suburb = $(".contactform #contactsuburb").val();
		var email = $(".contactform #contactemail").val();
		var telephone = $(".contactform #contacttelephone").val();
		var message = $(".contactform #contactmessage").val();
			
		//VALIDATION CHECK
		if(name.length === 0 || suburb.length === 0 || email.length === 0 || telephone.length === 0)
		{
			alert('Please enter all of your details.');
		}
		else
		{
			var dataString = 'The following message has been sent to you:<br />Name: ' + name + '<br />Suburb: ' + suburb + '<br />Email: ' + email + '<br />Telephone: ' + telephone + '<br />Message: ' + message;
			$.ajax({
				type: "POST",
				url: "sendmailnew.php",
				data: {
				"email": email,
				"subject": "Expression of Interest Website",
				"message": dataString			
				},
				success: function() {
					alert('Thank you, your details have been sent through to Reventon Group.');
					HidePanels();
					$("#splash").fadeIn(250);
				}
			});
		}
	}).mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
	});
	
	$("#bookrev").click(function(event)
	{
		var city = $('input[name=CITY]:checked').val(); //VALUE AT THE SELECTED CITY
		var name = $("input#bookname").val();
		
		var suburb = $("input#booksuburb").val();
		var email = $("input#bookemail").val();
		var telephone = $("input#booktelephone").val();
		var mobile = $("input#bookmobile").val();
		var message = $("#bookmessage").val();
		var topics = 'This person is interested in the following topics:<br />'
		
		//QUICK CHECK FOR VALIDATION
		if(name.length === 0 || suburb.length === 0 || email.length === 0 || telephone.length === 0)
		{
			alert('Please enter all of your details');
		}
		else
		{
			//CHECK OPTIONS FOR TOPICS
			if ($("#tax").is(":checked"))
			{
				topics = topics + "Reducing Personal Tax<br />";
			}
			
			if ($("#mortgage").is(":checked"))
			{
				topics = topics + "Paying Off Your Mortgage In Half The Time<br />";
			}
			
			if ($("#retiring").is(":checked"))
			{
				topics = topics + "Retiring Early<br />";
			}
			
			if ($("#wealth").is(":checked"))
			{
				topics = topics + "Building Wealth Through Property Investment<br />";
			}
			
			if ($("#debt").is(":checked"))
			{
				topics = topics + "Debt Consolidation<br />";
			}
			
			
			var dataString = 'The following booking request has been sent to you:<br />Name: ' + name + '<br />Suburb: ' + suburb + '<br />Email: ' + email + '<br />Telephone: ' + telephone + '<br />Mobile: ' + mobile + '<br />Comments: ' + message + '<br />Requested City:' + city + '<br />' + topics;
			
			$.ajax({
				type: "POST",
				url: "sendmailnew.php",
				data: {
				"email": email,
				"subject": "Booking request from Website",
				"message": dataString			
				},
				success: function() {
					alert('Thank you, your booking request has been sent through to Reventon Group.');
					HidePanels();
					$("#splash").fadeIn(250);
				}
			});
		}
	}).mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
	});
	
	$("#sendfeedback").click(function(event)
	{
		var question1 = $('input[name=question1]:checked').val(); 
		var question2 = $('input[name=question2]:checked').val(); 
		var question3 = $('input[name=question3]:checked').val(); 
		var question4 = $('input[name=question4]:checked').val(); 
		var question5 = $('input[name=question5]:checked').val(); 
		var question6 = $('input[name=question6]:checked').val(); 
		var name = $("input#surveyname").val();
		var challenges = $("#surveychallenges").val();
		var comments = $("#surveymessage").val();
		var email = 'survey@reventon.com.au';
				
		//QUICK CHECK FOR VALIDATION
		if(typeof question1 == 'undefined' || typeof question2 == 'undefined' || typeof question3 == 'undefined' || typeof question4 == 'undefined' || typeof question5 == 'undefined' || typeof question6 == 'undefined' || name == '')
		{
			alert('Please make a choice on all questions and provide your name.');
		}
		else
		{
			var questionstring = '<br />How satisfied with in home consultant - ' + question1 +
								 '<br />How satisfied with finance consultation - ' + question2 +
								 '<br />How satisfied with property consultation - ' + question3 +
								 '<br />Rate the courtesy at office - ' + question4 +
								 '<br />Questions Answered Fully? - ' + question5 +
								 '<br />Informative nature of office visit - ' + question6 +
								 '<br />Challenges - ' + challenges +
								 '<br />Additional Comments - ' + comments;
			
			
			var dataString = 'The following feedback form has been sent to you:<br />Name: ' + name + '<br />Answers: ' + questionstring;
			
			$.ajax({
				type: "POST",
				url: "sendmailnew.php",
				data: {
				"email": email,
				"subject": "Feedback Survey from Website",
				"message": dataString			
				},
				success: function() {
					alert('Thank you, your feedback has been sent through to Reventon Group.');
					HidePanels();
					$("#splash").fadeIn(250);
				}
			});
		}
	}).mouseenter(function(event)
	{
		$(this).css("cursor", "pointer");
	});
});

function HidePanels()
{
	$("#div-finance, #div-investments, #splash, #about, #privacy, #contact, #booknow, #feedback").hide();
}

function slideSwitch(page) 
{
    var classname;
	if(page == '0')
	{
		classname = 'investment';
	}
	if(page == '1')
	{
		classname = 'finance';
	}
	var $active = $('.' + classname + 'slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('.' + classname + 'slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.' + classname + 'slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
