/**
 * @Copyright CSSJockey
 * @Website: http://www.cssjockey.com
 * This message must stay intact, read more about terms of use here: http://www.cssjockey.com/terms-of-use
 * Do not change anything in this document unless you know what you are doing.
 */
$(document).ready(function(){
    // Wordpress Comments Check
    $("#commentform").submit(function(){
        var author = $("#author");
        var email = $("#email");
        var comment = $("#comment");
        var emailFormat = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
        if(author.val() == ""){
            alert("Name must be filled out!");author.focus();return false;
        }
        if (email.val() == "") {
            alert("Email must be filled out!");email.focus();return false;
        }
        if(email.val().search(emailFormat) == -1){
            alert("Please enter valid email address!");email.focus();return false;
        }
        if(comment.val() == ""){
            alert("Got nothing to say?");comment.focus();return false;
        }
    }) // End Function



// CONTACT FORM
$("#formloading").ajaxStart(function(){
    $(this).removeClass('hidden');
});
$("#contact").submit(function(){
    var fullname = $(this).find("#fullname");
    var emailid = $(this).find("#email");
    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 update = url.split("#")[1];
        $.ajax({
            type: "POST",
            url: "" + url + "",
            data: dataString,
            success: function(response){
                $('#' + update).html(response);
            }
        })
    }
    return false;
})




})
//#### Drop Down Menu ##################################
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close()
{  
    if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{  
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{
    if(closetimer)

    {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
    }

$(document).ready(function()
{
    $('#jsddm > li').bind('mouseover', jsddm_open)
    $('#jsddm > li').bind('mouseout',  jsddm_timer)
    });

document.onclick = jsddm_close;
$(document).ready(function(){
    $('#featuredrotation')
    .after('<div id="pages">')
    .cycle({
        fx: 'scrollLeft',
        speed:   300,
        timeout: 5000,
        pager:  '#pages'
    });
});

$(document).ready(function(){
    $('#footerposts ul')
    .cycle({
        fx: 'fade'
    });
});
jQuery( document ).ready( function ( $ ) {
	// Add first and last menu item classes
	$('#navleft ul li:last-child').addClass( 'noborder' );
});

