
jQuery(document).ready(function($) {
	
	simpleCart.email = "sc@sherylchapman.com";
	simpleCart.cartHeaders = ["Name", "Quantity", "Size", "Total" ];

	if( $('.simpleCart_finalTotal').text() != '$0.00' ) {
		$('.cart').show();
		$('.cart').stop().animate({ 'top': -($('.cart').height()-34) });
	} else {
		$('.cart').hide();
	};

	$("a.fancybox").fancybox();

	if( $('.porfolio-main').length > 0 ) {
		loadPorfolio()
		$('.porfolio-buttons').live('click', function() {
			$('.porfolio-main div').fadeOut(200);
			footerPos = $('.footer').position();
			loadPorfolio( $(this).attr('paged') )
		});
	}
	
	$('.cart').css({ top: -($('.cart').height()-34) });

	$('.item_add').live('click', function() {
		simpleCart.add( 'name='+$('.item_name').text(), 'price='+$('.item_price').text(), 'size='+$('.item_size').val() );
		$('.cart').animate({ top: 0 });
		if( !$('.cart').is(':visible') ) {
			$('.cart').fadeIn(400);
		}
	});

	$('.cart').hover(
		function () {
			$(this).stop().animate({ 'top': 0 });
			$(this).addClass('cart-active');
		},
		function () {
			$('.cart').stop().animate({ top: -($(this).height()-34) });
			$(this).removeClass('cart-active');
		}
	);

	$('.content').mouseover(function() {
		if( $('.cart').is(':visible') ) {
			$('.cart').stop().animate({ top: -($('.cart').height()-34) });
		}
		if( $('.show-cart').is(':visible') ) {
			$('.show-cart').stop().animate({ top: -($('.show-cart').height()-34) });
		}
	});

	$('.item_size').live('change', function() {
		if( $(this).val() == 'S' ) {
			$('.item_price').text('$100');
		} else if( $(this).val() == 'M' ) {
			$('.item_price').text('$200');
		} else if( $(this).val() == 'L' ) {
			$('.item_price').text('$300');
		} else if( $(this).val() == 'XL' ) {
			$('.item_price').text('$400');
		}

	});

	$('.content-nav-buttons').click(function () {
		$('.content-nav-title').removeClass('content-nav-active');
		$(this).parent().addClass('content-nav-active');
		postData = '';
		postData = 'child_of='+$(this).attr('child-of');
		postData += '&id='+$(this).attr('id');

//		$('.debug').show();
//		$('.debug').text( 'postData: '+postData )
		
		
		$('.client-list').fadeOut(200, function() {
			$.post("/wp-content/themes/sherylchapman-v4/jquery-loads/client-list.php", postData, function(content) {
				$('.client-list').html(content);
				$('.client-list').fadeIn(200);
			});
		});
	});


});

function loadPorfolio(paged) {
	$('.loading').fadeIn(100);
	$('body').addClass('hide-overflow');
	postData = 'title='+$('.porfolio-main').attr('title');
	postData += '&post_ID='+$('.porfolio-main').attr('post_ID');
	if(paged) {
		postData += '&paged='+paged;
	}
	
	$.post("/wp-content/themes/sherylchapman-v4/jquery-loads/portfolio.php", postData, function(content) {
		$('.porfolio-main').html(content);
		$('.porfolio-img img').hide();

		$('.porfolio-buy').hide();
		$('.porfolio-img img').load(function() {
				$('.porfolio-img img').fadeIn(400, function() {
					$('.loading').fadeOut(100, function() {
						$('.porfolio-main').fadeIn(200, function() {
							if( $('.porfolio-buy').length > 0 ) {
								$('.porfolio-buy').css({ top: -($('.porfolio-buy').height()-34) });
								$('.porfolio-buy').fadeIn(200);
							}
							$('body').removeClass('hide-overflow');
						});
					});
				});
		});
	});


};
