//General
jQuery(document).ready(function($){
    $.preloadCssImages();
    $(window).resize(function() {
        if (window.innerHeight < 560) {
            $('body').css("overflow","auto");
        } else {
            $('body').css("overflow","hidden");
        }
    });
});

//Card 1 button hover
jQuery(document).ready(function($){
    $('#card-content-3 a').hover(function(){
        $(this).addClass('button-hover');
    },function(){
        $(this).removeClass('button-hover');
    });
});

//Load Card 1 content using Ajax
jQuery(document).ready(function($){
    $('#card-content-3 a, a.ajaxlink').live("click",function() {
        $('#card-content-3 a').removeClass('button-click');
        $(this).addClass('button-click');
        $("#card-content-box-1").addClass("hide");
	var content_show = $(this).attr("title");
	var slug = content_show.toLowerCase().replace(/ /,'');
	if (slug == "/customwebsites") {
	    slug = "/";
	}
        $.ajax({
            method: "get",
            url: "/cms/wp-content/themes/coreymckrill/biz-content.php",
            data: "page="+content_show,
	    dataType: "html",
            beforeSend: function(){ $("#loading-1").show(); },
            complete: function(){ $("#loading-1").hide(); },
            error: function(html){
		$("#card-content-box-1").removeClass("hide");
                $("#card-content-box-1").html(html.responseText);
		if(typeof(pageTracker) != "undefined") {
		    pageTracker._trackPageview('/'+slug);
		}
                if (navigator.appName == "Microsoft Internet Explorer") {
                    $('.about-column, .testimonial, .portfolio-item, .contact-side').vAlign();
                }
	    },
	    success: function(html){
		$("#card-content-box-1").removeClass("hide");
                $("#card-content-box-1").html(html.responseText);
		if(typeof(pageTracker) != "undefined") {
		    pageTracker._trackPageview('/'+slug);
		}
                if (navigator.appName == "Microsoft Internet Explorer") {
                    $('.about-column, .testimonial, .portfolio-item, .contact-side').vAlign();
                }
            }
	});
        $(this).blur();
        return false;
    });
});

//Animation functions
jQuery(document).ready(function($){
    function slideLeft(element1,element2) {
        var a = $("#"+element1);
        var b = $("#"+element2);
        $(a).hide(
            "slide",
            { direction: "left", easing: "easeInOutBack" },
            1000, function() {
                $(a).addClass("hide");
            }
        );
        $(b).show(
            "slide",
            { direction: "right", easing: "easeInOutBack" },
            1000, function() {
                $(b).removeClass("hide");
            }
        );
    }
    function slideRight(element1,element2) {
        var a = $("#"+element1);
        var b = $("#"+element2);
        $(a).hide(
            "slide",
            { direction: "right", easing: "easeInOutBack" },
            900, function() {
                $(a).addClass("hide");
            }
        );
        $(b).show(
            "slide",
            { direction: "left", easing: "easeInOutBack" },
            900, function() {
                $(b).removeClass("hide");
            }
        );
    }
    function itemNumber(element) {
        var elementCount = $(element).size();
        var tN = new Array;
        tN[0] = $(element+':not(.hide)').attr('id');
        tN[0] = parseInt(tN[0].slice(-1));
        if (tN[0] == elementCount) {
            tN[1] = 1;
        } else {
            tN[1] = tN[0] + 1;
        }
        if (tN[0] == 1) {
            tN[2] = elementCount;
        } else {
            tN[2] = tN[0] - 1;
        }
        return tN;
    }
    $('.testimonial-nav-left a').live("click", function(){
        var a = itemNumber(".testimonial");
        slideRight("testimonial-"+a[0],"testimonial-"+a[2]);
        $(this).blur();
        return false;
    });
    $('.testimonial-nav-right a').live("click", function(){
        var a = itemNumber(".testimonial");
        slideLeft("testimonial-"+a[0],"testimonial-"+a[1]);
        $(this).blur();
        return false;
    });
    $('.portfolio-nav-left a').live("click", function(){
        var a = itemNumber(".portfolio-item");
        slideRight("portfolio-item-"+a[0],"portfolio-item-"+a[2]);
        $(this).blur();
        return false;
    });
    $('.portfolio-nav-right a').live("click", function(){
        var a = itemNumber(".portfolio-item");
        slideLeft("portfolio-item-"+a[0],"portfolio-item-"+a[1]);
        $(this).blur();
        return false;
    });
});

//Move to the next card
jQuery(document).ready(function($){
    var $paneTarget = $('body');
    $('#scroll-1').click(function(){
	var target = $('#container-2');
        $paneTarget.stop().scrollTo( target, 800, { easing:'easeInOutCirc' } );
	if(typeof(pageTracker) != "undefined") {
	    pageTracker._trackPageview('/aboutcorey');
	}
        return false;
    });
    $('#scroll-2').click(function(){
	var target = $('#container-1');
        $paneTarget.stop().scrollTo( target, 800, { easing:'easeInOutCirc' } );
	if(typeof(pageTracker) != "undefined") {
	    pageTracker._trackPageview('/');
	}
        return false;
    });
});

