jQuery(document).ready(function($){
	$('#homefader').after('<div id="slidenav">').cycle({
        fx: 'fade',
        manualTrump: true,
        pause: true,
        pauseOnPagerHover: true,
        delay: 200,
        timeout: 8000,
        cleartype: 1,
        pager: '#slidenav',
        before: onBefore,
        after: onAfter
	});
    function onBefore() {

    };
    function onAfter() { 

    };
    //contact drop down
    $('.open').click(function(){
	     if ($('#contact_content').is(':hidden')){
	      	$('#contact_content').slideDown('slow');
	      	$('a.contact_btn').addClass('clicked');
	      	$("#homeshow").cycle('pause');
	      }
	     else{
	      	$('#contact_content').slideUp('slow');
	      	$('a.contact_btn').removeClass('clicked');
	      	$("homeshow").cycle('resume');
	      }
    });
//contact form
$("#contact_form").validate({
	errorClass: "invalid",
	errorElement: "em",
	errorPlacement: function(error, element) {
	error.appendTo( element.prev() );
	},
	invalidHandler: function(form, validator) {
	var errors = validator.numberOfInvalids();
	if (errors) {
$('#messagenotsent').show('fast');
} else {
$('#messagenotsent').hide('fast');
}
},
submitHandler: function(form) {
$(form).ajaxSubmit({
	url:	'http://amberhobbs.com/wp-content/themes/AHbase/send_message.php',
	success: function() {
		$('#messagenotsent').hide('fast');
		$('#messagesent').show('fast');
		$('#contact_form').clearForm();
		$("#contact_content").delay(600).slideUp("slow");	
		}
});
}
});
//end contact form

//services slide show
$("#services_slideshow").cycle({
	timeout: 0,
	speed: 'fast',
	cleartype:  1,
	fastOnEvent:   0,
	pagerEvent: 'click',
	pager:  '#services_nav',
	containerResize: 0, 
	startingSlide: 0,
    after: onAfter,
	pagerAnchorBuilder: function(idx, slide) {
	    return '#services_nav li:eq(' + (idx) + ') a';
	}
});
function onAfter(curr, next, opts, fwd) {
        var $ht = $(this).height();
        //set the container's height to that of the current slide
        $(this).parent().parent().animate({height: $ht});
    }
    
$('#e-link').click(function() { 
    $('#services_slideshow').cycle(6); 
    return false; 
}); 
//end services slide show

//interiors slide show
$("#projects-imgs").cycle({
    timeout: 0,
    speed: 'fast',
    cleartype:  1,
    fastOnEvent: 0,
    allowPagerClickBubble: 1,
    pagerEvent: 'mouseover',
    pager:  '#projects-ul',
    startingSlide: 0,
    pagerAnchorBuilder: function(idx, slide) {
        return '#projects-ul li:eq(' + (idx) + ') a';
    }
});
//end interiors slide show

//interiors press show
$("#press-photo").cycle({
    timeout: 0,
    speed: 'fast',
    cleartype:  1,
    fastOnEvent: 0,
    pagerEvent: 'click',
    pager:  '#press-nav',
    pagerAnchorBuilder: function(idx, slide) {
        return '#press-nav li:eq(' + (idx) + ') a';
    }
});
//end press slide show

//interiors press show
/*$("#project-thumbs").cycle({
    timeout: 0,
    speed: 'fast',
    cleartype:  true,
    fastOnEvent: 0,
    pagerEvent: 'mouseover',
    allowPagerClickBubble: 1,
    pager:  '#pj-links'
});*/
jQuery.fn.cycle.transitions.scrollHorz2 = function($cont, $slides, opts) {
    $cont.css('overflow','hidden').width();
//    $slides.show();
    opts.before.push(function(curr, next, opts, fwd) {
        jQuery(this).show();
        
        var currW = curr.offsetWidth, nextW = next.offsetWidth;
        //var nextW = curr.offsetWidth, currW = next.offsetWidth;
        
        console.log(currW);
        console.log(nextW);
        
        opts.cssBefore = fwd ? { left: nextW } : { left: -nextW };
        opts.animIn.left = 0;
        opts.animOut.left = fwd ? -currW : currW;
        $slides.not(curr).css(opts.cssBefore);
    });
    opts.cssFirst = { left: 0 };
    opts.cssAfter = { display: 'block' }
};
$.fn.cycle.transitions.custom = function($cont, $slides, opts) {
    var $el = $($slides[0]);
    //console.log($el);
    var w = $el.width();
    //console.log(w);
    opts.cssBefore = { left: w, display:'block' };
    opts.animIn    = { left: 0 };
    opts.animOut   = { left: -(w) };
    opts.cssAfter  = { };
};
$("#pj-show").cycle({
    timeout: 0,
    fx: 'fade',
    slideResize: 0,
    containerResize: 1,
    speed: 'normal',
    cleartype:  true,
    fastOnEvent: 0,
    pagerEvent: 'click',
    pager: '#project-thumbs',
	pagerAnchorBuilder: function(idx, slide) {
        return '#project-thumbs li:eq(' + (idx) + ') a';
	}
});
/*
$('.i-slideshow').each(function(index) {
	$(this).cycle({
	    timeout: 0,
	    speed: 'fast',
	    fastOnEvent: 0,
	    sync: false,
	    pagerEvent: 'click',
	    pager:  '#pj-links',
		pagerAnchorBuilder: function(i) {
			if (index == 0)
				// for first slideshow, return a new anchro
				return '<a href="#">'+(i+1)+'</a>';
				// for 2nd slideshow, select the anchor created previously
				return '#pj-links a:eq('+i+')';
	      	}
	});
});
*/
//end
$("#logo").hover(function(){
	$(this).stop().animate({backgroundPosition:'0px -230px'});
	}, 
	function(){
	$(this).stop().animate({backgroundPosition:'0px 0px'});
});
//$("#services_nav li").click( function(){
//	window.location=$(this).find("a").attr("href"); return false;
//});
/*
$("#services_nav li").hover(function(){
	$(this).animate({backgroundPosition:'0px 0px'}, 200);
	$(this).children('a').animate({
		top: '112px',
		opacity: 1
	}, 200);
	}, 
	function(){
	$(this).animate({backgroundPosition:'0px -146px'}, 200);
	$(this).children('a').animate({
		top: '55px',
		opacity: 1
	}, 200);
});
*/
//current year for copywrite
	var currentYear = (new Date).getFullYear();
	$('#cur_year').prepend( (new Date).getFullYear() );
});
