$(function() {
    /**
     * Index contact form functionality.
     */
	$("a[rel^='ph']").prettyPhoto();
    $(".contact_btn_sld").click(function() {
        var sendername = $.trim($("input[name=sender_name]").val());
        var sendermail = $.trim($("input[name=sender_mail]").val());
        var sendermsg = $.trim($("textarea[name=sender_message]").val());
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if(sendername.length < 2 || sendername == 'Your name') {
            alert("Please, give us your real name.");
            $("input[name=sender_name]").css("border", "1px solid red").focus();
            return false;
        }

        if(sendermail.length < 10 || sendermail == 'Your e-mail') {
            alert("Please, provide a valid e-mail address");
            $("input[name=sender_mail]").css("border", "1px solid red").focus();
            return false;
        }

        if(reg.test(sendermail) == false) {
            alert("You entered invalid e-mail address.");
            $("input[name=sender_mail]").css("border", "1px solid red").focus();
            return false;
        }

        if(sendermsg.length < 10 || sendermsg == 'Your message') {
            alert("Please, give us at least 10 characters long descriptive text.");
            $("textarea[name=sender_message]").css("border", "1px solid red").focus();
            return false;
        }

        $.ajax({
            type: "POST",
            async: false,
            url: "form.php",
            data: {
                sn: sendername,
                sm: sendermail,
                smm: sendermsg
            },
            success: function(r) {
                $(".cf").empty().html('Your message has been successfully sent. ');
            },
            error: function() {
                alert("Could not initialize the Ajax request. Error.");
            }
        });
    });

    // End of index contact form

    /**
     * The default height of the slider element
     */
    $("#pr_title_img").attr("src", "tmdnew/img/pr_title_img_turtle.png");
    $("#flowpanes").css("height", "360px");
    $(".ttransfer").hide();
    $(".tstart").show();
    $(".tmdtransfer").removeClass("tmdst");
    $(".tmdstart").addClass("tmdst");
    $(".tmdstart").mouseover(function() {
       $(".ttransfer").hide();
       $(".tstart").show();
       $(".tmdtransfer").removeClass("tmdst");
       $(".tmdstart").addClass("tmdst");
       $("#pr_title_img").attr("src", "tmdnew/img/pr_title_img_turtle.png");
    });

    $(".tmdtransfer").mouseover(function() {
       $(".tstart").hide();
       $(".ttransfer").show();
       $(".tmdtransfer").addClass("tmdst");
       $(".tmdstart").removeClass("tmdst");
       $("#pr_title_img").attr("src", "tmdnew/img/pr_title_img.png");
    });

	$(".i1").click(function() {
		$("#flowpanes").css("height", "360px");
        location.href='#home';
    });

    $(".i2").click(function() {
    	$("#flowpanes").css("height", "550px");
        location.href='#home';
    });

    $(".i3").click(function() {
    	$("#flowpanes").css("height", "400px");
        location.href='#home';
    });

    $(".i4").click(function() {
        $("#flowpanes").css("height", "550px");
        location.href='#home';
    });

    $(".i5").click(function() {
        $("#flowpanes").css("height", "425px");
        location.href='#home';
    });

    $(".i6").click(function() {
        $("#flowpanes").css("height", "575px");
        location.href='#home';
    });

    $(".pointleft").click(function() {
       if($(".i1").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "575px");
           location.href='#home';
       }

       if($(".i2").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "360px");
           location.href='#home';
       }

       if($(".i3").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "550px");
           location.href='#home';
       }

       if($(".i4").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "400px");
           location.href='#home';
       }

       if($(".i5").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "550px");
           location.href='#home';
       }

       if($(".i6").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "420px");
           location.href='#home';
       }
    });

    $(".pointright").click(function() {
       if($(".i1").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "550px");
           location.href='#home';
       }

       if($(".i2").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "400px");
        location.href='#home';
       }

       if($(".i3").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "550px");
           location.href='#home';
       }

       if($(".i4").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "420px");
           location.href='#home';
       }

       if($(".i5").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "575px");
           location.href='#home';
       }

       if($(".i6").hasClass("curr_slide")) {
           $("#flowpanes").css("height", "360px");
           location.href='#home';
       }
    });

    $(".linktooltip").tipsy({offset: 4, gravity: 'sw'});

    // select #flowplanes and make it scrollable. use circular and navigator plugins
	var ctrls1 = $("#flowpanes").scrollable({size: 1, clickable: false}).circular();
	ctrls1.navigator({
		// select #flowtabs to be used as navigator
	    navi: "#flowtabs",
	    // select A tags inside the navigator to work as items (not direct children)
	    naviItem: 'a',	
	    // assign "current" class name for the active A tag inside navigator
	    activeClass: 'curr_slide'
	 });
	
	ctrls1.navigator({
		// select #flowtabs to be used as navigator
	    navi: "#dots",
	    // select A tags inside the navigator to work as items (not direct children)
	    naviItem: 'a.t',
	    // assign "current" class name for the active A tag inside navigator
	    activeClass: 'current_dot'
    });
	
	$(".schedule").click(function() {
		$(".sub_form").show();
	});
	
	$(".idiot_close").click(function() {
		$(".sub_form").hide();
	});
	
	$(".schedulesend").click(function() {
		var name = $("input[name=schedule_name]").val();
		var email = $("input[name=schedule_email]").val();
		var phone = $("input[name=schedule_phone]").val();
		var date = $("input[name=schedule_date]").val();
		var msg = $("textarea[name=schedule_message]").val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if(name == 'Your name' || name.length < 2) {
			alert("Please give us valid name in order to appoint a call with our experts.");
			$("input[name=schedule_name]").focus();
			return false;
		}
		
		if(email == 'Your e-mail' || reg.test(email) == false) {
			alert("Please enter a valid e-mail address.");
			$("input[name=schedule_email]").focus();
			return false;
		}
		
		if(date == 'Date' || date.length < 14) {
			alert("Please fill up a valid date in format YY/MM/dd HH:mm for your appointment.");
			$("input[name=schedule_date]").focus();
			return false;
		}
		
		$.ajax({
			type: "POST",
			async: false,
			url: "sform.php",
			data: {
				sched_name: name,
				sched_email: email,
				sched_date: date,
				sched_phone: phone,
				sched_msg: msg
			},
			success: function() {
				alert("Your appointment request was sent.");
				$(".sub_form").hide();
			}
		});
	});
});

