var host = location.host;

Cufon.set('fontFamily', 'theserifboldcaps');

Cufon.replace('.main_nav a');
Cufon.replace('.sub_nav a', {textShadow: '#b7751d 1px 1px'});
Cufon.replace('.sub_nav h2, .sub_nav li.active a, .sub_nav li.current_page_item a, .sub_nav li.current a, .schedule .schedule_nav', {textShadow: '#092a12 1px 1px'});
Cufon.replace('#member-links li a, #sort-links li a, #sort-links li span', {
	hover: true
});
Cufon.replace('.no-member_links a');
Cufon.replace('.schedule_nav a');
Cufon.replace('#photo-box .photo-header h3', {textShadow: '#646a6c 1px 1px'});
Cufon.replace('.additional_wrapper .additional_header h3', {textShadow: '#646a6c 1px 1px'}); // duplicate so that a cufon.refresh() works on just this element
Cufon.replace('.latest_videos .video_thumbs h3');
Cufon.replace('.twitter_wrapper h3');
Cufon.replace('.twitter_wrapper p.section');
Cufon.replace('.twitter_wrapper .social_media #copy');
Cufon.replace('h1.sign_in_title');
Cufon.replace('.newest_fans h3');
Cufon.replace('.account_nav li');
Cufon.replace('.profile_header li');
Cufon.replace('.tier2_header li');
Cufon.replace('.tier2_header li a');
Cufon.replace('div.item-list-tabs#subnav ul li a');
Cufon.replace('#sidebar-me .sidebar-head a');
Cufon.replace('.one_title_wrapper .one_title_header li');
Cufon.replace('.postbox h3'); 

Cufon.replace('.deal .who', {fontFamily : 'TheSerifSemiBold'});
Cufon.replace('.deal .date', {fontFamily : 'TheSerifSemiBold'});
Cufon.replace('.deal .price', {fontFamily : 'TheSerifCaps', textShadow: '#000000 2px 2px 2px'});

Cufon.replace('#nba-bar ul li a', {fontFamily: 'Arial Narrow', fontWeight: 'bold', hover: true});

jQuery.noConflict();

