/* 
	Thrifty Foods - jQuery Site Enhancements
	September 2008
	Atomic Crayon / karen@atomiccrayon.com / SMRT
*/

$(document).ready(function(){

/* =BODY CLASSES
----------------------------------------------------*/
//$('body').addClass('jquery-extra');
		
/* =LISTINGS & TABLES
----------------------------------------------------*/

// make boxes clickable

$(".listing-platters li").addClass('click-box').click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
});

$("#recipe #tip").addClass('click-box').click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
});


/* =LIGHTBOX
----------------------------------------------------*/

$(".lightbox-gallery .photo-small .lightbox-image a").addClass('lightbox').attr({rel: 'gallery'});


/* =SLIDING PANELS
----------------------------------------------------*/

// login slider

$('#login-slide').html('<a href="">Open/Close</a>');

$("#login-slide").toggle(
	function(){
		$("#login").toggleClass("login-open");
		$("#login-panel").slideToggle("normal");
		return false;
	},
	function() {
		$("#login-panel").slideToggle("normal", function () {
			$("#login").toggleClass("login-open");
		});
		return false;
	}
);


// section navigation slider

/*
// set the top margin of the slider tab -- vertical center

var SectionHeight = $('#section-navigation-inside').height();

alert(SectionHeight);

var tabMargin = Math.floor((SectionHeight / 2) - 100);

$('#section-navigation-slide').css("margin-top", tabMargin);
*/

$('#section-navigation-slide').html('<a href="">Navigation</a>');

$("#section-navigation-slide").toggle(
	function(){
		$("#section-navigation").toggleClass("section-navigation-open");
		$("#section-navigation-inside").animate({
		 "width": "toggle"
		}, "normal");
		$(this).toggleClass("open");
		return false;
	},
	function() {
		$("#section-navigation-inside").animate({
		 "width": "toggle"
		}, "normal", function() {
			$("#section-navigation").toggleClass("section-navigation-open");
		}
		);
		$(this).toggleClass("open");
		return false;
	}
);


/* =FLYER SIDEBAR
----------------------------------------------------*/

// build control tabs from slider div
$('#sidebar #flyer #flyer-slides .slide').css({'display' : 'block'});


var flyers = $("#flyer-slides .slide").map(function (index) {
      var txt = $(this).text();
	 return ('<span class="flyer-tab">' + txt + '</span>');
    }).get().join("");

    
$('#flyer-tabs').append(flyers);

$('#slide-controls').html('<span class="flyerPrevious">Prev</span> <span class="flyerNext">Next</span>');


$("#flyer-tabs").jFlow({
		slides: "#flyer-slides",
		controller: ".flyer-tab", // must be class, use . sign
		slideWrapper: "#flyer-slide", // must be id, use # sign
		selectedWrapper: "flyer-selected",  // just pure text, no sign
		width: "198px",
		height: "252px",
		duration: 400,
		prev: ".flyerPrevious", // must be class, use . sign
		next: ".flyerNext" // must be class, use . sign
});

/* =COMMUNITY SIDEBAR
----------------------------------------------------*/

// sidebar accordion
// there's got to be a more effecient way of doing this

// first find the height of all the blurbs and set all blurbs to the same height (else IE6 goes wonky)
var blurbHeight = 0;
$("ul#community-accordion li p.blurb").map(function () {
		h = $(this).height() * 1;
		
		if (h > blurbHeight) {
			blurbHeight = h;
		}
});
$("ul#community-accordion li p.blurb").height(blurbHeight);


$("ul#community-accordion li").click(
		function () {
			$(this).addClass('community-selected');
			$("ul#community-accordion li p.blurb").hide()
			$("ul#community-accordion li.community-selected p.blurb").show()
			$(this).removeClass('community-selected');
		}
);

/* =TRANSPARENT PNGS
----------------------------------------------------*/

$('#flyer a img').ifixpng();


});
