$(function() {

// Nav Hovers

	$('.navItemSm,.navItemLg').append('<span class="hover"></span>').each(function () {
	  
	  var $span = $('> span.hover', this).css('opacity', 0).html($(this).find('span').html());

	  $(this).hover(function () {
	    $span.stop().fadeTo(250, 1);
	  }, function () {
	    $span.stop().fadeTo(250, 0);
	  });
	});

	$('.navItemSm,.navItemLg').each(function(){
		if(location.pathname.indexOf($(this).attr('href')) > -1 ||($(this).attr('href') == '/tickets' && (location.pathname.indexOf('index.php') > -1 || location.pathname == '/' || location.pathname.indexOf('ticket') > -1))){
			$(this).css({backgroundPosition: '-182px 0'});
		}
	});
	
	if(parseInt($('#inner_content_wrap').css('paddingLeft')) > 0 || parseInt($('#inner_content_wrap').css('paddingRight')) > 0){
		$('#inner_content_wrap').css({width: (780 - (parseInt($('#inner_content_wrap').css('paddingLeft')) + parseInt($('#inner_content_wrap').css('paddingRight')))) + 'px'});
	}
	
	$('a').each(function(){
		if($(this).attr('href') && $(this).attr('href').indexOf('%0A') > -1){
			$(this).attr({href: $(this).attr('href').substr(0,$(this).attr('href').indexOf('%0A'))});
		}
		
		if($(this).attr('href') && $(this).attr('href').indexOf('http') < 0 && $(this).attr('href').indexOf('/') != 0){
			$(this).attr({href: '/' + $(this).attr('href')});
		}
		
		$(this).attr({rel: 'canonical'});
	});
	
	$('a').click(function(){
		if($(this).parent().hasClass('callout')){
			var pos = $('.callout a').index($(this)) + 1;
			trackEvent('dobpromo' + pos,'dob','a');
		}
		
		if($(this).hasClass('cityItem')){
			var pos = $('.cityItem').index($(this)) + 1;
			var city = $(this).attr('href').substr(8);
			trackEvent('dob/tour' + pos + '/' + city,'dob/tour' + pos,'a');
		}
		
		if($(this).children().hasClass('ticketsBtn')){
			trackEvent('dob/tix/click','dob/tix','a');
		}
		
		if($(this).parent().hasClass('internationalBtn')){
			var pos = $('.internationalBtn a').index($(this)) + 1;
			if($(this).text().indexOf(',') > -1){
				var city = $(this).text().substr(0,$(this).text().indexOf(','));
			} else {
				var city = $(this).text();
			}
			trackEvent('dob/intl' + pos + '/' + city,'dob/intl' + pos,'a');
		}
		
		if($(this).parent().parent().attr('id') == 'tickets_address'){
			trackEvent('dob/tix/maplink/','dob/tix','a');
		}
		
		if($(this).parent().attr('id') == 'tickets_map'){
			trackEvent('dob/tix/map','dob/tix','a');
		}
		
		if($(this).hasClass('teamTab')){
			trackEvent('dob/cast/' +  $(this).attr('id').substr(9),'dob/cast/' + $(this).attr('id').substr(9),'a');
		}
		
		if($(this).hasClass('ui-accordion-header')){
			var section = $(this).parent().parent().siblings('.faqTitle').text().replace(':','');
			var sec_div = $(this).parent().parent().parent();
			var pos = 1;
			for(i in sec_div.children('a')){
				if($(this) == sec_div.children('a').eq(i)){
					break;
				} else {
					pos++;
				}
			}
			
			trackEvent('dob/faq/' + section + pos + '/' + $(this).text(),'dob/faq/' + section + pos + '/','a');
		}
	});
	
	if(navigator.userAgent.indexOf('iPad') > -1){
		$('#footer').css({width: '1005px'});
		$('#top_nav').css({width: '1005px'});
	}
});

function trackEvent(lid,lpos,type){
	_gaq.push(['_trackEvent',lid,lpos]);
	
	/*
try{
		cto.linkId=lid;
		cto.linkPosition=lpos;
		cto.linkType=type;
		cto.trackLink();
		//clear link tracking variables
		cto.linkId="";
		cto.linkPosition="";
		cto.linkType="";
	}catch(e){}
*/
}

function clickCast(tab){
	if(!!$('a[href=team_tab_' + tab + ']')){
		$('a[href=team_tab_' + tab + ']').click();
	} else {
		setTimeout("clickCast('" + tab + "');",250);
	}
}
