// Title: Toffee Apple Tummies - javascript
// Author: Kalon Edser, http://www.kalonedser.com/
// Updated: 2 September 2010

jQuery(document).ready(function() {
	
	$('body').addClass('js');

	// fix png images with alpha channels
	$.ifixpng('../img/pixel.gif');
	$('.png').ifixpng();
	
	// scroll effect
	$.localScroll({
		target: '#inner-content',
		margin: true
	});
	$.localScroll.hash({
		target: '#inner-content',
		margin: true
	});

	// remove active class from active subcategory parent
	$('ul#nav-products li.active').parents('li.active').removeClass('active').addClass('expand');

	// add active class to products category
	if($('.index a').length > 0) {
		var $thiscat = $('.index a').attr('href');
		var $thiscat = $.url.setUrl($thiscat).param("c");
		$("#cat-" + $thiscat).addClass('active').parents('#nav-products-cat li').addClass('expand');
	}
	
	// mini-cart notices
	if($('.cart-msg').length > 0) {
		$('.cart-qty').hide();
		$('.cart-msg').hide().fadeIn();
		$('.cart-msg').animate({ opacity: 1}, 3000, function() {
			$(this).fadeOut(function(){
				$('.cart-qty').fadeIn();
			});
		});
	}
	
	var $paypal = 'Purchase via PayPal';
	
	// sort payment options
	$('#payment').sortOptions(false).selectOptions($paypal);

	// show extra checkout fields when not using PayPal
	$('.yab-shop-text').hide();
	
	$('select#payment').change(function(){
		switch ($(this).val()){
			case $paypal:
				$(".yab-shop-text").hide();
			break;
			default:
				$(".yab-shop-text").show();
		}
	});
	
	// toggle message
	$('a[rel^="message"]').toggle(
		function () { // toggle show
			$('#message-box').show("slide", {direction: 'up'}, 'normal', function() {
				$('#inner-content').scrollTo( '#message-box', 800, {margin:true} );
			});
		},
		function () { // toggle hide
			$('#message-box').hide("slide", {direction: 'up'}, 'normal');
		}
	);

	// photo viewer
	$("a[rel^='photo-viewer']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: .35, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
	});

	// open new window for external links
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

});