/**
 * site.js
 *
 * Breasclete Community Association
 *
 * Site-wide Javascript
 */
jQuery.noConflict();
jQuery(document).ready(function($) {
	// app-wide confirmable
	$('.confirm').click(function() {
		var label = $(this).attr('title');
		var choice = confirm(label);

		if(choice) {
			return true;
		} else {
			return false;
		}
	});

	// open all rel=external links in a new window
	$('a[rel=external]').click(function() {
		window.open($(this).attr('href'));
		return false;
	});

	// input box placeholder text
	if (Modernizr.input.placeholder) {
		// browser supports placeholder - do nothing
	} else {
		// implement a placeholder-like functionality
		jQuery.each(jQuery('input'), function(i, el) {
			var $$ = $(el);
			$$.val($$.attr('placeholder'));
			$$.focus(function() {
				$(this).val('');
			});

			$$.blur(function() {
				if($(this).val()) {
					// has value, do nothing
				} else {
					$(this).val($(this).attr('placeholder'));
				}
			});
		});
	}

	//$("a[rel='lightbox']").colorbox({transition:"none", width:"75%", height:"75%"});
	$(".scrollable").scrollable({circular: true});

	/**
	 * inside accodian menus
	 */
	$('.rn-menu-inside li ul.children').hide();
	$('.rn-menu-inside li.current_page_item ul.children, .rn-menu-inside li.current_page_parent ul.children').show();

	$('.rn-menu-inside li a').click(function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return false;
		}

		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('.rn-menu-inside li ul:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
		}
	});

});

// fairly nasty but effective browser sniffing
(function($) {
	var userAgent = navigator.userAgent.toLowerCase();
	$.browser = {
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
		safari: /webkit/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
	};
})(jQuery);

// image preload plugin
(function($) {
	var cache = [];

	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;

		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)

// add additional "corner" elements to a container for rounded corners
jQuery.fn.rounded = function(radius, border_width, style, top, bottom, offset_t, offset_r, offset_b, offset_l) {
	if($.browser.msie) {
		if(top) {
			$(this).prepend('<div class="tl"></div><div class="tr"></div>');
		}

		if(bottom) {
			$(this).append('<div class="bl"></div><div class="br"></div>');
		}

		$(this).css({
			'position'	: 'relative'
		});

		$(this).children('.tl, .tr, .bl, .br').css({
			'width': radius + 'px',
			'height': radius + 'px',
			'position': 'absolute'
		});

		$(this).children('.tl').css({
			'background': 'transparent url(' + style + 'tl.png) top left no-repeat',
			'top': offset_t + 'px',
			'left': offset_l + 'px'
		});

		$(this).children('.tr').css({
			'background': 'transparent url(' + style + 'tr.png) top left no-repeat',
			'top': offset_t + 'px',
			'right': offset_r + 'px'
		});

		$(this).children('.bl').css({
			'background': 'transparent url(' + style + 'bl.png) top left no-repeat',
			'bottom': offset_b + 'px',
			'left': offset_l + 'px'
		});

		$(this).children('.br').css({
			'background': 'transparent url(' + style + 'br.png) top left no-repeat',
			'bottom': offset_b + 'px',
			'right': offset_r + 'px'
		});
	}
};

