// Functions specific to a site.
(function($) {
	$(document).ready(function() {
		// Place document manipulation code here
		var bgImageSource, bgImageFinal;
		$('#subnav li a').each(function() {
			bgImageSource = $(this).css('background-image');
			if(bgImageSource != 'none')
				bgImageFinal = bgImageSource.replace(/"/g,"").replace(/url\(|\)$/ig, ""); 
			else
				bgImageFinal = '/images/sub-nav_hover.png';
			$(this).css({'background-image':'none'});
			var paddingLeft = parseInt($(this).css('padding-left'));
			var paddingRight = parseInt($(this).css('padding-right'));
			var width = parseInt($(this).width());
			$(this).parent().prepend('<img class="bg-stretch" src="' + bgImageFinal +  '" style="height: ' + $(this).parent().height() + 'px; width: ' + parseInt(paddingLeft + paddingRight + width) + 'px; position: absolute; z-index: 1;" />');

			if(bgImageSource == 'none')
				$(this).parent().find('img').hide();
				
			$(this).parent().find('a').each(function() {
				$(this).css({'z-index':'5', 'position':'relative'});
			});
		});

		$('#subnav li a:not([class*=active])').hover(function() {
			$(this).find('img').show();
		},
		function() {
			$(this).find('img').hide();
		});
	}); 
})(jQuery);

$('#cycle-container')
.before('<div id="cycle-button"><ul>') 
.cycle({ 
    fx:     'fade', 
    speed:  '800', 
    timeout: 4000, 
    pager:  '#cycle-button ul',
	pagerAnchorBuilder: function(idx, slide) {
		var anchor = '';
		anchor = '<li><a href="#" id="btn-cycle-' + (idx + 1) + '">' + (idx + 1) + '</a></li>';
		return anchor;
	}
});

