//////////////////////////////////////////
// All Custom jQuery by FireScript.ca ////
// Author: Firescript                 ////
// Website: http://www.firescript.ca  ////
// Client: GIPSC Payment Solutions    ////
//////////////////////////////////////////

$(document).ready(function (){

    var tabnum = 0; // Slider Counter
    var slidenav = $('.slide-nav'); // Slider Controls
    var slider = $('div.slider'); // Slider Content
    var timer; // Slider Timer
	var openClose = 0; // Login Counter
	var	name = $("#name").val();
	var	email = $("#e-mail").val();
	var	comments = $("#comments").val();
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var hasError = false;
	
	$("#name-req").hide();
	$("#email-req").hide();
	
 	$(".navigation li.active a").css("color", "#2F98C5");
 	
	// Logo Click Pixel Shift
	$(".logo").mousedown(function (){
		$(this).css("margin", "-1px 0 0 0");
		$(this).css("padding", "0 0 1px 0");
	});
	
	// Main Button Hover Pixel Shift
	$(".main-button").hover(function (){
		$(this).css("top", "-37px");
	}, function (){
		$(this).css("top", "-36px");
	});
	
	//Contact Form Submit
	
	$("button#submit").click(function(){
		
	var	name = $("#name").val();
	var	email = $("#e-mail").val();
	var	comments = $("#comments").val();
		
		$(".error-box").html("");
		if(name == ""){
			$(".error-box").append('Enter your name.');
			$("#name-req").fadeIn(200);
			$("#name").css("borderColor", " red");
			hasError = true;
		}
		
        if(email == '') {
           $(".error-box").append(' Enter an actual email address.');
            hasError = true;
			$("#email-req").fadeIn(200);
			$("#e-mail").css("borderColor", " red");
        }
		
        else if(!emailReg.test(email)) {
            $(".error-box").append(' Enter a valid email address.');
			$("#email-req").fadeIn(200);
			$("#e-mail").css("borderColor", " red");
            hasError = true;
        }
		
		if(comments == ""){
			$(".error-box").append(' Enter a comment please.');
			hasError = true;
		} 
		
		if(hasError == true) {

		$(".error-box").fadeIn(200).delay(1500).fadeOut(200); 
		return false; 
		
		}
			
	});
	
	// Login Slide Drop Down Panel	
	$(".login").click(function () {	
		if(openClose === 0){
			$("#top-bar-thin").animate({
			height: "150px",
			}, 500 );	
			$(".login-content").delay(500).fadeIn(250);
			openClose = 1;
			$(".login").html("Close &nbsp; X").css("background-color","#167ca7");
		}else if(openClose === 1){
			$(".login-content").slideUp(500);
			$("#top-bar-thin").animate({
			height: "3px",
			}, 500 );
			openClose = 0;
			$(".login").html("Login  &nbsp; ^").css("background-color","#2591bf");
		}	
	});

	// Login text box default value clear on focus
	 $(".login-textbox").focus(function () {
			$(this).val("");
	 });

    // start autoplay
    startTimer();
	
    // functions are below ////////////////////
	
    slidenav.click(function() {
        var activeTab = $(this).attr('rel');
		clearInterval(timer); //stop autoplay
        tabnum = slidenav.index(this);
        slider.children('div').fadeOut(300);
        slider.find("." + activeTab).delay(300).fadeIn(300);
        startTimer(); //again start autoplay
    });

    /////////
   	hover();
	/////////
	
    function hover() {
        slider.hover(function() { //on hovering
			$(".pause").fadeIn(300);
            clearInterval(timer); //stop autoplay
        }, function() { //on releasing
            $(".pause").fadeOut(300);
			resumeTimer()
        });
    }
    
    /////////

    function resumeTimer() {
        timer = setInterval(function() {
            if (tabnum == slidenav.length) {
                tabnum = 0;
            }
            slidenav.eq(tabnum).click();
        }, 5000);
    }

    /////////

    function startTimer() {
        tabnum++;
        timer = setInterval(function() {
            if (tabnum == slidenav.length) {
                tabnum = 0;
            }
            slidenav.eq(tabnum).click(); //click the current tab
        }, 5000);
    }

    // functions end here ///////////////////
	
	
});