(function($){$(function(){
	
	var addThisButtonPhoto = function(id) {
		addthis.button(id, {}, {
			url: BLOGINFO_URL + '/view/',
			title: 'Utah Jazz Verizon fan photo contest',
			description: 'Utah Jazz fans, show your pride by uploading photos of yourself in Jazz gear, at the games and anything else that shows your spirit. By doing so, you could win two Jazz tickets, a Jazz Jersey of your favorite player and a special gift pack from Verizon Wireless. A winner will be selected every month. http://www.utahjazz360.com/view/',
			templates: {
				twitter: 'Share your favorite Utah Jazz photos! Weekly winner will receive two tickets, a jersey and a Verizon gift pack. http://bit.ly/fDre8x #uj360 '
			}
		});
	}
	
	/**
	 * homepage tabs
	 */
	$('.jazz_fans .blog_header ul li a').click(function() {
		
		$('.jazz_fans .blog_header ul li').removeClass('active').removeClass('activelast');
		
		var parent = $(this).parent(),
			ajaxcall = parent.attr('class');
			
		var cleanAjaxCall = ajaxcall.replace(' last', '');
			
		window.location.hash = cleanAjaxCall;
		
		parent.addClass('active');
		
		if (parent.hasClass('last')) {
			parent.addClass('activelast');
		}
		
		Cufon.refresh('.sub_nav a', {textShadow: '#b7751d 1px 1px'});
		Cufon.refresh('.sub_nav h2, .sub_nav li.active a, .sub_nav li.current_page_item a, .sub_nav li.current a', {textShadow: '#092a12 1px 1px'});
		
		$('#jazz-fans-content').html('<div class="jazz-fans-loading"><img src="' + STYLESHEET_DIRECTORY + '/images/activity indicator.gif" /></div>');
		
		$.post(BLOGINFO_URL + '/ajax.php', {'call': cleanAjaxCall}, function(data) {
			$('#jazz-fans-content').html(data);
			
			if (cleanAjaxCall == 'fans_nav_photos') {
				addThisButtonPhoto('#photo-share-button');
			}
			
			Cufon.refresh('.additional_wrapper .additional_header h3');
		});
		
		return false;
	});
	
	if (window.location.hash) {
		$('.jazz_fans .blog_header ul li.'+window.location.hash.replace('#', '')+' a').trigger('click');
	}
	
	// tabs at the bottom of homepage
	$('.latest_videos_header ul li a').click(function() {
		$('.latest_videos_header ul li').removeClass('active').removeClass('activelast');
		$(this).closest('li').addClass('active');
		var parent = $(this).parent(),
			ajaxcall = parent.attr('class');
					
		if (parent.hasClass('last')) {
			parent.addClass('activelast');
		}
		Cufon.refresh('.sub_nav a', {textShadow: '#b7751d 1px 1px'});
		Cufon.refresh('.sub_nav h2, .sub_nav li.active a, .sub_nav li.current_page_item a, .sub_nav li.current a', {textShadow: '#092a12 1px 1px'});
		
		$('.latest_videos .videos_wrapper .flickr, .latest_videos .videos_wrapper .videos_wrapper, .latest_videos .videos_wrapper br').remove();
		$('.latest_videos .videos_wrapper').append('<div class="latest-from-jazz-loading"><img src="' + STYLESHEET_DIRECTORY + '/images/activity indicator.gif" /></div>');
		
		$.post(BLOGINFO_URL + '/ajax.php', {
			call: $(this).attr('href').replace('#', '')
		}, 	function(response) {			
			$('.latest_videos .videos_wrapper .latest-from-jazz-loading').remove();
			$('.latest_videos .videos_wrapper').append(response);
		});
		
		return false;
	});
	
	/**
	 * share button for verizon photo section
	 */
	addThisButtonPhoto('#photo-share-button');
	
	$('.video-choice').click(
		function() {
			
			var text = $('img', $(this)).attr('alt');
			
			if (text == '') {
				text = 'UtahJazz360 Video';
			}
			
			$('#main-video').remove();
			$('.now-playing').html(text);
			
			var html = '<div id="main-video">';
				html += '<script type="text/javascript">';
					html += "var flashvars = {'contentId': '" + $(this).attr('rel') + "', 'context': 'jazz_508x311', 'domId': 'main-video', 'w': '508', 'h': '311'};";
					html += "var params = {};";
					html += "var attributes = {};";
					html += "swfobject.embedSWF('http://i.cdn.turner.com/nba/nba/.element/swf/1.1/cvp/nba_container.swf', 'main-video', '508', '311', '9.0.0', '" + css_dir + "/swf/expressInstall.swf', flashvars, params, attributes);";
				html += '</script>';
			html += '</div>';
			
			$('#video-container').append($(html));
			
			return false;
		}
	);
	
	$('.ask_greg').filter(':last').addClass('last').end();
	
	$('.ask_greg').find('dt').live('click', function(){
		$(this).toggleClass('open').next().slideToggle('fast');
	});
	
	$('.main_nav, .sub_nav').each(function(){
		$(this).find('li:last').addClass('last');
	})
	
	$('.jazzbots_bio_more').click(
		function() {
			$(this)
				.parent().css('display', 'none')
				.next().css('display', 'block');
			return false;
		}
	);
	$('.jazzbots_bio_less').click(
		function() {
			$(this)
				.parent().css('display', 'none')
				.prev().css('display', 'block');
			return false;
		}
	);
	
	$('.member-link-myaccount').hover(
		function(){
			$(this).addClass('active-parent');
		},
		function(){
			$(this).removeClass('active-parent');
			Cufon.refresh('#member-links li a');
		}
	);
	
	$('.sort-link-sortby').hover(
		function(){
			$(this).addClass('active-parent');
		},
		function(){
			$(this).removeClass('active-parent');
			Cufon.refresh('#sort-links li a');
		}
	);
	
	$('a[href^=http://]:not([href^=http://' + host + '])').live(
		'click',
		function() {
			window.open($(this).attr('href'), $(this).text());
			return false;
		}
	);
	
	$('#members_search').bind(
		'focusout keypress',
		function() {
			var element = $('#members_search');
			if ($(element).val() != '') {
				$('#clear-search').show();
			}
		}
	);
	
	$('#clear-search').click(
		function() {
			$(this).hide();
			$('#members_search').val('');
			$('#members-directory-form').submit();
		}
	);
	
	$("#feedback-link").fancybox({
		'width': 439,
		'height': 630,
		'margin': 0,
		'padding': 0,
        'autoScale': false,
        'transitionIn': 'none',
		'transitionOut': 'none',
		'type': 'iframe'
	});
	
	$('#add-poll').click(function() {
		$('#poll-options').slideToggle();
		
		return false;
	});
	
	$('#download-bttn').click(function() {
		var value = $('#download-os').val();
		if (value != '') {
			window.location = value;
		} else {
			alert('Please select your operating system');
		}
		
		return false;
	});	
});})(jQuery);
