/* 

Community Restaurants Bootup Script
v. 1.0

last mod: 4-22-09
by: Mark


*/


/*################################################################################## BASE Functions */

/* open/close toggle for boxes */
function toggleListings(wrapper, boxelement, box, boxinner) {
	$(wrapper + " > " + boxelement + box + " > h3").append('<span class="toggle close"> Open</span>');
	
	$(wrapper + " > " + boxelement + box + " > div" + boxinner).slideUp("fast");
	/* open first item */
//	$(wrapper + " > " + boxelement + box + " > h3").eq(0).find("span").removeClass("close");
//	$(wrapper + " > " + boxelement + box + " > h3").eq(0).find("span").addClass("open");
//	$(wrapper + " > " + boxelement + box + " > h3").eq(0).find("span").html(" Close");
//	$(wrapper + " > " + boxelement + box + " > div" + boxinner).eq(0).slideDown("fast");
	
	$(wrapper + " > " + boxelement + box + " > h3").find("span").removeClass("close");
	$(wrapper + " > " + boxelement + box + " > h3").find("span").addClass("open");
	$(wrapper + " > " + boxelement + box + " > h3").find("span").html(" Close");
	$(wrapper + " > " + boxelement + box + " > div" + boxinner).slideDown("fast");
	
	
	$(wrapper + " > " + boxelement + box + " > h3").click(function() {
		if ($(this).find("span").hasClass("open")) {
			$(this).find("span").removeClass("open");
			$(this).find("span").addClass("close");
			$(this).find("span").html(" Open");
			$(this).parent().find("div" + boxinner).slideUp("fast");
		} else {
			$(this).find("span").removeClass("close");
			$(this).find("span").addClass("open");
			$(this).find("span").html(" Close");
			$(this).parent().find("div" + boxinner).slideDown("fast");
		}
	});
}

/* open/close toggling */
function openAll(wrapper, boxelement, box, boxinner) {
	/* open all items */
	$(wrapper + " > " + boxelement + box + " > h3").find("span").removeClass("close");
	$(wrapper + " > " + boxelement + box + " > h3").find("span").addClass("open");
	$(wrapper + " > " + boxelement + box + " > h3").find("span").html(" Close");
	$(wrapper + " > " + boxelement + box + " > div" + boxinner).slideDown("fast");
}

function closeAll(wrapper, boxelement, box, boxinner) {
	/* open all items */
	$(wrapper + " > " + boxelement + box + " > h3").find("span").removeClass("open");
	$(wrapper + " > " + boxelement + box + " > h3").find("span").addClass("close");
	$(wrapper + " > " + boxelement + box + " > h3").find("span").html(" Open");
	$(wrapper + " > " + boxelement + box + " > div" + boxinner).slideUp("fast");
}




$(document).ready(function() {

	if ($('#promo').length > 0) {
		$("#promo ul").innerfade({ speed: 'slow', timeout: 5000, type: 'sequence', containerheight: '130px' });
		//$("#graphics").innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '330px' });
	}
	
	if ($('#photos ul#photos-list li').length > 1) {
		$('#photos').addClass('slideshow');
		$('#photos').append('<div class="photos-nav"><p class="more-link"><a href="#" title="Next Photo">Next Photo</a></p><ul id="number-nav"></ul></div>');
		
		$('#photos ul#photos-list').cycle({ 
			fx: 'scrollRight',
			speed: 'fast',
			next:   '#photos p.more-link a', 
			timeout: 0,
			pager:  '#number-nav',
			pagerAnchorBuilder: function(idx, slide) {
				label = $('img',slide).parent().prevAll().length + 1;
				if (label < 10) { label = '0' + label; }
                return '<li><a href="#">' + label + '</a></li>';
			} 
		});
	}
	
	
	
	if ($('#restaurant-details').length > 0) {
		/* box toggling */
		toggleListings("#restaurant-details","div",".box",".box-inner");
		$("#restaurant-details").prepend("<p class=\"open-close-all\"><span class=\"close-all\"><a href=\"javascript:closeAll('#restaurant-details','div','.box','.box-inner');\">Close All</a></span> <span class=\"open-all\"><a href=\"javascript:openAll('#restaurant-details','div','.box','.box-inner');\">Open All</a></span></p><br class=\"clear\" />");
	}
	
	if ($('#jobListings').length > 0) {
		/* box toggling */
		toggleListings("#job-list","li",".job",".job-inner");
		$("#jobListings .sorting").prepend("<p class=\"open-close-all\"><span class=\"close-all\"><a href=\"javascript:closeAll('#job-list','li','.job','.job-inner');\">Close All</a></span> <span class=\"open-all\"><a href=\"javascript:openAll('#job-list','li','.job','.job-inner');\">Open All</a></span></p>");
	}
	
	if ($('.give-rating').length > 0) {
		$currentRating = 'stars-0';
		$('.give-rating').addClass('star-rating');
		$('.give-rating ul li label').click(function() {
			$('.give-rating ul').removeClass($currentRating);
			$forInput = $(this).attr('for');
			$rating = $(this).parent().find('input').attr('value');
			$currentRating = 'stars-' + $rating;
			$('.give-rating ul').addClass($currentRating);	
		});
		$('.give-rating ul li label').hover(function() {
			
		},function() {
			
		});
	}
	

	
},function(){
	GUnload();
});
