/* Author: Brad Kaloupek

*/
function onAfter(curr,next,opts, fwd) {
	var caption =  (opts.currSlide + 1) + '/' + opts.slideCount;
    $('#caption').html(caption);
    //get the height of the current slide
   //var $ht = $(this).height();
   //set the container's height to that of the current slide
   //$(this).parent().animate({height: $ht});
} 

toggleNav = function (){
		if ($('li.parentnav').hasClass('open')) {
	   	 $('li.parentnav ul').hide(600);
	   	 $('li.parentnav.open ul').show(600);
	    }
	};

initNav = function(){
		$('.current-page-parent').addClass('open');
		$('li.parentnav ul').hide();
		$('li.parentnav.open ul').show(600);
};

//$(function() {
$(document).ready(function() {
	$('#images ul li img').attr('height', '340');

	//image rotation 


	$('#images ul').cycle({
		fx:     'fade', 
	    speed:  'fast', 
	    timeout: 0, 
	    next:   '#next', 
	    prev:   '#prev',
		after: onAfter
	});
 	//simple rotation for homepage
 	$('#images-simple-rotation ul').cycle({
		fx:     'fade', 
	    speed:  'fast', 
	    speed:  3500 
	});

	//Add Hover states to nav
	$('nav ul li a, .work-nav ul li a').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');	
	});

	//nav structure
	//add class for identifying nesting
	$('nav#nav-main ul.menu li ul.sub-menu').parent().addClass('parentnav');

	//$('li.parentnav ul li a').click(function(){
	//	return true;
	//});

	$('li.parentnav').live("click", function(event){
		event.preventDefault();
		if ($(this).hasClass('open')) {
			//return false;
		} else{
		    $('li.parentnav').removeClass('open');
		    $(this).addClass('open');
		    toggleNav();
		    //return false;
		}
	});
	//return child links href
	$('li.parentnav ul li a').live("click", function(event){
		var clickedURL = $(this).attr('href');
		window.location = clickedURL;
	});

	initNav();

 	

	//prettyphoto
	$("a[rel^='prettyPhoto']").prettyPhoto();
});
