/**
 * @Copyright MattsMedia.com
 * @Website: http://www.MattsMedia.com
 * @Terms of Use: http://www.MattsMedia.com
 * If you change the contents below bad things will happen!
 */
$(document).ready(function(){
	
	$('a, .ttip, abbr, .entry img').tooltip({ 
	   track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " # ", 
		fade: 250 
	});

//Homepage portfolio cycle plugin
	$('#homeportfolio') 
	.before('<div id="pnav">') 
	.cycle({ 
	    fx:     'fade', 
	    speed:  500, 
	    timeout: 3000, 
	    pager:  '#pnav' 
	});
	$("#pnav a").html('&nbsp;');

$(".cjgallery").cycle({ 
    fx:     'fade', 
    speed:  '500', 
    timeout: 0, 
    next:   'a.gnext', 
    prev:   'a.gprev' 
});

// Survey Questions
$('.survey').cycle({ 
    fx:     'fade', 
    speed:  '1000', 
    timeout: 0, 
    next:   'a#snext', 
    prev:   'a#sprev' 
});
	


$("#testimonials").cycle({
    fx: 'fade',
    speed: 200,
    timeout: 10000,
    next:   '#tnext', 
    prev:   '#tprev' 
		
})

$("#testimonials_home").cycle({
    fx: 'fade',
    speed: 200,
    timeout: 10000,
    next:   '#tnext', 
    prev:   '#tprev' 
		
})

// CONTACT FORM
$("#formloading").ajaxStart(function(){
	$(this).removeClass('hidden');
});
$("#contact").hide();
$("#contact").submit(function(){
    var fullname = $(this).find("#fullname");
    var emailid = $(this).find("#emailid");
    var message = $(this).find("#message");
    var spam = $(this).find("#spam");
    var emailFormat = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    $("span.formerror").addClass('hidden');
    
    if (fullname.val() == "") {
        fullname.parent().find('span.formerror').html("This field is required.").removeClass('hidden');
        fullname.focus();
        return false;
    }
    else 
        if (emailid.val() == "") {
            emailid.parent().find('span.formerror').html("This field is required.").removeClass('hidden');
            emailid.focus();
            return false;
        }
        else 
            if (emailid.val().search(emailFormat) == -1) {
                emailid.parent().find('span.formerror').html("Not a valid email address.").removeClass('hidden');
                emailid.focus();
                return false;
            }
            else 
                if (spam.val() != '12') {
                    spam.parent().find('span.formerror').html("Incorrect Answer!!").removeClass('hidden');
                    spam.focus();
                    return false;
                }
                else 
                    if (message.val() == '') {
                        message.parent().find('span.formerror').html("Got nothing to say?").removeClass('hidden');
                        message.focus();
                        return false;
                    }
                    else {
                    
                        var url = $(this).attr('action');
                        var dataString = $('.aform').serialize();
                        var updatecontainer = url.split("#")[1];
                        newurl = url.split("#")[0];
                        newurl = newurl + "?random=" + Math.random() + "#" + updatecontainer;
                        var update = url.split("#")[1];
                        var update = update.split("&")[0];
                        $.ajax({
                            type: "POST",
                            url: "" + newurl + "",
                            data: dataString,
                            success: function(response){
                                $('#' + update).html(response);
                            }
                        })
                    }
    return false;
})

$("#survey").submit(function(){
    var url = $(this).attr('action');
    var dataString = $('.aform').serialize();
    var updatecontainer = url.split("#")[1];
    newurl = url.split("#")[0];
    newurl = newurl + "?random=" + Math.random() + "#" + updatecontainer;
    var update = url.split("#")[1];
    var update = update.split("&")[0];
    $.ajax({
        type: "POST",
        url: "" + newurl + "",
        data: dataString,
        success: function(response){
            $('#' + update).html(response);
        }
    })
    return false;
})

// Live Chat
$("#livechat").click(function(){
	$("#lightbox").fadeIn(500);
	$("#livechatwindow").fadeIn(300);
	return false;
})

$("#closelightbox").click(function(){
	$("#lightbox").fadeOut(500);
	$("#livechatwindow").fadeOut(300);
	return false;
})


})
$(window).ready(function(){
	$("#loading").fadeOut(500);
	$("#contact").show();
})
DD_roundies.addRule('.round', 10, true);
