/* BON JOVI */
/* Javascript Triggers and Custom Functions
----------------------------------------------------------------------------- */


	$(window).load(function() {

		markup();
		cufon();
		tabs();
		banners();

		// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
		try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }

		$('#hide_page').show();
		
	});


/* FUNCTION: TABS
----------------------------------------------------------------------------- */


	function tabs() {

		// KILL TABS
		$('div.tabbed').each(function() {

			$panel = $(this);

			// REMOVE TABS IF CORRESPONDING PANES IS NIL
			$panel.find('ul.tabs li').each(function() {

				$tab = $(this);

				var paneID = $tab.children('a').attr('href');

				// JQUERY TAB
				if ( paneID.match('#') && $tab.parent().siblings(paneID).length == 0 ) {
	
					$tab.remove();
	
				}
				
			});

		});

		// INITIALIZE TABS
		$('div.tabbed').not('.static').tabs({

			fx: false,
			spinner: '', 

			show: function() {

				// REFRESH CUFON
				/* if (typeof(window['Cufon']) != "undefined") Cufon.refresh(); */

			}

		});

	}
	
	
/* FUNCTION: CUFON
----------------------------------------------------------------------------- */


	function cufon() {
	
		var garaline = [ 

			'h2', 
			'h3:not(div.widget-media.display h3, #customer h3)', 
			'div.group h4', 
			'div.display h4',
			'div.widget-editorial.highlights h4',
			'div.tabbed:not(.compact) a.tab',
			'#title ul.categories a',
			'a.action', 
			'th', 
			'div.widget-media.player a.comments',
			'div.retailers a', 
			'a#post-comment', 
			'a#post-meetup', 
			'a#post-review',
			'#messages div a:first-child',
			'#tools ul.stories li h4',
			'#page-mission div.modify.submit-media ul.actions li em',
			'div.flag h4',
			'div.widget-tag.browse ul.tags h4 a',
			'#featured-news ul.headlines li > a:not(.comments)',
			'#media a'
			
		];

		var din_condensed = [ 

			'td.date', 
			'div.widget-event.browse td.tickets ul li'
			
		];

		Cufon.replace(din_condensed, { fontFamily: 'DIN Condensed', hover: true });
		$(din_condensed.toString()).css('visibility', 'visible');

		Cufon.replace(garaline, { fontFamily: 'Garaline', hover: true });
		$(garaline.toString()).css('visibility', 'visible');
	
	}
	
	
/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */


	function markup() {
	
		// INTRODUCTION
		$('#introduction ul.actions a.browse').text('Go to the English site').attr('href', 'http://en.bonjovi.com/');
	
		$('div.widget-event.browse td.start span, div.widget-event.browse td.end span, div.widget-event.browse td.tickets ul li a').each(function() {
		
			var content = $(this).html().replace(/Pre-sale/, 'Fan Club Pre-sale').replace(/VIP/, 'Fan Club VIP');
			$(this).html(content);
		
		});
		
		if (plan != "backstage_jbj" && page == "vip") {
			$('td.tickets li.vip a').attr('href','/join');
		} else if (plan != "backstage_jbj") {
			$('td.tickets li.vip a').attr('href','/vip');
			$('div.display a.action.vip').attr('href','/vip');
		}
		
	}
	

/* FUNCTION: BANNERS
----------------------------------------------------------------------------- */

	
	function banners() {
	
		$.get('/feeds/banners', function(data) {

			// Load banners
			$(data).find('unit').each(function() {

				// Medium Rectangle House Ad (Tour Header)
				if ($(this).find('name').text() == "tour-header") {

					bannersFeed($(this), $('#tour-header-ad'));

				}

			});

			$('#tour-header-ad ul.banners').after('<div class="pager"><div>').cycle({

				fade: true,
				speed: 400,
				timeout: 9000,
				pager: 'div.pager div'

			});

			$('#tour-header-ad div.pager div').each(function() {

				$(this).css('float', 'left');
				$(this).css('width', $(this).width() + 'px');
				$(this).css('float', 'none');
				$(this).children('a:last-child').addClass('last');

			});

		});
	
	}